1、 Field Types:域类型指的是:数据类型,例如int32、string以及组合类型(enumerations)及other message types
field rule := required | optional | repeated,
filed type := int32 | int64 | uint32 | uint64 | double | bool | string | bytes
2、protobuf一共有三个字段修饰符:
- required:该值是必须要设置的;
- optional :该字段可以有0个或1个值(不超过1个);意味着该字段的值可以被设置也可以不设置。
- repeated:该字段可以重复任意多次(包括0次),类似于C++中的list;
3、Multiple message types can be defined in a single .proto
file. This is useful if you are defining multiple related messages – so, for example, if you wanted to define the reply message format that corresponds to your SearchResponse
message type, you could add it to the same .proto
4、Optional Fields And Default Values(可选域的缺省值)
5、枚举常量
- 你可以通过将不同的枚举常量指定为相同的值。如果这样做你需要将allow_alias设定位true,否则编译器会在别名的地方产生一个错误信息。
-
enum EnumAllowingAlias { option allow_alias = true; UNKNOWN = 0; STARTED = 1; RUNNING = 1; } enum EnumNotAllowingAlias { UNKNOWN = 0; STARTED &