c++ - boost serialiaze archive convert to char -


i have serialized object following code:

void atodo::sendback(protocolbaseserver & in){    std::ostringstream archive_stream;    boost::archive::text_oarchive archive(archive_stream);    archive << *this;    std::string outbound_data=archive_stream.str(); //type needs first factory create correct object    outbound_data=_inittype+outbound_data;    //now send along    in.dowrite(outbound_data); } 

here protocolbaseser dowrite:

void protocolbaseserver::dowrite(std::string inmessage){    _totalmessage=inmessage;    std::cout << "totalmessage: " << _totalmessage << std::endl;    int32_t datalength=_totalmessage.length();    int32_t orgdatalength=_totalmessage.length();     std::cout << "data length: " << orgdatalength << std::endl;    //read in todo    datalength = htonl(datalength ); // ensure host system byte order on int;from network network byte order    std::cout << "writing length now" << std::endl;    protoservice<int32_t>::dowrite(_sock,&datalength,sizeof(int32_t));    std::cout << "written length" << std::endl;    std::cout << "writing :" << _totalmessage.data() << std::endl;    protoservice<int32_t>::dowrite(_sock,(void*)_totalmessage.data(),orgdatalength); // send string dataee    std::cout << "wrote :" << _totalmessage << std::endl;  } 

why when convert _totalmessage c string send on socket sends nothing.

also when attempt print _totalmessage.c_str() screen prints nothing? here output above. can see "writing:" line did not display something. feel there missing convert archive character array send on socket?

writing : size write: 38 wrote :22 serialization::archive 12 0 0 0 0 

what interesting function preps string send in fact output "outbound.c: " below:

void atodo::sendback(protocolbaseserver & in){    std::ostringstream archive_stream;    {      boost::archive::text_oarchive archive(archive_stream);    archive << *this;    }      archive_stream.flush();    std::string outbound_data=archive_stream.str(); //type needs first factory create correct object    std::cout << "outbound: " << outbound_data << std::endl;    std::cout << "outbound.c: " << outbound_data.c_str() << std::endl;    outbound_data=_inittype+outbound_data;    //now send along    in.dowrite(outbound_data); } 

edit. seem have found culprit. wanted prepend char outbound string did this: _inittype const char = 0x01.

it appears cannot use + operator concatenate const char string. mess .c_str() return.

void atodo::sendback(protocolbaseserver & in){    std::ostringstream archive_stream;    {      boost::archive::text_oarchive archive(archive_stream);    archive << *this;    }      archive_stream.flush();    std::string outbound_data=archive_stream.str(); //type needs first factory create correct object    std::cout << "outbound: " << outbound_data << std::endl;    std::cout << "outbound.c: " << outbound_data.c_str() << std::endl;    outbound_data=_inittype+outbound_data;    //now send along    in.dowrite(outbound_data); } 

i figured out. _inittype variable not being set 0x01 thought. set 0x00.

perhaps need close archive before using results:

{     boost::archive::text_oarchive archive(archive_stream);     archive << *this; } archive_stream.flush(); std::string outbound_data=archive_stream.str(); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -