Hi,
I would do it as follows:
At a serialize data function (in your case taking a class with void* and
writeptr to keep track of the written bytes or char* I usually use an
ostream istream for it).
Serialize( const CMyStream& MyStream )
{
if( MyStream.Write )
{
memcpy( MyStream.BasePtr + MyStream.Written, &l, sizeof l );
MyStream.Written += sizeof( l );
memcpy( MyStream.BasePtr + MyStream.Written, &l, sizeof f );
MyStream.Written += sizeof( f );
}
else
{
// Copy the other way around
}
}
// TODO: You probably don't want another class accessing the data members of
MyStream directly i.e. hide stuff
// Optional: Take care of little endian big endian conversion
// Optional: Take care of different sizes of longs for different
architectures
// Optional overload << operators for every type
I myself usually use ostream and istream which allows me directly to write
to files (ofstream derived) or memory (stringstream derived) or just to the
console ostream itself
--
Regards, Ron AF Greve
http://moonlit.xs4all.nl
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:dh**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
I have the following data types:
typedef union {
long l ;
double f;
char* s ;
void* p ;
} Value ;
typedef struct {
int id ;
char *label
Value value ;
size ;
}StructA ;
Does anyone know how I can serialize StructA into a raw memory block and
calculate the number of bytes of the memory block?
Someone out there should surely know how to do this - if even they don't
know how to do it, but can point me to a reference (my Google searches
have not come up with anything remotely useful) - I'd be most grateful
mtia