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?
proto3 basically makes all fields optional.
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.
Protobuf treats strings as primitive types and therefore they can not be null.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With