cereal
cereal copied to clipboard
Unified way of storing binary data in archives
I started writing serialisation for an Eigen matrix, so save and load functions because the only way to save an Eigen matrix is through a data pointer, since it has an interface like this:
int rows();
int cols();
T* data();
I quickly realised though that there is no single interface to write the binary data across archives (even though json and XML have the saveBinaryValue and loadBinaryValue functions, which are of course not part of the common archive interface, as is the saveBinary and loadBinary functions of the Binary archive).
I already added functions similar to the ones in the binary archive for getting a BinaryData object and saving it properly in the json.hpp and xml.hpp archives. I am going to open a PR soon as well, just wanted to document this here in case there is an objection/different solution.
Have you seen this solution on stack overflow for serializing an Eigen matrix with cereal?
I have, and that's what I tried to implement. That solution only uses the Binary archive. But the BinaryData argument is not accepted by Json and XML, correct me if I am somehow wrong there. I applied the fix that I mentioned, locally and then it works for both those archives.