If i have a 209 byte size data of about 50 parameters, if i use protobuf to serialize it,what would the size be like?

42 views
Skip to first unread message

Rishabh Unikrishanan

unread,
Jan 30, 2022, 5:10:25 AM1/30/22
to Protocol Buffers
An estimation,approximation ,docs or any additional resources would be helpful.Thanks.

Marc Gravell

unread,
Jan 30, 2022, 7:42:41 AM1/30/22
to Rishabh Unikrishanan, Protocol Buffers
You say "209 byte size" - using what measure is it 209 bytes? And what is the data? The payload size in protobuf often depends on the specific data, for example:

- for any fields: whether it is the default / unset value, vs whether it is a non-detault / explicitly set value, can change whether the field is serialized *at all*
- different values can take different sizes; for string data, we're talking about the UTF8 length; for integer data, we can usually think of the data as "7 bits useful data per byte", so a small integer might take one or two bytes, but a very large integer might take 5, 7, whatever bytes (negatives take more explaining and nuance)
- the field header size depends on the magnitude of the field number; field 7 takes 1 byte, but field 42 takes 2 bytes for the header, etc

For 50 fields, assuming we number them 1-50 and all have explicit values and are sent, we're talking about 85 bytes just for the field headers. If they're all small-medium integer values, maybe another 100 bytes for the values, so round up: maybe 200 bytes. If we presume that maybe half the fields don't have explicit values, maybe half that to 100. If the data is strings or sub-objects, it'll be bigger.

The best thing to do for a better answer is to test it using realistic data for your scenario, and simply measure it.

On Sun, 30 Jan 2022, 10:10 Rishabh Unikrishanan, <xxbys...@gmail.com> wrote:
An estimation,approximation ,docs or any additional resources would be helpful.Thanks.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/575d19c7-0d5e-4b86-bdec-e6a5a21d4d6cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages