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

隨筆 - 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 閱讀(1450) 評論(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>
            久久久福利视频| 久久经典综合| 国产精品久久久99| 亚洲一区二区三区四区视频| 亚洲蜜桃精久久久久久久| 欧美日韩精品免费看| 在线综合视频| 午夜免费久久久久| 亚洲福利视频网站| 亚洲激情另类| 欧美91福利在线观看| 中文精品视频| 性高湖久久久久久久久| 欧美在线视频全部完| 在线观看亚洲视频啊啊啊啊| 亚洲国产欧美一区二区三区久久 | 亚洲先锋成人| 亚洲欧美激情一区二区| 在线观看视频亚洲| 亚洲每日在线| 国产一区二区日韩| 最近中文字幕日韩精品| 欧美性做爰毛片| 另类尿喷潮videofree| 在线亚洲免费视频| 国语精品一区| 久久久91精品国产一区二区三区| 亚洲精品乱码视频| 国产亚洲一区在线| 亚洲精品资源美女情侣酒店| 国产午夜精品久久| 亚洲久色影视| 在线成人免费观看| 久久免费视频在线观看| 亚洲欧美日韩国产成人精品影院| 欧美日韩免费网站| 久久综合九色欧美综合狠狠| 欧美精品一区二区精品网| 久久久久久电影| 欧美一区在线看| 亚洲校园激情| 欧美极品在线观看| 麻豆国产精品一区二区三区| 国产精品午夜视频| 亚洲美女中文字幕| 国产精品久久毛片a| 亚洲综合色丁香婷婷六月图片| 亚洲精品永久免费| 欧美日韩精品在线播放| 美女主播一区| 好吊成人免视频| 亚洲一区二区在线播放| 一级成人国产| 欧美久久九九| 91久久中文字幕| 亚洲欧洲在线看| 日韩午夜中文字幕| 亚洲精品四区| 牛牛国产精品| 欧美福利一区二区| 在线视频成人| 麻豆成人精品| 亚洲成人资源| 亚洲欧洲精品一区二区| 99精品福利视频| 国产丝袜美腿一区二区三区| 99国产一区| 亚洲伊人一本大道中文字幕| 欧美一区二区久久久| 欧美有码在线视频| 国产一区二区三区免费观看| 午夜精品一区二区在线观看| 欧美一区二区三区四区在线观看地址| 久久久久一区二区三区| 久久日韩精品| 亚洲国产一区二区视频| 欧美精品色综合| 久久久99免费视频| 在线欧美影院| 欧美成人伊人久久综合网| 亚洲日韩视频| 午夜精品免费| 黄色日韩精品| 欧美国产日韩精品免费观看| 欧美与欧洲交xxxx免费观看| 国内成人精品视频| 老司机午夜精品视频在线观看| 亚洲午夜精品| 老牛影视一区二区三区| 亚洲国语精品自产拍在线观看| 国产夜色精品一区二区av| 久久国产手机看片| 亚洲国内在线| 欧美影视一区| 亚洲国产精品久久人人爱蜜臀| 亚洲一区免费观看| 免费成人你懂的| 一区二区三区四区五区在线| 久久综合一区| 一区二区三区欧美日韩| 久久五月天婷婷| 国产一区二区三区最好精华液| 一个人看的www久久| 美女尤物久久精品| 亚洲综合成人婷婷小说| 亚洲福利视频网| 国产精品久久一区主播| 久久综合九色九九| 欧美成人午夜激情视频| 伊人伊人伊人久久| 国产精品乱码一区二三区小蝌蚪| 日韩午夜在线播放| 亚洲午夜羞羞片| 亚洲黄一区二区三区| 国产美女高潮久久白浆| 欧美日韩1区| 免费在线成人av| 久久国产精彩视频| 在线中文字幕一区| 最新国产成人av网站网址麻豆 | 国产精品成人免费| 亚洲免费观看高清在线观看 | 欧美亚一区二区| 另类成人小视频在线| 亚洲欧美一区二区视频| 99精品福利视频| 91久久精品美女高潮| 免费观看不卡av| 久久精品123| 欧美亚洲在线| 欧美一级专区| 欧美在线国产| 午夜精品美女自拍福到在线 | 久久久亚洲一区| 亚洲欧美日韩精品久久亚洲区 | 夜夜嗨av一区二区三区四区| 在线观看日韩av电影| 欧美国产精品专区| 欧美 日韩 国产 一区| 久久精品青青大伊人av| 欧美一级视频| 久久精品噜噜噜成人av农村| 性xx色xx综合久久久xx| 性色av香蕉一区二区| 亚洲欧美日韩中文视频| 亚洲男女自偷自拍| 午夜精品av| 久久成人国产| 久久婷婷久久| 免费在线亚洲| 欧美日韩精品久久| 久久gogo国模裸体人体| 欧美一区二区视频97| 欧美一区二区三区四区视频| 亚洲国产欧美在线| 亚洲美女av电影| 国产精品99久久99久久久二8 | 欧美激情精品久久久六区热门 | 久久一二三国产| 久久中文在线| 欧美日本在线| 国产精品区一区二区三| 嫩模写真一区二区三区三州| 欧美va亚洲va香蕉在线| 午夜精品福利电影| 久久久久久精| 欧美精品免费视频| 国产精品福利网站| 国产视频亚洲| 亚洲精品久久久久久下一站| 在线亚洲观看| 91久久午夜| 伊人色综合久久天天| 99精品99| 亚洲精品一区二| 欧美一级片在线播放| 蜜桃精品一区二区三区| 99国内精品久久| 久久精品麻豆| 国产精品高潮呻吟久久av无限| 欧美黑人国产人伦爽爽爽| 国产精品爽黄69| 国产精品美女www爽爽爽视频| 欧美老女人xx| 国产一区二区三区免费在线观看| 国产精品二区在线观看| 亚洲第一在线综合网站| 国模套图日韩精品一区二区| 国产日韩欧美亚洲| 亚洲人成人一区二区在线观看 | 国产精品女主播一区二区三区| 欧美激情综合在线| 国产一区在线看| 亚洲自拍三区| 亚洲人成人一区二区三区| 欧美在线综合视频| 国产精品每日更新在线播放网址| 国产精品你懂的在线| 日韩一本二本av| 欧美黄色成人网|