Protocol buffer: does changing field name break the message?

Protocol Buffers

Protocol Buffers Problem Overview


With protocol buffer, does changing field name of a message still let it compatible backward? I couldn't find any cite about that.

Eg: original message

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;
}

Change to:

message Person {
  required string full_name = 1;
  required int32 id = 2;
  optional string email = 3;
}

Protocol Buffers Solutions


Solution 1 - Protocol Buffers

Changing a field name will not affect the protobuf encoding or compatibility between applications that use proto definitions which differ only by field names.

The binary protobuf encoding is based on tag numbers, so that is what you need to preserve.

You can even change a field type to some extent (check the type table at https://developers.google.com/protocol-buffers/docs/encoding#structure) providing its wire type stays the same, but that requires additional considerations whether, for example, changing uint32 to uint64 is safe from the point of view of your application code and, for some definition of 'better', is better than simply defining a new field.

Changing a field name will affect json representation, if you use that feature.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontibooView Question on Stackoverflow
Solution 1 - Protocol BuffersOleg EstekhinView Answer on Stackoverflow