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

隨筆 - 70, 文章 - 0, 評論 - 9, 引用 - 0
數據加載中……

Protocol Buffers (協議緩沖) 之 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來實現。

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

int32, sint32, int64, sint64
sint32, sint64支持負數
更多:

.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) 遠程過程調用


FAQ
1  問題:執行protoc.exe產生的代碼編譯出錯。
    描述:當跨目錄生成代碼時(用到import "xxx/aaa.proto";),執行protoc.exe --cpp_out=. test.proto,產生的代碼.cc里有::protobuf_AddDesc....,這個函數中總是多了個xxx(即那個目錄名),導致編譯失敗。
    解決:同一個項目里執行protoc.exe的目錄不要改變,與該項目的Makefile在同一個目錄下。
如項目在E:\workspace\test\qt\test2,那么執行: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 閱讀(1439) 評論(1)  編輯 收藏 引用 所屬分類: 數據

評論

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

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>
            亚洲在线网站| 欧美午夜欧美| 夜夜嗨av一区二区三区网页| 亚洲第一在线视频| 91久久亚洲| 亚洲精选在线观看| 夜夜精品视频一区二区| 亚洲天堂久久| 欧美在线在线| 欧美暴力喷水在线| 亚洲免费成人av| 性欧美激情精品| 麻豆精品在线视频| 国产精品wwwwww| 狠狠v欧美v日韩v亚洲ⅴ| 亚洲国产欧美一区| 午夜免费在线观看精品视频| 久久久久在线| 日韩亚洲成人av在线| 欧美一级淫片aaaaaaa视频| 免费精品视频| 国产欧美日韩在线播放| 亚洲国产黄色| 欧美一区二区在线免费播放| 欧美不卡在线| 午夜在线观看欧美| 欧美猛交免费看| 在线观看亚洲一区| 欧美在线亚洲在线| 日韩午夜在线观看视频| 久久综合给合久久狠狠狠97色69| 欧美日韩专区| 亚洲欧洲精品一区二区三区不卡| 欧美亚洲一区二区在线观看| 亚洲国产精品传媒在线观看| 亚洲靠逼com| 老司机精品福利视频| 国产日本欧美在线观看 | 久久综合精品国产一区二区三区| 欧美激情女人20p| 在线日韩成人| 久久一日本道色综合久久| 亚洲综合国产激情另类一区| 欧美激情一区二区| 亚洲国产综合91精品麻豆| 久久久噜噜噜久久中文字免| 亚洲一区二区三区涩| 欧美日韩在线高清| 一区二区免费在线播放| 欧美搞黄网站| 久久久国产成人精品| 国产欧美丝祙| 久久国产加勒比精品无码| 中日韩美女免费视频网站在线观看| 欧美成人资源| 一区二区三区视频观看| 亚洲大胆女人| 裸体歌舞表演一区二区| 欧美在线一级va免费观看| 国产精品人人爽人人做我的可爱 | 欧美日韩国产一区二区| 亚洲精品一区二区三区蜜桃久| 久久综合九色综合久99| 欧美有码在线视频| 国内精品伊人久久久久av影院| 欧美一级日韩一级| 亚洲素人一区二区| 国产精品亚洲片夜色在线| 亚洲欧美日韩中文播放| 亚洲私人影院在线观看| 国产欧美精品日韩| 久久人人爽爽爽人久久久| 久久久精品2019中文字幕神马| 精品88久久久久88久久久| 欧美成人一区二区| 欧美精品一区二区在线观看| 国产精品99久久不卡二区| 一区二区三区日韩在线观看| 国产精品夜夜夜一区二区三区尤| 亚洲免费中文| 久久国产精品网站| 亚洲国产精品久久久久| 亚洲精品一区二区三区不| 国产精品久久久久99| 久久嫩草精品久久久精品| 欧美成人69| 香蕉久久夜色| 美女日韩在线中文字幕| 在线视频中文亚洲| 欧美在线综合| 一区二区三区四区五区视频 | 亚洲国产精品一区| 亚洲精品在线一区二区| 国产精品久久夜| 久久午夜电影网| 欧美伦理一区二区| 久久嫩草精品久久久精品| 欧美韩日一区| 久久久7777| 欧美视频一区在线观看| 久久综合精品一区| 国产精品乱码一区二区三区| 免费观看30秒视频久久| 国产精品激情电影| 亚洲国产清纯| 狠狠狠色丁香婷婷综合激情| 一本色道88久久加勒比精品 | 亚洲国产成人av| 国产日韩精品视频一区| 亚洲人成绝费网站色www| 亚洲图片你懂的| 在线视频欧美一区| 久久五月婷婷丁香社区| 午夜精品久久久久| 欧美高清视频一区二区| 欧美一区二区三区视频在线| 欧美高清视频在线 | 美女主播精品视频一二三四| 国产精品久久久久久久电影| 欧美二区在线播放| 激情av一区| 欧美一区二区三区四区在线观看 | 免费观看一区| 国产日韩欧美精品在线| 在线一区欧美| 国产精品99久久久久久www| 欧美激情精品久久久久久黑人 | 亚洲一区在线直播| 欧美sm极限捆绑bd| 欧美大成色www永久网站婷| 国产一区二区在线免费观看| 亚洲一级黄色片| 午夜精品福利电影| 国产精品美女久久久| 亚洲一区二区三区视频播放| 亚洲图片欧洲图片av| 欧美日韩国产精品专区| 亚洲国产天堂久久国产91| 亚洲国产毛片完整版| 美女性感视频久久久| 亚洲国产精彩中文乱码av在线播放| 在线看视频不卡| 免费在线看成人av| 91久久久久久| 亚洲一区日韩在线| 国产精品自在线| 欧美一区1区三区3区公司| 久久久久久久综合日本| 影音先锋日韩有码| 欧美成人黑人xx视频免费观看| 亚洲国产欧美在线| 亚洲伊人网站| 国产日韩欧美亚洲一区| 久久精品男女| 欧美激情片在线观看| 一本色道久久综合精品竹菊 | 亚洲国产三级在线| 欧美激情1区2区3区| 亚洲精品自在久久| 欧美亚洲免费电影| 怡红院精品视频在线观看极品| 免费日韩av| 亚洲天堂av综合网| 免费久久99精品国产自在现线| 最新中文字幕亚洲| 国产精品国产三级国产aⅴ浪潮| 亚洲欧美三级在线| 欧美大尺度在线观看| 亚洲欧美变态国产另类| 狠狠色狠狠色综合| 欧美日韩国产黄| 国产精品免费福利| 久久久久久久久蜜桃| 久久国产欧美| 国产专区综合网| 欧美精品日韩| 欧美一区观看| 日韩亚洲在线观看| 久久久伊人欧美| 一本大道久久a久久精二百| 国产精品自拍一区| 欧美国产日韩一二三区| 午夜一区不卡| 99国产精品国产精品久久| 麻豆freexxxx性91精品| 亚洲男女自偷自拍| 亚洲看片一区| 黄色亚洲在线| 国产精品视频男人的天堂| 欧美福利电影网| 久久久久国产精品一区三寸| 亚洲天堂第二页| 亚洲国产精品999| 久久久久久久久久久成人| 亚洲手机成人高清视频| 91久久精品一区二区三区| 国产午夜精品理论片a级探花 | 亚洲国产成人91精品| 国产精品手机在线| 欧美午夜精彩|