protobuf命名规则

笔者最近在使用protobuf进行数据传输的时候,发现序列化后的proto数据使用node.js转化为json字符串后, proto数据中的变量如frameId自动变成了frameid, 导致不能正确的从json转换回proto数据格式,最后发现还是proto命名规则搞的鬼, 使用驼峰命名的成员变量如frameID, 在使用proto的方法进行赋值时,会默认变成: frame.set_frameid(int64),使得最后的变量转成了frameid名字,因此造成了问题. 故而笔者将proto命名规则转录于下,以后提醒自己,严格按照规范的文档进行编写.

Message And Field Names

Use CamelCase (with an initial capital) for message names – for example, SongServerRequest. Use underscore_separated_names for field names – for example, song_name.
按: message使用驼峰式命名, 首字母大写,成员数据使用下划线分隔命名

message SongServerRequest {
  required string song_name = 1;
}

Using this naming convention for field names gives you accessors like the following:

C++:
  const string& song_name() { ... }
  void set_song_name(const string& x) { ... }

Java:
  public String getSongName() { ... }
  public Builder setSongName(String v) { ... }

Enums

按: 枚举类型使用驼峰式命名, 首字母大写,每一项使用下划线大写分隔命名
Use CamelCase (with an initial capital) for enum type names and CAPITALS_WITH_UNDERSCORES for value names:

enum Foo {
  FIRST_VALUE = 0;
  SECOND_VALUE = 1;
}

Each enum value should end with a semicolon, not a comma.

Services

按: grpc的函数接口使用驼峰式命名,首字母大写, 成员数据使用驼峰式命名
If your .proto defines an RPC service, you should use CamelCase (with an initial capital) for both the service name and any RPC method names:

service FooService {
  rpc GetSomething(FooRequest) returns (FooResponse);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值