USCiLab / cereal

A C++11 library for serialization
BSD 3-Clause "New" or "Revised" License
4.25k stars 767 forks source link

About the use of CEREAL_CLASS_VERSION #813

Open yydy1983 opened 10 months ago

yydy1983 commented 10 months ago

There is no version in the data that has been serialized and saved. How can I read it in a program that has been upgraded with CEREAL_CLASS_VERSION?

dimateos commented 6 months ago

If you had no version argument in your serialize functions, Cereal did not store any versioning info. So now you files are incompatible: Cereals tries to read versioning where there is none.

Data serialized without versioning cannot be loaded by a versioned serialization function (and vice versa). https://uscilab.github.io/cereal/serialization_functions.html

You could modify Cereal to store a version tag by default anyway or add some try catch afterwards... This would increase complexity and impact performance.

Cereal, by design, ignores versioning data management completely when you dont need it. If you suspect that you may need it later, you should add it from the start: at least the version argument so it will use the default version 0 for all classes.