Data is getting overwriting instead of appending in SerializeDelimitedToOstream

Viewed 55

[Scenario]

I am attempting to serialize data at every iteration to a file through SerializeDelimitedToOstream API of C++ Protobuf library. Once all the iterations are done, I am deserializing the final file with the serialized data to a json for checking the content. For deserializing I use, ParseDelimitedFromZeroCopyStream API to verify the data.

[Expectation]

Data from all iterations must be appended to the file and the final json must contain data from all iterations.

[Observation]

Data from the very last iteration is present. Nothing else. When I put a size check on the file per iteration, I can observe an increase in size. But deserializing results in just the last iteration data.

[Code]

Serializing Process:

loop{
//opening the file using 
std::fstream output(fileName, ios::out | ios::binary | ios::app);
//Serializing data using
google::protobuf::util::SerializeDelimitedToOstream(*Message, &output);}

Deserialization process:

std::fstream input(fileName, std::ios::in | std::ios::binary);
google::protobuf::io::IstreamInputStream zstream(&input);
google::protobuf::util::ParseDelimitedFromZeroCopyStream( &<obj_main_message>,&zstream, &bStatus);

Note: obj_main_message is our Custom Proto message structure. Any ideas on how to fix this?

0 Answers
Related