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 :"<
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 :"<
boost::archive::text_oarchive ota(serializedRequest, boost::archive::no_header);
ota<<(*this);
cout<<"\n text_oarchive :"<
}
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
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
participants (2)
-
Abraham, Marshel
-
oswin krause