Ben Chuanlong Du's Blog

It is never too late to learn.

Tips on Protobuf

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

oneof vs enum

Prefer to have oneof with a string field describing the specific type of oneof.

message A { // A here is the "interface".
  string name = 1;
  string a_type = 2; // Or an enum. See AIP-126 and AIP-143 for more information.

  // .. Anything else that applies to all A's.

  // Stuff that's specific to the concrete types.
  oneof content {
    B b = 3;
    C c = 4;
    // ...
  }
}

References

Comments