在使用writeTo(OutputStream)序列化消息之前,在GPB消息上调用getSerializedSize()会导致性能下降吗?
在将消息写入输出流之前,我需要能够知道消息的大小.
我在Java上使用GPB.
解决方法
没有性能损失.从Protobuf邮件列表上的
this thread的第二条消息:
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.