开发者

Performance penalty of getSerializedSize() in Protocol Buffers

开发者 https://www.devze.com 2022-12-14 04:08 出处:网络
Is there a performance penalty for calling getSerializedSize() on a GPB message before serializing the message with writeTo(OutputStream)?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消