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

隨筆 - 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 閱讀(1439) 評(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>
            亚洲第一天堂av| 国产精品国产a级| 亚洲第一天堂av| 久久久亚洲国产美女国产盗摄| 亚洲专区欧美专区| 亚洲免费婷婷| 亚洲欧美一区二区三区极速播放| 亚洲一区二区精品视频| 亚洲综合电影一区二区三区| 一本到12不卡视频在线dvd| 日韩一级免费| 性欧美超级视频| 老鸭窝亚洲一区二区三区| 欧美大片91| 亚洲乱码国产乱码精品精| 99热在这里有精品免费| 亚洲综合另类| 免费中文字幕日韩欧美| 欧美日韩中文字幕在线| 国产视频精品xxxx| 亚洲成人在线观看视频| 99精品国产热久久91蜜凸| 新片速递亚洲合集欧美合集| 久久综合九色欧美综合狠狠| 亚洲国产精品精华液网站| 亚洲午夜高清视频| 久久综合九色99| 国产精品啊v在线| 在线播放日韩欧美| 亚洲主播在线播放| 欧美激情视频给我| 亚洲欧美久久| 欧美激情综合五月色丁香| 国产精品毛片高清在线完整版| 在线免费不卡视频| 欧美在线一二三区| 亚洲久色影视| 久久阴道视频| 国产亚洲第一区| 一区二区三区视频免费在线观看| 久久久青草青青国产亚洲免观| 亚洲人成高清| 美女91精品| 国产综合精品| 久久国产精品电影| 国产精品99久久久久久宅男| 免费成人美女女| 一区在线视频| 久久久久成人精品| 亚洲欧美日韩国产综合在线| 欧美三区不卡| 亚洲视频一区| aⅴ色国产欧美| 欧美日产一区二区三区在线观看| 亚洲电影免费在线观看| 欧美成人一区在线| 欧美日韩国产精品专区| 亚洲国产二区| 蜜桃av一区二区在线观看| 亚欧成人精品| 国产亚洲福利一区| 久久精品亚洲一区| 欧美在线播放| 伊人久久综合97精品| 久久只精品国产| 久久精品一区二区三区不卡牛牛| 国产日产欧产精品推荐色| 久久精品国产综合精品| 欧美一区二区在线免费观看| 好吊日精品视频| 欧美刺激性大交免费视频| 免费日韩精品中文字幕视频在线| 亚洲国产精品一区制服丝袜| 亚洲二区精品| 国产精品va在线| 久久精品国产欧美激情| 久久久精品日韩欧美| 亚洲级视频在线观看免费1级| 欧美激情一级片一区二区| 欧美激情亚洲另类| 亚洲自拍偷拍色片视频| 欧美一区二区三区在线观看视频| 国产综合久久久久影院| 欧美高清成人| 国产精品久久久久久五月尺| 久久精品国产一区二区三区| 久久精品亚洲一区二区| 亚洲精品少妇| 亚洲欧美国产高清va在线播| 精品不卡一区二区三区| 亚洲国产精品久久| 国产精品国产三级国产a| 久久黄色影院| 欧美电影免费网站| 亚洲欧美怡红院| 久久综合一区二区| 女人色偷偷aa久久天堂| 一本久久综合亚洲鲁鲁| 欧美一级免费视频| 亚洲欧洲在线一区| 夜夜爽www精品| 伊人久久亚洲热| 中文久久乱码一区二区| 亚洲大片一区二区三区| 一本久道久久综合中文字幕| 国模私拍视频一区| 一区二区三区日韩在线观看| 激情六月婷婷久久| 一区二区三区视频在线观看| 悠悠资源网久久精品| 亚洲一级片在线观看| 亚洲人体影院| 久久精品日韩一区二区三区| 午夜精品福利一区二区三区av | 欧美一级久久久| 久久综合网络一区二区| 欧美日韩国语| 亚洲成色777777女色窝| 国产欧美日韩综合一区在线播放| 亚洲国产成人在线视频| 国产一区二区丝袜高跟鞋图片| 亚洲日本欧美| 亚洲精品欧美一区二区三区| 欧美在线免费看| 欧美一区二区在线免费观看| 欧美精品一区二区三区很污很色的| 久久久久综合网| 国产网站欧美日韩免费精品在线观看| 亚洲精品免费一二三区| 亚洲国产日韩一级| 久久久美女艺术照精彩视频福利播放| 亚洲欧美激情诱惑| 国产精品都在这里| 一区二区欧美激情| 亚洲少妇在线| 欧美日韩在线免费视频| 最新中文字幕亚洲| 亚洲精品中文在线| 欧美成人一区二区在线| 欧美激情欧美狂野欧美精品| 亚洲成人资源网| 久久午夜激情| 亚洲国产欧美日韩精品| 日韩午夜视频在线观看| 欧美激情在线| 夜夜嗨av一区二区三区中文字幕 | 一区二区国产日产| 欧美日韩精品欧美日韩精品| 亚洲精品一二区| 亚洲专区一区| 国产午夜亚洲精品理论片色戒 | 欧美午夜激情在线| 亚洲影视在线播放| 久久黄色网页| 亚洲高清视频在线| 欧美激情欧美狂野欧美精品| 亚洲日本理论电影| 亚洲欧美综合另类中字| 国产一区在线观看视频| 久久免费黄色| 亚洲免费观看| 久久国产精品黑丝| 亚洲福利免费| 欧美午夜一区二区三区免费大片| 亚洲一区尤物| 欧美高清在线视频| 亚洲一区二区三区在线看| 国产九九精品视频| 狂野欧美激情性xxxx| 亚洲伦理在线| 久久久欧美精品| 一本色道久久88亚洲综合88| 国产免费成人在线视频| 免费短视频成人日韩| 一区二区三区四区国产| 麻豆成人在线| 亚洲淫片在线视频| 老司机精品视频一区二区三区| 最新亚洲一区| 久久九九有精品国产23| 亚洲日本免费电影| 国产美女搞久久| 欧美人成在线| 久久综合九色| 亚洲欧美日韩精品久久亚洲区| 欧美激情2020午夜免费观看| 亚洲欧美中日韩| 亚洲精品久久久久久久久| 国产三区二区一区久久| 欧美日韩国产首页在线观看| 久久久久欧美精品| 亚洲综合丁香| 夜夜嗨av一区二区三区中文字幕| 欧美sm重口味系列视频在线观看| 欧美一区二区三区视频在线| 日韩亚洲一区在线播放| 在线观看三级视频欧美| 国产一区二区三区在线观看视频| 欧美先锋影音| 欧美日韩一级视频|