I think it's being buffered in the FileOutputStream -- you should be sure to delete the output streams (in the reverse order that you created them) before you close the file.
On Mon, Oct 11, 2010 at 1:07 PM, Paul Yang <mjpabl...@gmail.com> wrote: > Hi, > I am new to protocol buffers, and I am trying to serialize a message > to a file. I need to serialize the file so that in can be opened in > Java using parseDelimitedFrom(). However, when I write to the file > using SerializeToCodedStream or SerializeWithCachedSizes, nothing > happens to the serializedMessage.bin file, and it stays at 0 bytes. > Why is nothing being written to the file? I have attached the code > below: > > int fd = open("serializedMessage.bin", O_WRONLY); > > google::protobuf::io::ZeroCopyOutputStream* fileOutput = new > google::protobuf::io::FileOutputStream(fd); > > google::protobuf::io::CodedOutputStream* codedOutput = new > google::protobuf::io::CodedOutputStream(fileOutput); > > codedOutput->WriteVarint32(message1.ByteSize()); > message1.SerializeToCodedStream(codedOutput); > // also tried snap1.SerializeWithCachedSizes(codedOutput) > > close(fd); > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to proto...@googlegroups.com. > To unsubscribe from this group, send email to > protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.