Explain the Protocol Buffers binary wire format — how are fields encoded as tag-length-value and what makes it compact compared to JSON?
Last updated
Each field is a key plus value. The key is a varint (variable-length integer) holding
(field_number << 3) | wire_type.Wire type sets the layout: 0 = varint, 1/5 = fixed 64/32-bit, 2 = length-delimited (a length prefix before strings, bytes, or nested messages, giving tag-length-value).
It beats JSON by dropping field names and punctuation, encoding numbers as binary varints, and omitting fields at default values.