Thanks Zach. The documentation is generated from comments in the source
code coded_stream.h
<https://github.com/google/protobuf/blob/master/src/google/protobuf/io/coded_stream.h>.
Could you help send us a patch to fix this problem? (Or file an issue on
the github site https://github.com/google/protobuf).

On Mon, Nov 3, 2014 at 1:19 PM, <acidto...@gmail.com> wrote:

> On the page "
> https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.io.coded_stream
> "
>
> there is an example at the top of the page which contains code that
> appears to show a user how to create and serialize a message to a file.
> However the flags to open the file lack the O_CREAT flag which allows
> creating the file if it doesn't exist. I was troubleshooting a situation
> where this snippet was used and compiled, but never created a file.
>
> The full snippet is below along with my correction below that.
>
> Hopefully this saves others some time after copy/pasting that example and
> finding it doesn't write anything.
>
> Cheers,
> Zach Davis
>
> int fd = open("myfile", O_WRONLY);
> ZeroCopyOutputStream* raw_output = new FileOutputStream(fd);
> CodedOutputStream* coded_output = new CodedOutputStream(raw_output);
>
> int magic_number = 1234;
> char text[[]] = "Hello world!";
> coded_output->WriteLittleEndian32(magic_number);
> coded_output->WriteVarint32(strlen(text));
> coded_output->WriteRaw(text, strlen(text));
>
> delete coded_output;
> delete raw_output;
> close(fd);
>
> int fd = open("myfile", O_CREAT | O_WRONLY);
> ZeroCopyOutputStream* raw_output = new FileOutputStream(fd);
> CodedOutputStream* coded_output = new CodedOutputStream(raw_output);
>
> int magic_number = 1234;
> char text[[]] = "Hello world!";
> coded_output->WriteLittleEndian32(magic_number);
> coded_output->WriteVarint32(strlen(text));
> coded_output->WriteRaw(text, strlen(text));
>
> delete coded_output;
> delete raw_output;
> close(fd);
>
>  --
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to