c++ - Microsoft GUID serialization using boost serialize? -


i have following:

struct member {     guid id;     int extra;      template<class archive>     void serialize(archive & ar, const unsigned int file_version)     {         ar & id;         ar & extra;     }  } 

when compile code following compile error:

error 25 error c2039: 'serialize' : not member of '_guid'

how specialise boost serialization microsoft guid?

here's hint: assuming uuid type pod, can use make_binary_object.

here's mockup type uuid pod:

#include <array>  using uuid = std::array<uint8_t, 16>; // mock static_assert(std::is_pod<uuid>(), "assumes uuid pod"); 

any pod do. e.g. boost::uuids::uuid¹ pod. same struct uuid { char data[16]; } etc.

non-intrusive serialization:

#include <boost/serialization/serialization.hpp> #include <boost/serialization/binary_object.hpp>  namespace boost { namespace serialization {     template <typename ar>         void serialize(ar& ar, uuid& u, unsigned /*version*/) {             ar & make_binary_object(&u, sizeof(u));         } } } 

demo

live on coliru

#include <iostream> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp>  int main() {     std::stringstream ss;     {         boost::archive::text_oarchive oa(ss);         uuid u {{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}};         oa << u;     }      std::cout << ss.str() << "\n";      {         boost::archive::text_iarchive ia(ss);         uuid u {};         ia >> u;          std::copy(begin(u), end(u), std::ostream_iterator<int>(std::cout << "roundtripped: ", " "));     } } 

¹ although library defines serialization in boost/uuid/uuid_serialize.hpp header


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -