1

I've been struggling with a Cereal serialization issue for hours.

If my struct is serialized on Windows and deserialized on Android it fails with:

cereal::Exception: Failed to read 1 bytes from input stream! Read 0" failed

if the binary file is serialized on Android and deserialized on Windows it works. And also works on Windows/Windows and Android/Android. In all cases the binary file is exactly one byte.

I have exactly the same code running on Windows and Android Linux, and just one bool inside my serialized struct. (cereal version is the same on both builds)

This is what I do to serialize:

ofstream os_out("data.bin", std::ios_base::binary | ios::binary);
{
    cereal::BinaryOutputArchive archive_out(os_out);
    archive_out(a);
}
os_out << std::flush;
os_out.close();

And to deserialize:

std::ifstream os_in("data.bin", std::ios_base::binary);
{
    cereal::BinaryInputArchive archive_in(os_in);
    archive_in(a);
}
os_in.close();

Cannot figure out what is wrong...

Pedro Soares
  • 1,117
  • 12
  • 14
  • just tried to use PortableBinaryOutputArchive and it all doesn't work. the only difference is the size of the binary file which is 2 bytes instead of 1 – Pedro Soares Dec 10 '20 at 21:10
  • Possibly you have something which might be encoded as a different size between windows and android ? e.g. bool, could be 1 or 4 bytes depending on the compiler. Hard to say without seeing the types you are serializing. – Goblinhack Apr 26 '21 at 10:00
  • Why do you not have "ios::binary" when reading ? " Opening a file with ios::binary controls how newline characters are handled. On Windows, they are expanded to CRLF pairs." See https://stackoverflow.com/questions/2225600/whats-the-difference-between-opening-a-file-with-iosbinary-or-iosout-or-bot – Goblinhack Apr 26 '21 at 10:04

0 Answers0