Protocol buffer: does changing field name break the message?

前端 未结 1 2017
别那么骄傲
别那么骄傲 2021-02-03 19:37

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

         


        
相关标签:
1条回答
  • 2021-02-03 19:58

    Changing a field name will not affected 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 that simply defining a new field.

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

    0 讨论(0)
提交回复
热议问题