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.
It is essential to be aware that protobuf is not necessarily the fastest option. If your data is mainly string, then JSON format might be a good choice.
Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data. It is useful in developing programs to communicate with each other over a network or for storing data.
Protocol buffers messages always use little-endian encoding. Implementations running on big-endian architectures should be doing the conversions automatically. If you are receiving data in wrong order, I would suggest using protoc --decode_raw to see whether the error occurs on the transmission or reception side.
Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With