GHashTable serialization

While working on LogJam ( I needed a module to
serialize and deserialize GHashTables to strings, so I wrote one. It's
generic enough, and small, so I thought you might be interested in
putting it in GLib.

I'm not sure I should post code to the list, and I'm not familiar with
your coding conventions, so please comment on the code at

(The interesting functions are prefixed with lj_ and not g_ because of
their association with LogJam.)

Here's the interface. You can plug in any (de)serialization functions
you like for hash tables of any type; ones for ints and strings are
provided by the module.


typedef GString* (*SerializeFunc) (gpointer data);

GString* lj_hash_freeze(GHashTable* hash, SerializeFunc key_serialize,
    SerializeFunc val_serialize);

GString* gint_serialize(gint* data);
GString* gchar_serialize(gchar* data);

void lj_hash_thaw(GHashTable* hash, SerializeFunc key_deserialize,
    SerializeFunc val_deserialize, GString *frozen_hash);

gint* gint_deserialize(GString* data);
gchar* gchar_deserialize(GString* data);


Gaal Yahas <gaal forum2 org>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]