The standard solution for this is to length-delimit your messages in the
file with CodedOutputStream.  So you create a CodedOutputStream for the file
(call it coded_output_stream), and then for each message, something like
(untested):

coded_output_stream.WriteVarint32(message.ByteSize());
message.SerializeToCodedStream(&coded_output_stream);

Then to read them in, for each message:

int32 size;
coded_input_stream.ReadVarint32(&size);
CodedInputStream::Limit old_limit = coded_input_stream.PushLimit(size);
message.ParseFromCodedStream(&coded_input_stream);
coded_input_stream.PopLimit(old_limit);

2010/7/23 Julian González <julian....@gmail.com>

> Hi,
>
> I am a newbie with Protocol Buffers I think I can use it in my
> application because right now I am using a CSV file and it takes a
> while to generate the file and also it is very big, I mean huge above
> 2 GB, so I thought switching to a binary format would be better I
> found protocol buffers, I really like it, it is easy and flexible but
> I could find how to write several messages of the same type in a
> single file. In my application I write samples, millions o samples and
> every sample contains like 6 different fields, I would like to use
> protocol buffer, but so far I could not find a way to write a read
> several messages. Can somebody help me?
>
> --
> 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.

Reply via email to