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]
相关文章推荐
- 网马生成器 MS Internet Explorer XML Parsing Buffer Overflow Exploit (vista) 0day
- Windows XP Service Pack 3 RC1 v.3244 winxp补丁3 提供下载
- Run As Service runassrv.exe 详细参数第1/2页
- php中ob(Output Buffer 输出缓冲)函数使用方法
- PHP STRING 陷阱原理说明
- asp.net String.IsNullOrEmpty 方法
- asp.net Web Service 接口大量数据传输解决方案
- javascript String 对象
- mysql输出数据赋给js变量报unterminated string literal错误原因
- jquery里的each使用方法详解
- javascript String 的扩展方法集合
- C#中string与byte[]的转换帮助类-.NET教程,C#语言
- javascript下string.format函数补充
- Silverlight中动态获取Web Service地址
- Ruby语言中的String深入理解
- String与string的区别(注意大小写)
- 解决mysql不能插入中文Incorrect string value
- javascript String split方法误操作
- Javascript string 扩展库代码
- MySql 错误Incorrect string value for column