Tweak your code to use the xml_archive. Then examine this. This will reveal what is out of sync. Robert Ramey Ewald Peiszer wrote:
Hi
I am using the boost s11n lib, version 1.35.0, in combination with a text archive, Windows platform, MSVC++ 2005 compiler.
I have split serialize into load and save members, as indicated in the tutorial.
However, it seems as if save expects a different header format (ie text stream like stringstream etc) as the corresponding load method outputs. Output of my load method: 22 serialization::archive 4 0 0 10(...)
Everything before 10 is s11n housekeeping stuff, 10 is the beginning of the "real" data.
Now, if a string like this is used as input for save, then the first variable that is extracted is not the 10 (what it should be) but rather a 0 (or something else which is equally wrong); instead, the 10 shows up as the value of the const unsigned int version which is one of the two parameters of load/save/serialize members. Actually, version is supposed to be 0, I do not set a version number deliberatly anywhere. Playing around, I added a third 0 to the header, resulting in
22 serialization::archive 4 0 0 0 10
and, guess what, this time save(...) correctly managed to de-serialize the data congtained in the string.
I tried it also with a single seralize() member (and not splitting into save/load). Save behaviour.
The relevant code is below (class code and code to (de)serialize class instance.
Has anybody experienced the same or similar problems? Any help is greatly appreciated. If you need more information please ask.
Regards Ewald
------------------------------------- Excerpt of class code:
class Foo {
(...)
private: int buflen;
// s11n stuff friend class boost::serialization::access;
template<class Archive> void save(Archive & ar, const unsigned int version) const { // store length of buffer ar & buflen; // store data itself for (int j = 0; j < buflen; j++) ar & buffer[j]; }
template<class Archive> void load(Archive & ar, const unsigned int version) { // get length of buffer ar & buflen;
// create buffer with appropriate length deleteBuffer(); init(buflen);
// reat data into buffer for (int j = 0; j < buflen; j++) ar & buffer[j]; }
BOOST_SERIALIZATION_SPLIT_MEMBER()
/* // just to try it with serialize alone: template<class Archive> void serialize(Archive &ar, const unsigned int version) { ar & buflen; } */
(...) }; -------------------------------------
// check the save operation std::stringstream ssq (std::stringstream::in | std::stringstream::out); { const Foo rp(10); boost::archive::text_oarchive oa(ssq); oa << rp; }
-----------------------------------
// load { stringstream ss (stringstream::in| std::stringstream::out); ss << s11nbuf << endl;
boost::archive::text_iarchive ia(ss);
// restore from the archive ia >> rp; }
---------------------------------- (end of post)