Richard said:
Unless someone else has already done so, which is what the OP was asking
about.
No, in C you can't have a well defined way of serializing structs in
general.
The problem, is most clearly illustrated with any char * entry. If
some header parser/serializer sees that there is a char * field in a
struct, what should it assume that it means? Is that a pointer to one
character, or is it a pointer to a NUL terminated string? Is the
underlying buffer assumed to be of some certain length (which cannot
even be hinted at in the declaration, except by a comment or something
lame like that)?
In fact that the underlying buffer for the char * may be characterized
by another field in the struct (like it is for a bstring for example.)
I.e., some other field may in fact describe the length of the usable
buffer in which a NUL terminated string is placed -- this information
need not be stored in the serialized form, however, how would a
serializing tool know to do this?
And of course none of this speaks to how you are supposed to fill in a
struct which contains a union as a sub-field. Usually *which* entry of
the union is used is indicated by a state derivable from the other
fields (if its not just one of the fields itself.)
This is why things like CORBA, COM, and IDLs in general exist.