Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-08-31 09:04:48


Carlo Wood wrote:
> On Tue, Aug 31, 2004 at 02:27:02PM +0300, Peter Dimov wrote:
>>> A general "binary serialization class" would never know
>>> where builtin-variables begin and end (or what type they
>>> are) and therefore cannot swap bytes on Big-Endian machines.
>>
>> You may be right, depending on the meaning of "general", but useful
>> binary serializers do exist. You just need to decide how to
>> represent the built-in types. For example, I've chosen that the
>> external representation of a char is 8 bits, a short 16, int and
>> long 32. This is perfectly portable, as long as the values of my
>> variables do not exceed these limits.
>
> What does size have to do with endianness?
> if you have the following struct:
>
> struct Data {
> char c1;
> char lt[3];
> int s;
> unsigned short p1;
> unsigned short p2;
> bool init;
> bool flags[5];
> unsigned char t[8];
> };
>
> Then how would your general (== does not know anything about the
> internals of 'Data') serializer write that to a TCP/IP socket
> when running on a Big-Endian machine, such that both Big-Endian
> and Little-Endian machines can read the result from the
> network?

No way. But my serializer isn't "general" by your definition (endianness is
only one of the problems, there's also sizeof() and padding). It is an
ordinary boost::serialization-style serializer that happens to use a binary
external format.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net