Generally the most efficient way to serialize a message to stdout is:
(If your system doesn't define STDOUT_FILENO, just use the number 1.)
If you normally use C++'s cout, you might want to write to that instead:
For small messages, it may be slightly faster to serialize to a string and
then write that. But the difference there would be small, and if it matters
to you we should probably just fix the protobuf library to do this
All of these methods require that you write the size first if you intend to
write multiple messages to the stream.
On Sun, Aug 23, 2009 at 9:06 AM, Saptarshi <saptarshi.g...@gmail.com> wrote:
> I would like to write the size of the serialized message followed by
> the message(to stdout)
> One approach is to write to an array, write the length and then the
> Method 1
> v= ByteSize()
> SerializeWithCachedSizesToArray(uint8* data,)
> and then write data
> But this requires I create an array.
> Method 2
> Another approach is to write ByteSize(to stdout) and then call
> SerializeWithCachedSizes(OstreamOutputStream) directly writing to
> Is the second method more efficient? I just need to create messages
> and throw them out.
> I don't need the serialized data hanging around.
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to email@example.com
To unsubscribe from this group, send email to
For more options, visit this group at