青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 70, 文章 - 0, 評論 - 9, 引用 - 0
數(shù)據(jù)加載中……

Protocol Buffers (協(xié)議緩沖) 之 Language Guide

Assigning Tags
As you can see, each field in the message definition has a unique numbered tag. These tags are used to identify your fields in the message binary format, and should not be changed once your message type is in use. Note that tags with values in the range 1 through 15 take one byte to encode. Tags in the range 16 through 2047 take two bytes. So you should reserve the tags 1 through 15 for very frequently occurring message elements. Remember to leave some room for frequently occurring elements that might be added in the future.
The smallest tag number you can specify is 1, and the largest is 229 - 1, or 536,870,911. You also cannot use the numbers 19000 though 19999 (FieldDescriptor::kFirstReservedNumber through FieldDescriptor::kLastReservedNumber), as they are reserved for the Protocol Buffers implementation - the protocol buffer compiler will complain if you use one of these reserved numbers in your .proto.

For historical reasons, repeated fields of basic numeric types aren't encoded as efficiently as they could be. New code should use the special option [packed=true] to get a more efficient encoding. For example:
repeated int32 samples = 4 [packed=true];

謹慎使用required描述符,因為在以后的擴展中,很難去掉該字段。建議全部使用optional和repeated來實現(xiàn)。

Adding Comments
To add comments to your .proto files, use C/C++-style // syntax.

int32, sint32, int64, sint64
sint32, sint64支持負數(shù)
更多:

.proto Type Notes C++ Type Java Type
double double double
float float float
int32 Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. int32 int
int64 Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. int64 long
uint32 Uses variable-length encoding. uint32 int[1]
uint64 Uses variable-length encoding. uint64 long[1]
sint32 Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. int32 int
sint64 Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. int64 long
fixed32 Always four bytes. More efficient than uint32 if values are often greater than 228. uint32 int[1]
fixed64 Always eight bytes. More efficient than uint64 if values are often greater than 256. uint64 long[1]
sfixed32 Always four bytes. int32 int
sfixed64 Always eight bytes. int64 long
bool bool boolean
string A string must always contain UTF-8 encoded or 7-bit ASCII text. string String
bytes May contain any arbitrary sequence of bytes. string ByteString


Optional Fields And Default Values
If the default value is not specified for an optional element, a type-specific default value is used instead: for strings, the default value is the empty string. For bools, the default value is false. For numeric types, the default value is zero. For enums, the default value is the first value listed in the enum's type definition.

Enumerations
You can define enums within a message definition, as in the above example, or outside – these enums can be reused in any message definition in your .proto file. You can also use an enum type declared in one message as the type of a field in a different message, using the syntax MessageType.EnumType.

Importing Definitions
In the above example, the Result message type is defined in the same file as SearchResponse – what if the message type you want to use as a field type is already defined in another .proto file?
You can use definitions from other .proto files by importing them. To import another .proto's definitions, you add an import statement to the top of your file:
import "myproject/other_protos.proto";
The protocol compiler searches for imported files in a set of directories specified on the protocol compiler command line using the -I/--import_path flag. If no flag was given, it looks in the directory in which the compiler was invoked.

