1 year ago
#326189
L.Maple
c++ thrift serialize multiple objects to vector<string> only end with the last object result
The code is :
std::vector<std::string*> itemDataList;
for(int i = 0 ; i<4; i++){
ctr::ZwItem zwItem;
zwItem.news = newsList[i];
zwItem.__isset.news = true;
boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
TCompactProtocol compactProtocol(buffer);
zwItem.write(&compactProtocol);
std::string itemData = buffer->getBufferAsString();
INFO << newsId << " size: " << std::to_string(itemData.size());
itemDataList.emplace_back(&itemData);
}
std::ostringstream yy;
for(auto p : itemDataList){
yy << std::to_string(p->size()) << ",";
}
MI << "sizeList: [" << yy.str() << "]";
and the running log shows this:
when I print the serialized string sizes after the for loop, the 4 string pointers in itemDataList have the same size , not the expected [3033, 2581, 2938, 2458].
So what's the problem with my code?
c++
serialization
thrift
thrift-protocol
0 Answers
Your Answer