be*******@yahoo.com (Voronkov Konstantin) wrote in message news:<77**************************@posting.google. com>...
Thank you for answer, but I still did not
got *how* to make serialization of enum type.
Can you provide more instructions or hint, please?
My task is to serialize enum to something like byte array,
and then load enum from that byte array to the same enum
type on other platform.
One way to do I see is:
- static cast enum to integer
- convert integer to network byte order with htonl()
- transmit the result via network to remote host
- get result and convert it to host byte order with ntohl()
- cast integer back to enum
Is it portable way? Is there any well-known
tenchnics for such kind of tasks?
Thanks for help,
Konstantin
By example:
class RecordStream {
public:
//! Type of a record stream and database codes.
enum Type {
//! Unknown record stream type.
stUnknown = '\0',
//! Record stream generated from the external source.
stIncoming = 'i',
//! Record stream generated by the OSB.
stRegular = 'r',
//! Record stream contains error records.
stError = 'e',
//! Record stream contains filtered records.
stFilter = 'f'
};
};
RecordStream::Type RecordStream::toType(char c)
{
Type rc = Type(tolower(c));
bool done = false;
switch (rc) {
case stIncoming: // fall through for all defined types
case stRegular:
case stError:
case stFilter:
case stUnknown: done = true; break;
// no default: let compiler warn
}
if (!done) rc = stUnknown;
return rc;
}
char RecordStream::toChar(RecordStream::Type t)
{
int rc = t;
rc = toType(static_cast<char>(rc));
return static_cast<char>(rc);
}
Note the casts in order to avoid compiler warnings.
Stephan Brönnimann
br****@osb-systems.com
Open source rating and billing engine for communication networks.