If I change,
syntax = "proto3";
package a.v0;
message HtmlStore{
string html = 1;
}
to
syntax = "proto3";
package a;
message HtmlStore{
string html = 1;
}
I have a python API which returns protobuf. There are existing clients consuming the API. I want to change protobuf definition of certain elements and I want to know if it will break the existing clients?
It can accept input crafted by later versions of protobuf. The sender is backward compatible because it's creating output that can be consumed by earlier versions. So long as you're careful about when and how you change and remove fields, your protobuf will be forward and backward compatible.
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.
JSON is usually easier to debug (the serialized format is human-readable) and easier to work with (no need to define message types, compile them, install additional libraries, etc.). Protobuf, on the other hand, usually compresses data better and has built-in protocol documentation via the schema.
Protobuf reserved fields If a field is removed from a message in a new version of the service, that field number should never be reused. You can enforce this behavior by using the reserved keyword.
Note: if you're using JSON encoding: all bets are off.
If you're using binary encoding, the package
isn't usually part of the wire format - unless you've made use of the google.protobuf.Any
feature.
So assuming you haven't used Any
: changing the package
will be completely invisible in terms of what is sent, and nobody will be impacted.
However! If they receive an updated version of the .proto and run the code-gen as part of their build, then their previously working code may cease to compile - requiring them to remove the .v0
from code that references those types.
The only things that are sent on the wire are the field-numbers (1 in the case of html
), the wire-type (length-prefixed in the case of html
- so: wire-type 2) and the actual values. You can also safely rename HtmlStore
and html
(under the same conditions re Any
etc).
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