Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Serialization
From: Abraham, Marshel (Marshel.Abraham_at_[hidden])
Date: 2014-10-25 07:56:59


Hey ,

Thanks for the support .

I was quite dump . I overthinked a bit , jus serializing class members to and ostream would be enough for me hopefully.

I am in another spot :

I have serialized some data into an ostream to be send over a devicefile., in binary format.

I am getting output like this when printing the contents of ostream which is fine.

Now I need to calculate the checksum using a certain algorithm :

Here is an analogous implementation :

uint8_t Connector::calculateChecksum(uint8_t* data, uint16_t length)
{
      uint16_t* checksumData = (uint16_t*) data;

      uint8_t ret = 0;

      int length16;

      if(0 == length%2)
      {
            length16 = length/2;
      }
      else
      {
            length16 = (length/2) + 1;
      }

      for(int i = 0; i<length16; i++)
      {
            ret += -(checksumData[i]) + 1;
      }

      return ret;
}

Long Story Short :

Is there any ibuilt casting to convert std::string to uint16_t* and/or uint8_t*

Or any short readable routine to calculate checksum from ostream format is also fine.

CheckSum algorithm : The checksum
is
calculated
using
two$B!G(Bs--$B!>(B
complement
addition
of
all
16--$B!>(Bbit
words
contained
in
the
packet

Regards
Marshel Abraham
3097146

From: Boost-users [mailto:boost-users-bounces_at_[hidden]] On Behalf Of oswin krause
Sent: Saturday, October 25, 2014 2:21 PM
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Boost Serialization

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]<mailto: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