views:

57

answers:

1

Is there a performance penalty for calling getSerializedSize() on a GPB message before serializing the message with writeTo(OutputStream)?

I need to be able to know the size of a message before writing it to an output stream.

I'm using GPB on Java.

+2  A: 

There is no performance penalty. From the second message of this thread on the Protobuf mailing list:

You can call getSerializedSize() to find out the message size ahead of time. Note that calling this doesn't actually waste any time since the result is cached, and it would have to be called during serialization anyway.

ire_and_curses