protobuf基础概念

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 &
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值