Serializing TObjects to a uint8_t array

Hi Guys,
I am at a loss for how to serialize/deserialize an object to/from a simple char* array, which could be saved to disk, or sent over a serial line, etc. With so many options for streaming to various end states (xml/json/etc), it seems this must be possible, but I can’t find a short route to it. There are some old hints on the forum, but they don’t seem to apply to the modern codebase. Any tips?


For future searchers, the answer to this was found in an ancient 16-year-old post by Fons (link below). Basically, you have to build your own Message class that inherits from TMessage. At that point, you can serialize any TObject-inheriting class into a raw uint8_t array, send it along any channel you like, then reconstruct it on the other end.

Note added: you probably will want to add SetBit(TBuffer::kIsOwner, false) to your constructor to avoid double free issues with the buffer you provide to TMessage.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.