Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does removing existing field from protobuf message cause issues?

I am having one protobuf message -

message Sample{
    string field1 = 1;
    string field2 = 2;
    string field3 = 3;
}

These messages are stored in datastore in binary format. So if I want to remove any of the defined field in the above message will it cause any issue in deserialization of the message from datastore?

like image 213
Rahul Vedpathak Avatar asked Jul 08 '20 12:07

Rahul Vedpathak


People also ask

Are all fields optional in proto3?

proto3 basically makes all fields optional.

Can you rename protobuf fields?

Renaming a field - With Protobuf content, the field names are only used in generated code. The field number is used to identify fields on the network. Renaming a field isn't a protocol breaking change for Protobuf. However, if a server is using JSON content then renaming a field is a breaking change.

Can protobuf fields be null?

Protobuf treats strings as primitive types and therefore they can not be null.

What is repeated field in protobuf?

repeated : this field can be repeated any number of times (including zero) in a well-formed message. The order of the repeated values will be preserved.


2 Answers

No. Removing fields is fine, although you might want to mark it reserved so that nobody reuses it in an incompatible way. New code with old data (with the field) will silently ignore it; old code with new data will just load without the field populated, since everything in proto3 is implicitly optional. This was more of a problem in proto2, when required was a thing. Another option is to leave the field but mark it with [deprecated = true] - it'll still exist and be populated, but some tools will mark the member with the platform-specific obsolete markers for that language/framework.

like image 97
Marc Gravell Avatar answered Oct 09 '22 02:10

Marc Gravell


Adding and removing fields will not cause safety issues as mentioned in the answer from Marc. The only safety you should care about it is to mark the field as reserved. This will ensure that no one uses the same field number accidentally in future

like image 42
Sushil Singh Avatar answered Oct 09 '22 02:10

Sushil Singh