By simple classes i mean classes/structures that do not contain vectors, stacks, linked list or any other variable length data structures.
If we have a class with some simple double, long, int,... fields, does serialized sizes of different instances of this class depend on the value of these fields? (e.g depending on number of meaningful bits, in case of ignoring left 0 bits to save space)
How do strings affect size of serialized data?
You need to read the wire format documentation, basically.
The size of floating point fields will always be fixed, but for integers there are options: fixed32
and fixed64
will be fixed (as the name suggests), but int32
, int64
, sint32
, sint64
, uint32
and uint64
are variable-length, designed to make encoding of small values efficient.
Strings are encoded as the length of the UTF-8-encoded data, then the data itself. The length itself is serialized in a variable-length format, again so that short strings are encoded efficiently.
See more on this question at Stackoverflow