Thanks for the suggestion.

Do you think that using std::iostream in the following scenario would
work / be a good choice?
1. read message_length
2. buffer message_length bytes into iostream variable.
3. when all data is received, use  IstreamInputStream to wrap the
iostream and have it parsed with ParseFromZeroCopyStream()

Does the iostream handles releasing the bytes already read by PB?

Thanks.

On Nov 24, 5:29 pm, Evan Jones <ev...@mit.edu> wrote:
> Gilad Ben-Ami wrote:
> > So in this case, what is the best method to use PB?
> > Should i use SerializeToArray and ParseFromArray instead of using the
> > protobuf::io streams?
>
> To use protocol buffers with an asynchronous library, you need to
> collect the data for the message is some data structure until you know
> it is all there. If performance is not critical the least effort
> approach is:
>
> 1. Read the message_length from the stream in some way.
> 2. Create a std::string.
> 3. Read message_length bytes from the stream, appending them to the
> std::string.
> 4. Use message.ParseFromString() to parse the message.
>
> This can be bad for performance because the data may be copied many
> times. If performance is really critical, you basically need to
> efficiently collect the bytes into some "buffer data structure." I'm
> assuming the ACE library probably provides something that does this?
> Then, once you have at least message_length bytes, you parse it via a
> ZeroCopyInputStream implementation.
>
> For my asynchronous library, my implementation is approximately:
>
> // assume we read the message_length from input somehow
> if (input.availableBytes() < message_length) {
>    // get called back later
>    return IO_WAIT;
>
> }
>
> // MyInputWrapper implements google::protobuf::io::ZeroCopyInputStream
> MyInputWrapper wrapper(&input, message_length);
> MyProtocolBuffer message;
> message.ParseFromZeroCopyStream(&wrapper);
>
> I hope this helps,
>
> Evan
>
> --
> Evan Joneshttp://evanjones.ca/

--

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