I'm using the following code to attempt to serialize/deserialize an object as binary data:
MyDTO dto1;
std::ostringstream os(std::stringstream::binary);
{
cereal::BinaryOutputArchive oarchive(os); // Create an output archive
oarchive(dto1);
}
MyDTO dto2;
std::istringstream is(os.str(), std::stringstream::binary);
{
cereal::BinaryInputArchive iarchive(is); // Create an input archive
try {
iarchive(dto2);
}
catch (std::runtime_error e) {
e.what();
}
}
When the code runs, an exception is caught with the message:
"Failed to read 8 bytes from input stream! Read 0"
Can anyone help me understand what's going wrong?