
#include <stdlib.h>
#include <string.h>

#include "serializationinfo.h"

struct s_SerializationInfo
{
    hshTvoid_list   *table;
};

SerializationInfo *
serializationinfo_new()
{
    SerializationInfo *info = (SerializationInfo *) malloc (sizeof (SerializationInfo));
    info->table = hshFvoid_init ((void (*) (void *)) dynFfree);

    return (info);
}

void
serializationinfo_destroy (void *ptr)
{
    SerializationInfo *info = (SerializationInfo *) ptr;

    hshFvoid_destroy (info->table);

    free (info);
}

void
serializationinfo_addValueData (SerializationInfo *info, const char *key, int keyLen, dynTstring *value)
{
    char *alloc_key = malloc (keyLen + 1);

    memcpy (alloc_key, key, keyLen);

    *(alloc_key + keyLen) = 0;

    /* if we use raw_add, we have to allocate the key ourselves */
    hshFvoid_raw_add (info->table, alloc_key, keyLen, value, 0);
}

void
serializationinfo_addValue (SerializationInfo *info, const char *key, dynTstring *value)
{
    hshFvoid_add (info->table, key, value);
}

dynTstring *
serializationinfo_getValue (SerializationInfo *info, const char *key)
{
    return ((dynTstring *) hshFvoid_find (info->table, key));
}

hshTiterator *
serializationinfo_getIterator (SerializationInfo *info)
{
    return (hshFiterator_init (info->table));
}

void
serializationinfo_destroyIterator (hshTiterator *iter)
{
    hshFiterator_free (iter);
}
