I am serializing a set of contents, indexed by multiple properties using boost::multi_index_container, and a params struct, into a binary archive which I want to deserialize latter. But the archive created using boost 1.74 is unreadable (Invalid or corrupted archive) when read using boost 1.83.
I have included an mre inside in the git repo. Although it is a single small cpp file I made a repo to share it with the CMakeLists.txt and the Dockerfile. Following is my content
struct content{ friend class boost::serialization::access; using angle_type = std::size_t; inline content(angle_type angle): _angle(angle) {} inline angle_type angle() const { return _angle; } void reset_angle_random(){ static std::random_device dev; static std::mt19937 rng_angle(dev()); std::uniform_int_distribution angle_dist(0, 180); _angle = angle_dist(rng_angle); } void freeze(){ // complicated deterministic business logic _angle = 0; } content frozen() const{ mre::content copy(*this); copy.freeze(); return copy; } static content generate(){ static std::random_device dev; static std::mt19937 rng(dev()); std::uniform_real_distribution dist_length(-0.5f, 0.5f); mre::content content{0}; content._length = dist_length(rng); content.reset_angle_random(); return content; } template void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::make_nvp("length", _length); ar & boost::serialization::make_nvp("angle", _angle); } friend std::size_t hash_value(content const& c){ std::size_t seed = 0; boost::hash_combine(seed, c._length); boost::hash_combine(seed, c._angle); return seed; } inline std::size_t hash() const { return boost::hash{}(*this); } inline std::size_t frozen_id() const { return frozen().hash(); } inline std::string id() const { return (boost::format("%1%~%2%-%3%") % frozen_id() % hash() % angle()).str(); } inline bool operator >; inline explicit package(const mre::parameters& params): _loaded(false), _parameters(params) {} inline explicit package(): _loaded(false) {} void save(const std::string& filename) const; void load(const std::string& filename); inline std::size_t size() const { return _samples.size(); } inline bool loaded() const { return _loaded; } const mre::content& operator[](const std::string& id) const; const mre::parameters& params() const { return _parameters; } template void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::make_nvp("samples", _samples); ar & boost::serialization::make_nvp("params", _parameters); } public: std::size_t generate(std::size_t contents, std::size_t angles); private: bool _loaded; container _samples; mre::parameters _parameters; }; I am also serializing a set of paremeters mentioned below.
struct parameters{ std::size_t degree; std::size_t frame_size; template void serialize(Archive & ar, const unsigned int version) { ar & boost::serialization::make_nvp("degree", degree); ar & boost::serialization::make_nvp("frame_size", frame_size); } }; Saving, loading and generating are done as following
void mre:
Источник: https://stackoverflow.com/questions/780 ... ndex-conta
Мобильная версия