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.
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.
精彩评论