c++ - using cereal and boost serialisation in the same program -


we have system uses lot of boost serialisation store data. looking migrate away this, using cereal instead.

however, unlikely able migrate serialised objects. @ least, have able de-serialise old version of data.

is possible use both boost , cereal serialise same object, preferably without having write serialisation function twice?

an example of our code is:

class base { public:     std::string m_vara;     std::string m_varb      template<class archive>     void serialize(archive & rarchive, const unsigned int nversion)     {         rarchive & boost_serialization_nvp(m_vara);         rarchive & boost_serialization_nvp(m_varb);     } };  class derived : public base { friend class boost::serialization::access; public:     std::bitset<32> m_flags;     template<class archive>     void serialize(archive & rarchive, const unsigned int nversion)     {         rarchive & boost_serialization_base_object_nvp(base);          rarchive & boost_serialization_nvp(m_flags);             }     };  std::ostringstream stream; derived var; {     boost::archive::xml_oarchive rarchive(stream);     rarchive & boost::serialization::make_nvp("configuration", var); } 

i don't think have more complicated this.

i'll go out on limb , "yes".

the libraries have similarity, if don't coexist bug in either or both libraries.

you don't show code, don't know how organized serialization code.

for approach can envision migration paths.

the important thing realize actual serialization code needs visible @ point serialization occurs. if limit tu , make functions involved in file-static, you'll safe sharks¹.

obviously, you'll better off if serialization code non-intrusive². if do, make intrusive method relay free functions can file-static.

holy grail: unified serialization functions

this require more work, obviously, seems doable modicum of meta programming. quick looks it's easier implement boost-serializability existing cerial serialize functions, guess that's tough luck.


¹ sharks ambiguous overloads or odr violations

² /ɪnˈtruːsɪv/ adjective 1. causing disruption or annoyance...


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -