I have a proto A that depends on proto B. Then I deprecated the field protoB:
import "protoB.proto";
message ProtoA {
string assignmentStatus = 1;
protoB proto_b = 2 [deprecated = true];
}
I'd think in this case I should be able to remove the import
statement right? But when I did that, the compiler complains about the dependency not being imported.
What's the deal here?
You generally can freely change the name and order of fields. However, when you're producing JSON serialized data with protobuf, the field names are also reserved by the receiver. This requires users to reserve field identifiers and names when removing or deprecating fields.
Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.
For bool s, the default value is false. For numeric types, the default value is zero. For enums , the default value is the first value listed in the enum's type definition. This means care must be taken when adding a value to the beginning of an enum value list.
Marking something as deprecated just ... marks it as deprecated; for example, in C# the proto_b
member would be declared but marked as [Obsolete]
. Since it still exists, it needs to know what to describe it as. The data is still accessible in your application, for example.
If you want to remove it: remove it:
message ProtoA {
string assignmentStatus = 1;
// field 2 *was* protoB proto_b = 2, now removed
}
(leaving a comment is important to avoid people accidentally reusing the field number, which could cause problems with pre-existing data).
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