Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Serialization
From: oswin krause (oswin.krause_at_[hidden])
Date: 2014-10-25 04:51:17


Hi,

"Does not work" is most likely not a good error description. In the case
of a text archive you can take a look at the file and see what is
stored. so what is stored additionally to what you wanted to store?

Your question is also hard to answer without knowing the types of the
variables. Assuming that all numerics are 4 Byte, i get 28 Byte from the
non-string variables +40 characters+6*'\0' which gives 84 Bytes.
Assuming numerics are 8 Bytes i get something even higher. Thus it is
not really possible to answer your question.

On 25.10.2014 00:24, Abraham, Marshel wrote:
>
>
>
> I am trying to Serialize a class :
>
> StartPeerSessionRequest::StartPeerSessionRequest() {
>
> mProtocolVersion = 1*10000 + 14*100 + 4;
>
> mSessionFlags = 1;
>
> mMaxResponseLength = 0;
>
> mMake = "MyMake";
>
> mModel = "MyModel";
>
> mSerialNumber = "10000";
>
> mTrackDelay = 0;
>
> mHeadUnitModel = "Headunit";
>
> mCarModelYear = "2014";
>
> mVin = "1234567980";
>
> mVehicleMileage = 1000;
>
> mShoutFormat = 3;
>
> mNotificationInterval = 1;
>
> }
>
> template <class Archive>
>
> void StartPeerSessionRequest::serialize(Archive &ar, const unsigned
> int version)
>
> {
>
> ar & mProtocolVersion;
>
> ar & mSessionFlags;
>
> ar & mMaxResponseLength;
>
> ar & mMake;
>
> ar & mModel;
>
> ar & mSerialNumber;
>
> ar & mTrackDelay;
>
> ar & mHeadUnitModel;
>
> ar & mCarModelYear;
>
> ar & mVin;
>
> ar & mVehicleMileage;
>
> ar & mShoutFormat;
>
> ar & mNotificationInterval;
>
> }
>
> void StartPeerSessionRequest::save()
>
> {
>
> boost::archive::binary_oarchive oa(serlreq,
> boost::archive::no_header);
>
> oa << (*this);
>
> /*cout<<"\n binary_oarchive :"<<serlreq.size();*/
>
> boost::archive::text_oarchive ota(serializedRequest,
> boost::archive::no_header);
>
> ota<<(*this);
>
> cout<<"\n text_oarchive :"<<serializedRequest.str()<<"size
> :"<<serializedRequest.str().size();
>
> }
>
> serializedRequest.str.size() provides me a length of 87
>
> actually it should provide me 65 bytes.( I ve counted u can figure
> that out from the constructor )
>
> I suspect it is appending lengths in between.
>
> I have tried using text_archive also it doesnt work.
>
> What I need is to just plain serialize class members as it is.
>
> I guess i need to use some traits or wrappers, or|boost::serialization::binary_object|
>
> Please let me know
>
> Thanks
>
> Regards
>
> Marshel Abraham
>
> 3097146
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net