Re: object serialization
On Apr 20, 2:49 am, William <Wizumw...@gmail.com> wrote:
I'm looking for an example that would show how to serialize a c++
object at it's simplest w/o using any other api's. I have a class that
I want to serialize and then pass to my obj-c class so I can send it
over the wire.
I'm just looking for how to serialize it, then pack it back up on the
other end.
There are, regretfully, no simple answers. Basically, you'll
have to either define a line protocol yourself, or use an
existing one, then code every type you use to conform to the
line protocol.
If there are no other particular constraints, I'd start with XDR
for the low level types, and build on it. I'd probably define a
oxdrstream and an ixdrstream, with << and >> operators for the
primitive types. (Handling integers is easy. Floating point
less so; depending on how portable you want to code, it can even
be very complex.) More complex types then output each field.
(Some consideration must also be given to variable length types,
e.g. vectors and strings. XDR has some basic rules for these as
well.) And don't forget to follow pointers, if the pointed to
data is logically part of your object. (You cannot, of course,
serialize a pointer.)
You'll also have to give some thought to how the receiving end
will know what type it is getting. Depending on the protocol,
this may be more or less implicit, but most of the times, there
will be cases where you'll have to transmit this information as
well.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34