Search code examples
c++flatbuffers

Serializing object in flatbuffers in cpp


I am attempting to use flatbuffers as a way to communicate between master/slave servers. The issue I am facing is, that after I have read data from char* into flatbuffer, I can't find a way to write it back into char*. First configuration:

flatc --cpp --gen-mutable --gen-object-api -o ${OUT} ${IN}

And here is code which bothers me:

char* buffer = <MY_FLATBUFFER_DATA>;
auto managedObject = GetMutableManagedObject(buffer);
makeChanges(managedObject);
char* newBuffer = managedObject.deserialize(); // This is my imaginative method

I want to be able to deserialize object which has been modified and send it back to the slave. Is it possible? Or I have to use "slower" (as it describes tutorial) Pack/UnPack methods?

(I do not mind another approach kind of answer)


Solution

  • Yes, you need Pack/UnPack. --gen-mutable only allows very limited modification (some scalars), if you want to be able to modify everything you need the object api.