Boost logo

Boost Users :

Subject: [Boost-users] Boost Serialization
From: Abraham, Marshel (Marshel.Abraham_at_[hidden])
Date: 2014-10-24 18:24:30


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 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