example:
message Foo {
...
string AccountToken = 3
string BusinessToken = 4
...
}
since those 2 fields want to be deprecated by the project owner, can I safely remove those 2 fields just by deleting and regenerate the code then remove all reference?
Yes you can remove them. If the other side still sends these fields your newer code will just ignore them. But just like @LeiYang mentioned, use the deprecated syntax. Things will go wrong if a developer later uses index 3 or 4 for a different field. Especially if it is not of the same type, string in your case.
It is important to understand that the serialisation of Protocol Buffers is made possible with these tags. Removing them could cause unexpected behaviours during deserialisation.
So be aware that removing these two fields and not using the reserved keyword can break backward and forward compatibility. If a later version of your schema uses the 3 and 4 as tags and some old version of your code still use these tags as AccountToken and BusinessToken, you'll have unexpected behaviours.
in order to safely remove these fields, you can do:
message Foo {
reserved 3, 4;
...
}
and optionally you can reserve the field name so that the schema do not use the AccountToken and BusinessToken fields' name and thus don't conflict with your code (eg: you go back to older version of your code and a field is called business_token but it doesn't have the same meaning anymore with the new schema). To do that you can do:
message Foo {
reserved 3, 4;
reserved "business_token", "account_token"; // assuming they are called like this
...
}
By doing the first step, and optionally the second, you ensure full compatibility (backward and forward).
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