GHashTable serialization



While working on LogJam (http://logjam.danga.com/) 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

http://www.forum2.org/gaal/lj/hash_serialize.tar.gz

(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.

==snip==

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);

==snip==

-- 
Gaal Yahas <gaal forum2 org>
http://www.forum2.org/gaal/
http://www.livejournal.com/~gaal/



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