Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] serialize/deserialize
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-20 (14:20)
From: Michael Hicks <mwh@c...>
Subject: RE: [Caml-list] serialize/deserialize
You can always write your own serialization functions from scratch, based on
streams.  In our networking implementation written in OCaml (see, we wrote a simple package for
marshalling ints, strings, characters, etc. into our own version of streams.
These streams could then be dumped to a string (which was fast, since our
streams are represented by strings internally) and sent out as packets.  We
tuned it for speed and space a while back, so hopefully it's not too slow.
If you download the distribution at the above URL, take a look at
plan/util/ for the basic package and then look at
plan/basis/ to see how we used the marshalling primitives for
our application.  Note that most of this code was written before there was a
generic OCaml Buffer module, so it probably could be rewritten to use that,
but I haven't looked into it.


-----Original Message-----
[]On Behalf Of Brian Naylor
Sent: Friday, July 19, 2002 1:19 AM
Subject: [Caml-list] serialize/deserialize

I need to write my own marshalling functions for a network protocol stack.
there any way I can make use of the <caml/intext.h> serialization and
deserialization functions? Has anyone trod this path before me and is
to share their wisdom?

Why am I doing this, you ask? Bandwidth is critical, and custom marshalling
save a lot of space - especially in getting rid of headers. Also, I want to
things like serialize some info, add a MAC, then serialize some more. The
off-the-shelf solution is too space-inefficient:

let alen = Marshal.to_buffer buf ofs max adata [] in
let mac = Digest.substring buf ofs alen in
let blen = Marshal.to_buffer buf (ofs + alen) (max - alen) (mac, bdata) []

Thanks for any advice...

Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list:
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: