serialization - (C++) serialize object of class from external library -
is there way serialize (or, more save file) object class can't modify?
all of serialization approaches i've found far require manner of intrusion, @ least adding methods class, adding friends etc.
if object class in library didn't write myself, don't want have change classes in library.
more concretely: i'm developing module-based application involves inter-module communication (which simple as: 1 module, source, owner of data, , module, destination, has pointer data, , there's simple updating/hand shaking protocol between modules). need able save state of modules (which data last communicated between modules). now, ideal if communication handle type, including ones external libraries. need save data when saving module state.
in general, there no native serialization in c++, @ least according wikipedia article on topic of serialization.
there's faq resource on topic here might useful if haven't found already. general info on serialization, though; doesn't address specific problem raise.
there couple of (very) ugly approaches can think of. you've thought of , rejected these, i'm throwing them out there in case:
do have access data members of class? worst case, read out c-style structure, apply compiler's version of "packed" keep sizes of things predictable, , transferable binary blob way.
you cast pointer object pointer uint8_t, , treat whole thing array. messy if there references, pointers, or vtable in there. approach might work pod objects, though.
Comments
Post a Comment