jjzjj

getSerializedSize

全部标签

java - Protocol Buffers 中 getSerializedSize() 的性能损失

在使用writeTo(OutputStream)序列化消息之前,在GPB消息上调用getSerializedSize()是否会降低性能?在将消息写入输出流之前,我需要知道消息的大小。我在Java上使用GPB。 最佳答案 没有性能损失。来自thisthread的第二条消息在Protobuf邮件列表上:YoucancallgetSerializedSize()tofindoutthemessagesizeaheadoftime.Notethatcallingthisdoesn'tactuallywasteanytimesincether