Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does protocol buffer handle versioning?

How does protocol buffers handle type versioning?

For example, when I need to change a type definition over time? Like adding and removing fields.

like image 595
CodingHero Avatar asked Dec 15 '11 11:12

CodingHero


People also ask

How do Protocol buffers work?

Protocol buffers are a combination of the definition language (created in . proto files), the code that the proto compiler generates to interface with data, language-specific runtime libraries, and the serialization format for data that is written to a file (or sent across a network connection).

Why is protobuf backwards compatible?

It can accept input crafted by later versions of protobuf. The sender is backward compatible because it's creating output that can be consumed by earlier versions. So long as you're careful about when and how you change and remove fields, your protobuf will be forward and backward compatible.

Does protobuf handle endianness?

Protocol buffers messages always use little-endian encoding.

Does protobuf preserve order?

Yes, repeated fields retain the order of items.


1 Answers

Google designed protobuf to be pretty forgiving with versioning:

  • unexpected data is either stored as "extensions" (making it round-trip safe), or silently dropped, depending on the implementation
  • new fields are generally added as "optional", meaning that old data can be loaded successfully

however:

  • do not renumber fields - that would break existing data
  • you should not normally change the way any given field is stored (i.e. from a fixed-with 32-bit int to a "varint")

Generally speaking, though - it will just work, and you don't need to worry much about versioning.

like image 114
Marc Gravell Avatar answered Sep 19 '22 16:09

Marc Gravell