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

隨筆 - 70, 文章 - 0, 評(píng)論 - 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];

謹(jǐn)慎使用required描述符,因?yàn)樵谝院蟮臄U(kuò)展中,很難去掉該字段。建議全部使用optional和repeated來(lái)實(shí)現(xiàn)。

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

int32, sint32, int64, sint64
sint32, sint64支持負(fù)數(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) 遠(yuǎn)程過(guò)程調(diào)用


FAQ
1  問(wèn)題:執(zhí)行protoc.exe產(chǎn)生的代碼編譯出錯(cuò)。
    描述:當(dāng)跨目錄生成代碼時(shí)(用到import "xxx/aaa.proto";),執(zhí)行protoc.exe --cpp_out=. test.proto,產(chǎn)生的代碼.cc里有::protobuf_AddDesc....,這個(gè)函數(shù)中總是多了個(gè)xxx(即那個(gè)目錄名),導(dǎo)致編譯失敗。
    解決:同一個(gè)項(xiàng)目里執(zhí)行protoc.exe的目錄不要改變,與該項(xiàng)目的Makefile在同一個(gè)目錄下。
如項(xiàng)目在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) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): 數(shù)據(jù)

評(píng)論

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

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>
            欧美精品1区| 亚洲精品乱码久久久久久日本蜜臀 | 亚洲精品一区在线观看香蕉| 99riav久久精品riav| 欧美日韩成人综合天天影院| 正在播放日韩| 久久久久久有精品国产| 永久免费精品影视网站| 噜噜噜噜噜久久久久久91| 亚洲人成在线观看| 午夜精品久久久久久久99水蜜桃| 国产色综合天天综合网| 免费av成人在线| 一区二区精品在线| 久久免费视频在线观看| 亚洲精选中文字幕| 国产农村妇女精品一区二区| 久久女同精品一区二区| 日韩一级在线观看| 久久精品91久久香蕉加勒比| 亚洲精品精选| 国产精自产拍久久久久久蜜| 免播放器亚洲| 亚洲欧美在线看| 亚洲国产精品久久久久秋霞蜜臀| 亚洲欧美国产77777| 伊人久久婷婷色综合98网| 欧美日本网站| 久久露脸国产精品| 亚洲婷婷免费| 亚洲激情图片小说视频| 亚洲欧美日韩另类精品一区二区三区| 欧美亚州在线观看| 午夜精品美女自拍福到在线| 亚洲深夜激情| 亚洲高清视频中文字幕| 国产精品嫩草影院av蜜臀| 久久久蜜桃一区二区人| 一本色道久久综合亚洲精品不| 久久久久久夜精品精品免费| 中日韩男男gay无套| 影音先锋另类| 国产精品一区在线观看| 欧美猛交免费看| 久久久青草青青国产亚洲免观| 亚洲图片欧美午夜| 亚洲国产精品久久久久久女王| 欧美在线视频在线播放完整版免费观看 | 夜夜嗨网站十八久久| 老司机免费视频一区二区| 久久久久国内| 亚洲日本无吗高清不卡| 好吊色欧美一区二区三区视频| 国产精品扒开腿做爽爽爽视频| 欧美黄色免费| 免费一级欧美片在线观看| 久久精品免费观看| 亚洲自拍高清| 亚洲一区二区精品视频| 一区二区冒白浆视频| 亚洲精品午夜精品| 亚洲国产精品v| 亚洲电影免费观看高清完整版| 免费欧美在线| 欧美1级日本1级| 欧美国产极速在线| 欧美成人午夜激情视频| 欧美18av| 亚洲国产毛片完整版 | 狂野欧美激情性xxxx欧美| 欧美一区二区免费视频| 亚洲欧美日韩国产中文在线| 亚洲免费一在线| 午夜一区二区三区不卡视频| 先锋影音一区二区三区| 亚洲欧美日本伦理| 性一交一乱一区二区洋洋av| 性久久久久久久久| 欧美中文日韩| 久久免费高清视频| 欧美3dxxxxhd| 亚洲黄色大片| 99re这里只有精品6| 一区二区三区国产| 亚洲网友自拍| 欧美一区国产二区| 狼狼综合久久久久综合网| 欧美成人国产一区二区| 免费h精品视频在线播放| 夜夜狂射影院欧美极品| 久久激情视频久久| 久久久女女女女999久久| 久久婷婷蜜乳一本欲蜜臀| 久久在线播放| 亚洲电影免费观看高清完整版在线观看| 亚洲第一精品久久忘忧草社区| 亚洲国产天堂久久国产91| 亚洲美女一区| 亚洲男人影院| 免费看精品久久片| 欧美日韩国产综合视频在线| 国产美女高潮久久白浆| 一区二区三区自拍| 99在线热播精品免费| 午夜国产欧美理论在线播放| 久久久伊人欧美| 亚洲精品一区二区三区四区高清| 亚洲一区在线直播| 久久婷婷综合激情| 欧美视频福利| 尤物九九久久国产精品的分类| 亚洲另类自拍| 久久久久一区二区三区| 亚洲国产欧美久久| 午夜精品电影| 久久色在线观看| 久久av在线看| 欧美精品一区二区三区视频 | 亚洲第一偷拍| 亚洲一级在线| 奶水喷射视频一区| 亚洲欧美国产精品va在线观看| 欧美mv日韩mv国产网站| 国产精品美女| 亚洲三级网站| 久久综合九色综合久99| 99精品黄色片免费大全| 久久米奇亚洲| 国产日韩精品一区观看| 一本到高清视频免费精品| 美腿丝袜亚洲色图| 亚洲在线播放| 欧美性视频网站| 亚洲精品国产精品国自产在线| 欧美制服丝袜第一页| aaa亚洲精品一二三区| 另类春色校园亚洲| 国产一区二区三区四区hd| 亚洲欧美另类中文字幕| 亚洲欧洲日韩女同| 久久久久在线观看| 国产一区二区三区四区五区美女| 亚洲欧美日韩精品久久| 亚洲精品日韩在线| 男女精品视频| 在线不卡亚洲| 久久亚洲私人国产精品va| 亚洲欧美日韩在线一区| 国产精品日本精品| 亚洲一区二区3| 一本久道久久综合中文字幕| 欧美国产日韩免费| 亚洲国产老妈| 欧美国产日韩xxxxx| 久久久久久久久一区二区| 国产字幕视频一区二区| 久久大香伊蕉在人线观看热2| 亚洲午夜免费福利视频| 欧美午夜精品久久久久久孕妇| 99国内精品久久| 亚洲清纯自拍| 欧美日韩美女| 亚洲视频一区在线观看| 91久久精品一区二区三区| 欧美v日韩v国产v| 亚洲伦理网站| 亚洲美女在线看| 欧美肉体xxxx裸体137大胆| 亚洲一区在线播放| 在线视频欧美一区| 国产精品一区久久久久| 久久久久久久网| 久久国产毛片| 91久久国产自产拍夜夜嗨| 亚洲国产高清一区| 欧美日韩一区二区三区在线| 亚洲永久网站| 亚洲欧洲av一区二区三区久久| 国产亚洲网站| 欧美激情按摩| 欧美日韩综合久久| 欧美在线视频一区| 久久综合中文| 亚洲视频www| 午夜视频一区在线观看| 在线国产亚洲欧美| 亚洲激情不卡| 国产精品亚洲综合久久| 久久久一区二区三区| 欧美成人a视频| 亚洲综合国产精品| 欧美在线观看视频| 亚洲乱码久久| 亚洲欧美日韩区| 亚洲欧洲日韩女同| 亚洲视频精品在线| 精品动漫3d一区二区三区| 亚洲精品九九| 狠狠色综合网| 亚洲精选一区|