Comment #5 on issue 469 by how to write/read more than one piece of message to/from a text file in c++

Yes,it is just binary data chunk. When I open the file stored some protobuf messages, it seems like that the SerializeToString method forms a c++ string with '\n' as the last character. And when debugging, the first character of the serielized string is '\n' whose ASCII code is 0x0A. if you try parse it in this way,it will work: head a character '\n' at the buffer that receive the parsed binary data chunk gotten from readline.the c++ example code is like:
        string fPath("message.txt");
        string strMsg;
        char buf[1024] = {0};
        fstream f;,std::ios_base::in | std::ios_base::binary);
                buf[0] = '\n';
                f.getline(buf+1,sizeof(buf) - sizeof(char));
                string strTmp(buf);

At most of the time, it will work, yet there is a problem: when it failed to parse, you can do nothing, reading source code, it's a much lot of work. And I have come across this problem. In other words, the parsing method by heading a character '\n' is unreliable or unstable.

Any one have other Feasible way to read/write messages from/to a file? Thanks.

You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:

You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To post to this group, send email to
Visit this group at
For more options, visit

Reply via email to