Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the best way to deprecate a field in Protocol Buffer v3, reserved vs deprecated=true?

When using Protocol Buffers version 3, from what I can see, there are 2 ways you can deprecate a field:

Either using the deprecate field using tags:

message MyMessage {
    string deprecated_my_field = 1 [deprecated=true];
}

Or creating a reserved field ID:

message MyMessage {
    reserved 1; // Deprecated "my_field"
}

I am leaning towards reserved since then no one will be able to use the field.

Is this a bad idea?

like image 429
corgrath Avatar asked Sep 12 '25 06:09

corgrath


1 Answers

Both will work; the first option keeps the definition in the model, so it can still be accessed and queried - but it may generate a build warning when available (for clients who update from the schema). This may have useful applications in some cases.

The second option completely removes the field from the model, so any existing usages will break at build when clients update from the schema. Again, this could be good or bad, depending on how "done" you are with the field.

In some cases, the softer "mark it as a build warning, but allow access" may be preferred; in others, the hard "that doesn't exist!" approach is cleaner. It is subjective.

Either will fundamentally get the job done.

like image 139
Marc Gravell Avatar answered Sep 15 '25 02:09

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!