您的位置:首页 > 产品设计 > UI/UE

Protocol Buffers:Style Guide

2011-07-11 09:46 281 查看

Style Guide 风格指南

[align=left]注:这是本人的翻译,可能不准确,可能有错误,但是基本上可以理解,希望能对大家有所帮助!(转载请注明出处:本文来自learnhard的博客:http://www.codelast.com/http://blog.csdn.net/learnhard/)[/align][align=left]
[/align][align=left]This document provides a style guide for .proto files. By following these conventions, you'll make your protocol buffer message definitions and their corresponding classes consistent and easy to read.[/align][align=left]本文档提供了.proto文件的书写风格指南。通过遵守这些约定,你的protocol buffer消息定义和它们的对应类将会风格一致且易于阅读。[/align][align=left] [/align][align=left]Message And Field Names 消息和字段名[/align][align=left]Use CamelCase (with an initial capital) for message names – for example, SongServerRequest. Use underscore_separated_names for field names – for example, song_name.[/align][align=left]消息名使用驼峰格式(每个单词首字母大写)来书写——例如SongServerRequest。字段名使用小写的下划线分隔式(underscore_separated_names)来书写——例如song_name[/align][align=left](转载请注明出处:本文来自learnhard的博客:http://www.codelast.com/http://blog.csdn.net/learnhard/)[/align][align=left]
[/align][align=left]message SongServerRequest {[/align][align=left] required string song_name = 1;[/align][align=left]}[/align][align=left]Using this naming convention for field names gives you accessors like the following:[/align][align=left]字段名使用这种形式的命名约定的话,生成的访问类中的函数就有如下形式:[/align][align=left]C++:
 conststring& song_name(){…}
 void set_song_name(conststring& x){…} Java:
 public String getSongName(){…}
 public Builder setSongName(String v){…}
[/align][align=left]Enums 枚举[/align][align=left]Use CamelCase (with an initial capital) for enum type names and CAPITALS_WITH_UNDERSCORES for value names:[/align][align=left]枚举名使用驼峰格式(每个单词首字母大写)来书写,值名使用大写的下划线分隔式(CAPITALS_WITH_UNDERSCORES)来书写:[/align][align=left]enum Foo {
  FIRST_VALUE =1;
  SECOND_VALUE =2;
}[/align][align=left]Each enum value should end with a semicolon, not a comma.[/align][align=left]每一个枚举值都应该以分号结尾,而不是逗号。[/align][align=left]文章来源:http://www.codelast.com/ [/align][align=left]Services 服务[/align][align=left]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:[/align][align=left]如果你的.proto文件定义了一个RPC服务,那么服务名和任何RPC函数名都应该使用驼峰格式(每个单词首字母大写)来书写:[/align][align=left]service FooService {[/align][align=left] rpc GetSomething(FooRequest) returns (FooResponse);[/align][align=left]}[/align][align=left] [/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息