protocol-buffersprotobuf-netproto

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?


Solution

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