Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google protobuf 3: deprecated a field, but cannot remove the dependencies?

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?

like image 852
HeyThere Avatar asked Feb 18 '20 11:02

HeyThere


People also ask

Can you remove fields from Protobuf?

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.

What is the difference between proto2 and proto3?

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.

How do I set default value in Protobuf?

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.


1 Answers

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).

like image 130
Marc Gravell Avatar answered Oct 23 '22 17:10

Marc Gravell