boost-serialization

How to hook up Boost serialization & iostreams to serialize & gzip an object to string?

六月ゝ 毕业季﹏ 提交于 2019-11-28 16:33:38
I've been using the Boost serialization library, which is actually pretty nice, and lets me make simple wrappers to save my serializable objects to strings, like so: namespace bar = boost::archive; namespace bio = boost::iostreams; template <class T> inline std::string saveString(const T & o) { std::ostringstream oss; bar::binary_oarchive oa(oss); oa << o; return oss.str(); } template <class T> inline void saveFile(const T & o, const char* fname) { std::ofstream ofs(fname, std::ios::out|std::ios::binary|std::ios::trunc); bar::binary_oarchive oa(ofs); oa << o; } template <class T> inline void

Boost Serialization Binary Archive giving incorrect output

放肆的年华 提交于 2019-11-28 14:24:41
I am trying to Serialize a class. Class definition: class StartPeerSessionRequest { public: StartPeerSessionRequest(); virtual ~StartPeerSessionRequest(); void composeRequestwithHardCodeValues(); void save(); stringstream serializedRequest; /*boost::serialization::binary_object serlreq;*/ private: StartPeerSessionRequest(const StartPeerSessionRequest &); uint16_t mProtocolVersion; uint16_t mSessionFlags; uint16_t mMaxResponseLength; string mMake; string mModel; string mSerialNumber; uint8_t mTrackDelay; string mHeadUnitModel; string mCarModelYear; string mVin; uint16_t mVehicleMileage; uint8_t

how to customise default Boost xml Serialisation default node naming to make it more readable

左心房为你撑大大i 提交于 2019-11-28 14:18:44
The code below generates a xml file but , when it loops theough a map , it always names the map key as first and value as second Is there a way that we can customise tag names first and second to groupid and groupType as shown in desired output #include <fstream> #include <boost/serialization/map.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/xml_oarchive.hpp> #include <string> #include <iostream> #include <map> using namespace std; class MyConnections { public: MyConnections() { e_group.insert( std::make_pair(1,"ETOTO") ) ; e_group.insert( std::make_pair(2,"ETOTO") ) ; }

How to serialize armadillo's vector

不想你离开。 提交于 2019-11-28 06:15:22
问题 How can I serialize arma::Col ? Below are a MWE and the error output. MWE: #include <boost/mpi/environment.hpp> #include <boost/mpi/communicator.hpp> #include <iostream> #include "armadillo" namespace mpi = boost::mpi; struct S { int i; arma::Col<double>::fixed<3> cvector; friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int version) { ar& i; ar& cvector; } }; int main() { mpi::environment env; mpi::communicator world; S s; if

boost serialization, deserialization of raw C arrays

孤者浪人 提交于 2019-11-28 00:18:13
I'm trying to serialize and deserialize raw C pointers and their data, with the example below. It seems to serialize just fine, but I am unsure how to make it deserialize - it just crashes with a memory access violation exception when I deserialize it. I suppose it is because it dosn't know how to deserialize it, but where do I specify that? Using a vector is not an option, in very large primitive data amounts it is painfully slow #include <stdint.h> #include <string> #include <iostream> #include <fstream> #pragma warning (push) #pragma warning( disable : 4244 ) #include <boost/serialization

Boost serialization with pointers and non-default constructor

可紊 提交于 2019-11-27 22:33:26
问题 How would you serialize/deserialize this class using boost::serialization? #include <vector> struct Foo { struct Bar { std::vector<int> * data; // Must point to Foo::data Bar( std::vector<int> * d ) : data(d) { } }; std::vector<int> data; std::vector<Bar> elements; Foo() { // do very time consuming calculation to populate "data" and "elements" } }; The constructor in Foo must not be executed when the objected is loaded from the serialized data, but if the object is default constructed the

Get private data members for non intrusive boost serialization C++

自闭症网瘾萝莉.ら 提交于 2019-11-27 22:26:29
I have tried providing getters of class A for my non-member serialize() function` since accessing from members is private. template<typename T> class A { public: A(const T& id) : m_id(id) {} T& getRef() { return m_id; } // not giving good results T getId() { return m_id; } // not giving good results const T& getRef() const { return m_id; } // not giving good results private: // I would like to keep it private T m_id; } namespace boost { namespace serialization { template<class Archive,typename T> void serialize(Archive &ar, A &a, const unsigned int version) { // ar &BOOST_SERIALIZATION_NVP(a.m

how to do performance test using the boost library for a custom library

折月煮酒 提交于 2019-11-27 15:43:51
I need to do performance testing of a library written in c++. The library consist of few sets of structures. I have already done the serialization test for these class but not sure how to do perfomance test for these . Below is sample of a struct in library struct X { public: int p; double q; X(); ~X(); } struct Y { float m; double n; Y(); ~Y(); } struct Z { public: std::map<std::string,boost::shared_ptr<X>> Xtype; std::map<std::string,boost::shared_ptr<Y>> Ytype; int i; string name; Z(); ~Z(); } If any example is provided then it will be really good. Okay, so I added serialization to the

How to hook up Boost serialization & iostreams to serialize & gzip an object to string?

别说谁变了你拦得住时间么 提交于 2019-11-27 09:46:43
问题 I've been using the Boost serialization library, which is actually pretty nice, and lets me make simple wrappers to save my serializable objects to strings, like so: namespace bar = boost::archive; namespace bio = boost::iostreams; template <class T> inline std::string saveString(const T & o) { std::ostringstream oss; bar::binary_oarchive oa(oss); oa << o; return oss.str(); } template <class T> inline void saveFile(const T & o, const char* fname) { std::ofstream ofs(fname, std::ios::out|std:

Boost Serialization Binary Archive giving incorrect output

若如初见. 提交于 2019-11-27 08:33:53
问题 I am trying to Serialize a class. Class definition: class StartPeerSessionRequest { public: StartPeerSessionRequest(); virtual ~StartPeerSessionRequest(); void composeRequestwithHardCodeValues(); void save(); stringstream serializedRequest; /*boost::serialization::binary_object serlreq;*/ private: StartPeerSessionRequest(const StartPeerSessionRequest &); uint16_t mProtocolVersion; uint16_t mSessionFlags; uint16_t mMaxResponseLength; string mMake; string mModel; string mSerialNumber; uint8_t