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?
--
Carlo Wood