c++ - From binary to xml serialization using boost -
i'm working on several classes used boost serialization binary archive using :
my_archive & my_variable; however want move add xml archive serialization support, while keeping backward compatibility. boost enforce (of course) use nvp wrapper reason.
unfortunately, seems impossible mix nvp() , direct binary serialization in same serialize fonction (with managing versioning).
so here code looks until :
friend class boost::serialization::access; template<class archive> void serialize(archive & ar, const unsigned int version) { // serialize base class information if (version == 4) { ar & boost::serialization::make_nvp( "var", mvariable ); } else if (version == 3) { ar & mvariable; } } with
boost_class_version(mytype, 4) when calling & operator xml archive template error on is_wrapper<>() because of serialization not using nvp wrapper.
so here question, there work around allow me regarding version number (know @ compile time) adapt serialize function use xml/binary version 4 , binary previous one.
you should add nvp wrapper; it's just metadata annotation , isn't used binary archives (or standard text archives, matter).
so don't need change versioning, binary archives
ar & boost_serialization_nvp(x); // or ar & boost::serialization_make_nvp("foo", x); is equivalent to
ar & x;
Comments
Post a Comment