Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is protocol buffer serialization output fully deterministic?

Given a protocol buffers schema and some data, is the protocol buffers serialization deterministic across libraries and languages?

Basically, am I guaranteed that the same data will always serialize in the same way (down to the byte) regardless of the library used?

like image 503
Flavien Avatar asked Nov 01 '22 00:11

Flavien


1 Answers

In general, the same data will serialize in exactly the same way.

However, this is not guaranteed by the protobuf specifications. For example, the following differences in encoding are allowable and must decode to the same result in all conforming libraries:

  • Encoding fields in different order than the tag number order.
  • Encoding packed fields as unpacked.
  • Encoding integers as longer varint byte sequences than needed.
  • Encoding same (non-repeated) field multiple times.
  • Probably others.
like image 182
jpa Avatar answered Nov 09 '22 13:11

jpa