Serialization/Deserialization in C/C++ for union arrays -
what best way serialize / deserialize union arrays strings , basic integer?
for example, want serialize:
union val_u { int i; char *s; } void serialize(void *buffer, const char *format, const union val_u src[]); void deserialize(union val_u dst[], const char *format, const void *buffer);
the arbitrary composition of union arrays denoted contents of format string: 'i' indicates integer while 's' indicates string. serialize() copies contents of src union member types denoted format described above buffer. deserialize() copies contents of buffer dst union member types denoted format. literally reverse of serialize() function.
format string identification (arbitrary)
any idea how implement functions? also, how make portable across architecture?
thanks!
the easiest way print out string representation. don't binary representations , don't have worry representations or alignment or padding.
then use string integer functions (atoi , like) them numeric representations in deserialization routines.
it's not efficient way things, that's not important thing. getting things right, first, important. then, if it's not enough, worry improving it.
ithis string n234234 n8292 imore stuff n-92
i think saying, , should work you.
Comments
Post a Comment