Monday, June 8, 2015

Google Protobuf: proto3 enhancements

Proto3 is the new version of Google Protobuf with various enhancements and additions. Let's go over them one by one.

1. Since all fields are optional by default. Hence "optional" keyword has been done away with. If nothing is specified, it will be considered optional. (Protof files just became a tad smaller)



2. Support to group fields are not longer there. Group was just another way of nesting information in messages. But it was inefficient way to do (better way, Nested Messages). Hence is no longer supported.



3. Packed repeated fields were introduced in 2.1.0. Repeated fields needed to be explicitly set packed=true to use this encoding. In proto3, repeated primitive fields have been made packed by default. They have to be set false to be disabled. 



4. Common proto types (timestamp.proto etc) have been added. They can be used after importing. This takes a step towards usable library in protobuf. See below,



5. reserverd keyword introduced. By this, user has the control over reserved field_names and field_numbers. Once declared as reserved, these can't be used anywhere in the message.

Below, the field_numbers and names can't be used anywhere in the message again. Gives us more control.


6. Support for Objective-C and C# introduced in proto3. yay!

7. There are other language specific changes for various languages.



2 comments:

  1. Support for explicit default values for optional fields (e.g. [default = -1]) also have been removed in proto3.

    ReplyDelete
  2. "reserved" has been there since proto2:
    https://developers.google.com/protocol-buffers/docs/reference/proto2-spec#reserved

    ReplyDelete