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 Jones
http://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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.