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

隨筆 - 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來實(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)程過程調(diào)用


FAQ
1  問題:執(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)  編輯 收藏 引用 所屬分類: 數(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>
            亚洲一二区在线| 亚洲日本理论电影| 国产精品99久久久久久久女警 | 久久精品一区二区三区中文字幕| 最新国产精品拍自在线播放| 久久久国产亚洲精品| 欧美成熟视频| 亚洲久久视频| 日韩一级黄色片| 国产精品久久久久久久久久尿 | 黄色成人av网站| 久久精品道一区二区三区| 欧美综合国产精品久久丁香| 国产视频久久网| 久久久久久夜| 免费一级欧美片在线观看| 99re6这里只有精品视频在线观看| 亚洲欧洲三级电影| 亚洲精品在线二区| 欧美大胆成人| 91久久精品国产91性色| 亚洲精品一区二区三| 男女精品视频| 亚洲人成在线观看一区二区| 国产精品欧美久久| 午夜在线视频观看日韩17c| 欧美一区二区三区在线| 99精品国产在热久久婷婷| 欧美高清在线一区| 亚洲欧美日韩综合aⅴ视频| 欧美一级在线视频| 久久久久久网| 亚洲国产欧美一区二区三区同亚洲| 亚洲欧洲在线播放| 99国产精品久久久久久久| 欧美日韩国产首页| 久久蜜桃精品| 好吊成人免视频| 久久一区二区三区国产精品| 一区二区三区免费在线观看| 久久免费国产| 亚洲狠狠丁香婷婷综合久久久| 国产精品伊人日日| 亚洲裸体俱乐部裸体舞表演av| 狠狠色噜噜狠狠色综合久 | 久久人人爽人人爽| 欧美成人午夜激情在线| 欧美日韩美女在线观看| 久久视频精品在线| 国产精品免费视频xxxx| 欧美亚洲日本一区| 欧美大学生性色视频| av成人免费在线| 欧美福利视频网站| 中文在线不卡视频| 亚洲美女av电影| 国产精品一卡| 免费不卡在线观看| 欧美国产日韩二区| 精品盗摄一区二区三区| 亚洲欧美在线网| 亚洲午夜黄色| 激情五月综合色婷婷一区二区| 欧美激情精品久久久久久大尺度 | 亚洲精品综合| 久久久99国产精品免费| 一本色道久久| 一区二区在线看| 国产精品国产a级| 一区二区三区视频在线看| 99香蕉国产精品偷在线观看| 国产亚洲激情在线| 久久成人一区| 每日更新成人在线视频| 国产精品xnxxcom| 亚洲视频网站在线观看| 欧美刺激午夜性久久久久久久| 亚洲欧美激情在线视频| 国产精品天天摸av网| 欧美高清你懂得| 久久久久综合| 亚洲国产视频一区| 久久精品国产99| 一区二区电影免费在线观看| 在线播放亚洲| 免费欧美日韩| 久久夜色精品一区| 久久国产精品一区二区| 亚洲一区三区视频在线观看| 久久国产精品黑丝| 韩国在线视频一区| 国产欧美日韩亚洲精品| 老司机亚洲精品| 日韩一区二区电影网| 亚洲韩国日本中文字幕| 欧美不卡视频一区发布| 中文av字幕一区| 亚洲毛片一区| 亚洲三级视频在线观看| 在线观看一区| 国产精品videosex极品| 欧美日韩第一页| 欧美精品啪啪| 欧美在线影院| 久久精品欧美日韩| 99热在这里有精品免费| 久久精品视频导航| 久久国产精品黑丝| 久久久综合网站| 久久久久久9| 美女啪啪无遮挡免费久久网站| 久久久噜噜噜久噜久久| 久久视频在线视频| 欧美va天堂在线| 亚洲国产欧美在线 | 久久艳片www.17c.com| 久久午夜电影网| 美女久久网站| 亚洲国产高清aⅴ视频| 欧美一区二区三区在线观看| 亚洲精品韩国| 亚洲视频电影在线| 性做久久久久久免费观看欧美| 欧美专区在线观看一区| 久久久久五月天| 亚洲国产欧洲综合997久久| 亚洲人成在线观看| 亚洲一区三区视频在线观看| 欧美亚洲三级| 欧美成人视屏| 国产精品视频一区二区高潮| 国产一区二区三区在线观看视频| 精品91在线| 日韩图片一区| 欧美一区国产二区| 欧美夫妇交换俱乐部在线观看| 91久久国产综合久久蜜月精品| 亚洲天堂av在线免费| 99这里只有久久精品视频| 亚洲在线观看免费| 麻豆免费精品视频| 国产精品成人一区二区三区夜夜夜| 国产日韩高清一区二区三区在线| 亚洲高清激情| 91久久午夜| 亚洲三级性片| 欧美在线亚洲| 亚洲黄色一区二区三区| 亚洲影视九九影院在线观看| 欧美jizzhd精品欧美巨大免费| 国产精品久久久久国产精品日日 | 99re6热在线精品视频播放速度| 亚洲午夜精品久久久久久浪潮| 久久精品国产免费观看| 欧美色大人视频| 国产精品一区在线观看| 亚洲人成毛片在线播放女女| 先锋资源久久| 亚洲精品视频一区| 久久米奇亚洲| 国产日本欧美一区二区| 亚洲精品久久| 另类天堂av| 午夜精品影院| 久久婷婷成人综合色| 国产精品豆花视频| 91久久久久久久久| 久久久中精品2020中文| 亚洲自拍偷拍网址| 久久久久久网| 国产亚洲一区二区三区在线播放| 一区二区三区www| 亚洲第一页自拍| 久久久久欧美精品| 国产亚洲欧美日韩在线一区| 亚洲欧美日韩精品久久奇米色影视| 亚洲区一区二区三区| 免费成人高清| 在线精品亚洲| 美国成人毛片| 久久久精品日韩欧美| 国产日韩欧美一区二区三区在线观看 | 亚洲国产美女精品久久久久∴| 久久久97精品| 性欧美video另类hd性玩具| 国产精品国码视频| 亚洲欧美日韩国产中文| 亚洲视频999| 国产精品日产欧美久久久久| 亚洲一区二区视频| 中文在线不卡视频| 国产精品腿扒开做爽爽爽挤奶网站| 亚洲性色视频| 亚洲视频在线观看免费| 国产精品v日韩精品| 性欧美办公室18xxxxhd| 午夜精品久久久久久久久久久久久 | 亚洲综合不卡| 久久亚洲春色中文字幕久久久| 午夜综合激情|