Field

  • The given number must be unique among all fields for that message.
  • Reserve the deleted field number when deleting fields.
  • Use the field numbers 1 through 15 for the most-frequently-set fields.
message Foo {
  reserved 2, 15, 9 to 11;
  reserved "foo", "bar";
}

Syntaxs

Any

Oneof

  • Works like an enum or variant

Enum Specification

The following specifies the behavior of conformant implementations for protobuf. Because this is subtle, many implementations are out of conformance. See Known Issues for details on how different implementations behave.

  • When a proto2 file imports an enum defined in a proto2 file, that enum should be treated as closed.
  • When a proto3 file imports an enum defined in a proto3 file, that enum should be treated as open.
  • When a proto3 file imports an enum defined in a proto2 file, the protoc compiler will produce an error.
  • When a proto2 file imports an enum defined in a proto3 file, that enum should be treated as open.

Default Values

  • For strings, the default value is the empty string.
  • For bytes, the default value is empty bytes.
  • For bools, the default value is false.
  • For numeric types, the default value is zero.
  • For enums, the default value is the first defined enum value, which must be 0.
  • For message fields, the field is not set. Its exact value is language-dependent. See the generated code guide for details.

Explaination

假设 user.proto 是
enum E {}

大概流程是
protoc 解析 user.proto ,按照一个google那边给的 plugin.proto 规定的signature, serialize 到 protobuffer 的二进制格式到 stdin,

plugin 读 stdin 的二进制, deserialize 获得 user.proto 有什么 field 之类的信息,例子正好到mbt也是
enum E {}
plugin 也按照 plugin.proto 的规定的 signature serialize 这串 string 到二进制,由 protoc 再 deserialize ,获得这串 string 和负责写文件到 output.pb.mbt

plugin 命名规则是 protoc-gen-<lang>,要在 PATH 里
protoc 调用规则是 protoc --<lang>_out=. user.proto