Updating A Message Type
If an existing message type no longer meets all your needs. It's very simple to update message types without breaking any of your existing code. Just remember the following rules:
Don't change the numeric tags for any existing fields.
Any new fields that you add should be optional or repeated. This means that any messages serialized by code using your "old" message format can be parsed by your new generated code, as they won't be missing any required elements. You should set up sensible default values for these elements so that new code can properly interact with messages generated by old code. Similarly, messages created by your new code can be parsed by your old code: old binaries simply ignore the new field when parsing. However, the unknown fields are not discarded, and if the message is later serialized, the unknown fields are serialized along with it – so if the message is passed on to new code, the new fields are still available. Note that preservation of unknown fields is currently not available for Python.
Non-required fields can be removed, as long as the tag number is not used again in your updated message type (it may be better to rename the field instead, perhaps adding the prefix "OBSOLETE_", so that future users of your .proto can't accidentally reuse the number).
A non-required field can be converted to an extension and vice versa, as long as the type and number stay the same.
int32, uint32, int64, uint64, and bool are all compatible – this means you can change a field from one of these types to another without breaking forwards- or backwards-compatibility. If a number is parsed from the wire which doesn't fit in the corresponding type, you will get the same effect as if you had cast the number to that type in C++ (e.g. if a 64-bit number is read as an int32, it will be truncated to 32 bits).
sint32 and sint64 are compatible with each other but are not compatible with the other integer types.
string and bytes are compatible as long as the bytes are valid UTF-8.
Embedded messages are compatible with bytes if the bytes contain an encoded version of the message.
fixed32 is compatible with sfixed32, and fixed64 with sfixed64.
Changing a default value is generally OK, as long as you remember that default values are never sent over the wire. Thus, if a program receives a message in which a particular field isn't set, the program will see the default value as it was defined in that program's version of the protocol. It will NOT see the default value that was defined in the sender's code.

Extensions
a.proto:
message Foo {
  // ...
  extensions 100 to 199;
}
b.proto:
import "a.proto"
extend Foo {
  optional int32 bar = 126;
}
Similarly, the Foo class defines templated accessors HasExtension(), ClearExtension(), GetExtension(), MutableExtension(), and AddExtension(). All have semantics matching the corresponding generated accessors for a normal field.

Defining Services
RPC (Remote Procedure Call) 遠程過程調(diào)用


FAQ
1  問題:執(zhí)行protoc.exe產(chǎn)生的代碼編譯出錯。
    描述:當跨目錄生成代碼時(用到import "xxx/aaa.proto";),執(zhí)行protoc.exe --cpp_out=. test.proto,產(chǎn)生的代碼.cc里有::protobuf_AddDesc....,這個函數(shù)中總是多了個xxx(即那個目錄名),導(dǎo)致編譯失敗。
    解決:同一個項目里執(zhí)行protoc.exe的目錄不要改變,與該項目的Makefile在同一個目錄下。
如項目在E:\workspace\test\qt\test2,那么執(zhí)行:protoc.exe -I=/e/workspace/test/qt/test2/ --cpp_out=/e/workspace/test/qt/test2/ /e/workspace/test/qt/test2/protobuf/personalmain/LPersonalMainCategory.proto

posted on 2011-01-26 09:19 seahouse 閱讀(1450) 評論(1)  編輯 收藏 引用 所屬分類: 數(shù)據(jù)

評論

# re: Protocol Buffers (協(xié)議緩沖) 之 Language Guide  回復(fù)  更多評論   

protobuf_AddDesc...我也遇到了
2012-05-23 10:24 | 秒大刀
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美激情一区| 欧美成人高清视频| 亚洲欧美激情诱惑| 国产婷婷97碰碰久久人人蜜臀| 午夜久久久久久| 亚洲欧美日韩国产精品| 国产一区在线看| 欧美电影在线播放| 欧美极品aⅴ影院| 亚洲欧美在线aaa| 久久国产日韩| 亚洲裸体俱乐部裸体舞表演av| 9久re热视频在线精品| 国产精品久久二区二区| 久久久久在线观看| 欧美激情在线播放| 欧美专区福利在线| 欧美.日韩.国产.一区.二区| 亚洲一区二区高清视频| 香蕉av777xxx色综合一区| 亚洲国产另类 国产精品国产免费| 欧美激情亚洲自拍| 国产精品羞羞答答xxdd| 欧美国产日产韩国视频| 国产精品久久久久久久久果冻传媒| 久久久久9999亚洲精品| 欧美日韩成人综合在线一区二区| 久久国产精品99精品国产| 欧美精品入口| 美女免费视频一区| 国产精品日韩高清| 亚洲观看高清完整版在线观看| 欧美视频一区二区在线观看| 久久阴道视频| 国产精品国产三级国产普通话三级 | 午夜亚洲福利在线老司机| 亚洲欧洲在线一区| 欧美一区2区视频在线观看| 中文国产成人精品| 欧美sm重口味系列视频在线观看| 欧美一区二区三区另类| 欧美久久在线| 欧美国产一区二区在线观看| 国产欧美日韩综合一区在线观看| 亚洲精品一区二区三区av| 亚洲高清不卡| 欧美在线视频免费| 欧美一级艳片视频免费观看| 欧美精品成人| 亚洲国产精品999| 伊人精品成人久久综合软件| 亚洲欧美日韩爽爽影院| 亚洲一区二区三区高清| 欧美精品在线一区| 欧美国产激情| 亚洲欧洲日韩女同| 牛牛精品成人免费视频| 欧美成人日韩| 亚洲人成亚洲人成在线观看图片| 久久久成人网| 麻豆国产精品一区二区三区 | 欧美啪啪一区| 亚洲国产经典视频| 亚洲精品在线一区二区| 欧美大片在线观看一区二区| 亚洲国产高清aⅴ视频| 亚洲精品一区二区三区四区高清| 免费日韩一区二区| 亚洲电影免费观看高清完整版在线观看| 好吊一区二区三区| 久久性色av| 亚洲国产精品成人综合| 一区二区冒白浆视频| 欧美日韩一区自拍| 亚洲一区在线观看免费观看电影高清| 亚洲免费在线播放| 国产日韩欧美a| 久久亚洲高清| 亚洲精品美女在线观看| 亚洲男人的天堂在线aⅴ视频| 国产精品成人免费| 销魂美女一区二区三区视频在线| 久久精品视频在线播放| 亚洲国产乱码最新视频| 欧美区一区二区三区| 亚洲女人天堂av| 蜜桃久久精品乱码一区二区| 91久久精品一区| 国产精品夫妻自拍| 欧美影院成人| 亚洲精品社区| 久久久国产精彩视频美女艺术照福利| 一区二区视频欧美| 欧美视频在线观看免费| 欧美一区二区三区在线| 亚洲日本成人女熟在线观看| 欧美一区二区三区在线观看视频| 黄色成人免费网站| 欧美午夜精彩| 久久综合色8888| 亚洲免费影视第一页| 亚洲电影中文字幕| 欧美在线看片a免费观看| 在线播放视频一区| 国产精品区一区| 免费观看一区| 欧美亚洲视频一区二区| 99国产一区| 欧美成人自拍视频| 久久爱www久久做| 99这里只有久久精品视频| 黑人极品videos精品欧美裸| 欧美日韩美女一区二区| 久久精品99国产精品日本| 99视频超级精品| 欧美黑人多人双交| 久久久久久久网| 性伦欧美刺激片在线观看| 亚洲毛片在线观看| 亚洲第一在线视频| 国产亚洲一区二区三区| 欧美色道久久88综合亚洲精品| 久久久久久久久一区二区| 亚洲网站在线播放| 日韩亚洲视频在线| 亚洲黄色尤物视频| 欧美成人精品1314www| 久久久久久精| 欧美一区二视频在线免费观看| 一本色道久久综合亚洲精品按摩 | 亚洲国产精品美女| 国产主播在线一区| 国产性色一区二区| 国产麻豆精品久久一二三| 国产精品国产馆在线真实露脸| 欧美国产在线视频| 欧美精品v国产精品v日韩精品| 老司机久久99久久精品播放免费| 欧美一区二区高清在线观看| 午夜欧美精品久久久久久久| 亚洲一区二区影院| 亚洲视频免费看| 亚洲视频一区二区在线观看| 一区二区三区高清| 中文亚洲免费| 亚洲免费影视第一页| 亚洲欧美日韩国产一区二区| 午夜欧美电影在线观看| 久久成人精品无人区| 久久国产精品一区二区| 久久免费精品日本久久中文字幕| 久久久久久9| 久久综合给合| 欧美日韩mp4| 国产精品区一区二区三| 国产亚洲欧美日韩一区二区| 国产日本欧美一区二区三区在线| 国产日韩精品一区二区浪潮av| 韩国精品久久久999| 在线观看一区二区精品视频| 亚洲国产精品电影| 一区二区久久| 欧美在线观看一二区| 久久综合网络一区二区| 欧美激情一区二区| 亚洲人永久免费| 亚洲欧美日韩精品| 久久婷婷国产麻豆91天堂| 欧美韩日一区二区三区| 国产精品久久久久久久久免费| 国产亚洲综合精品| 亚洲乱码国产乱码精品精天堂| 亚洲综合首页| 久久久久久成人| 亚洲精品一区二区三区樱花| 亚洲欧美日韩精品综合在线观看| 久久久综合网站| 国产精品高潮呻吟久久av无限| 精品成人乱色一区二区| 一区二区激情| 蜜桃av久久久亚洲精品| 亚洲精品一二三区| 久久久久久亚洲精品杨幂换脸| 欧美风情在线观看| 国产综合一区二区| 夜夜嗨av一区二区三区中文字幕 | 99热这里只有精品8| 欧美在线精品免播放器视频| 欧美绝品在线观看成人午夜影视| 国产精品乱人伦一区二区 | 在线免费观看一区二区三区| 中文av一区特黄| 欧美激情一区二区三区在线视频观看 | 亚洲国产精品嫩草影院| 午夜影视日本亚洲欧洲精品| 欧美金8天国| 在线观看亚洲| 久久天天狠狠| 亚洲免费一区二区| 欧美午夜性色大片在线观看|