I am using Google Protocol Buffer for message serialization. This is my sample proto file content.
package MessageParam;
message Sample
{
message WordRec
{
optional uint64 id = 1;
optional string word = 2;
optional double value = 3;
}
message WordSequence
{
repeated WordRec WordSeq = 1;
}
}
I am trying to serialize the message in C++ like following
MessageParam::Sample::WordSequence wordseq;
for(int i =0;i<10;i++)
{
AddRecords(wordseq.add_wordseq());
}
std::string str = wordseq.SerializeAsString();
After executing the above statement, the size of the str is 430. It is having embedded null characters in it. While I am trying to assign this str to std::wstring, std::wstring is terminating when it finds first null character.
void AddRecords(MessageParam::Sample::WordRec* wordrec)
{
int id;
cin>>id;
wordrec->set_id(id);
getline(cin, *wordrec->mutable_word());
long value;
cin>>value;
wordrec->set_value(value);
}
Value of wordseq.DebugString() is WordSeq { id: 4 word: "software" value: 1 } WordSeq { id: 19 word: "technical" value: 0.70992374420166016 } WordSeq { id: 51 word: "hardware" value: 0.626017153263092 } How can I serialize "wordseq" as string which contains embedded NULL characters ?