[serialization] load/save seem to different header format

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)

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)

Robert Ramey schrieb:
Tweak your code to use the xml_archive. Then examine this. This will reveal what is out of sync.
The output is now
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>

AMDG Ewald Peiszer wrote:
Robert Ramey schrieb:
Tweak your code to use the xml_archive. Then examine this. This will reveal what is out of sync.
The output is now
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization>
<rp class_id="0" tracking_level="0" version="0"> <buflen>10</buflen> </rp> And this also works at the time of de-s11n.
If possible, however, I would rather use the text archive. So, I guess that in the textarchive one of the 0 is missing (class_id, tracking_level, version), but I don't have any idea why that could be the case.
Summary: if I use xml archive -> works if I use text archive -> the s11n operation prints only two 0 where there should be three -> does not work.
I filled in the missing parts of your code to make a complete program (attached) and it works for me with Boost 1.35.0 and MSVC 8.0 Express. In Christ, Steven Watanabe

I filled in the missing parts of your code to make a complete program (attached) and it works for me with Boost 1.35.0 and MSVC 8.0 Express.
Thank you for your effort! Your test code also works for me and it even works with my original class. ...after some more hours I finally found the problem. I declared the variable I deserialize my archive to as Foo *xy = new Foo(); Accordingly I should have written something like ia >> (*xy); (NB the * operator.) *blush* Regards Ewald
participants (3)
-
Ewald Peiszer
-
Robert Ramey
-
Steven Watanabe