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

隨筆 - 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>
            国产精品午夜在线| 欧美一区二区三区免费看| 欧美激情一区三区| 欧美大片在线观看| 欧美日韩一级黄| 国产精品草草| 国产欧美日韩在线播放| 极品中文字幕一区| 亚洲国产精品久久久| 日韩写真在线| 欧美a级在线| 亚洲国产欧美一区二区三区丁香婷| 国产夜色精品一区二区av| 国内精品久久久久影院薰衣草| 国产最新精品精品你懂的| 在线观看一区视频| 亚洲视频在线视频| 久久久91精品国产一区二区精品| 欧美/亚洲一区| 夜夜嗨一区二区| 欧美一区二粉嫩精品国产一线天| 久久久久久久久久久久久女国产乱| 欧美jizz19性欧美| 国产精品推荐精品| 亚洲国产欧美久久| 久久gogo国模裸体人体| 亚洲肉体裸体xxxx137| 一区二区三区日韩欧美| 久久久人成影片一区二区三区| 欧美日韩国产在线播放| 黄色成人免费观看| 亚洲欧美中文字幕| 亚洲人成网站影音先锋播放| 欧美一区二区三区四区视频 | 亚洲精品一区二区在线| 欧美一区二区精品久久911| 亚洲成色999久久网站| 先锋a资源在线看亚洲| 欧美日本免费一区二区三区| 激情一区二区三区| 久久久www成人免费精品| 9l视频自拍蝌蚪9l视频成人| 久久三级视频| 国产亚洲欧美在线| 亚洲欧美综合网| 一区二区高清| 欧美日本三区| 亚洲美女中出| 亚洲第一视频| 可以看av的网站久久看| 国产亚洲美州欧州综合国| 亚洲视频大全| 日韩天天综合| 欧美视频在线观看一区| 在线亚洲精品| 一区二区三区产品免费精品久久75| 免费91麻豆精品国产自产在线观看| 国产网站欧美日韩免费精品在线观看 | 美女任你摸久久| 亚洲精品久久久久久久久| 午夜精品免费在线| 亚洲精品极品| 欧美日本一区二区三区| 亚洲精品一区二区三区不| 亚洲第一精品电影| 欧美精品在线一区二区| 亚洲看片免费| 亚洲精品一区二区网址| 欧美日韩精品伦理作品在线免费观看| 亚洲精品一二区| 99re国产精品| 国产精品视频一区二区高潮| 亚洲欧美日韩第一区| 一区二区精品国产| 国产精品永久免费视频| 久久久天天操| 欧美成人免费全部| 亚洲一区二区三区中文字幕| 亚洲深夜av| 激情六月综合| 亚洲精品久久久蜜桃| 国产精品视频精品| 欧美 日韩 国产 一区| 欧美人牲a欧美精品| 香蕉国产精品偷在线观看不卡| 欧美一区二区视频97| 亚洲国产婷婷综合在线精品 | 久久久久国产精品麻豆ai换脸| 影音先锋日韩精品| 一本到12不卡视频在线dvd| 国产偷久久久精品专区| 欧美激情一区二区三区蜜桃视频 | 久久久久久一区| 日韩小视频在线观看专区| 亚洲欧美自拍偷拍| 日韩午夜中文字幕| 香蕉久久一区二区不卡无毒影院| 黄色欧美日韩| 一区二区毛片| 亚洲激情在线观看| 亚洲欧美电影在线观看| 91久久黄色| 性高湖久久久久久久久| 亚洲精品免费在线播放| 欧美一区二区在线看| 一区二区三区福利| 久久综合电影一区| 欧美影院一区| 欧美亚一区二区| 亚洲国产高清在线| 激情丁香综合| 亚洲欧美日韩在线综合| 999亚洲国产精| 久久综合色婷婷| 久久国产天堂福利天堂| 欧美日韩国产免费| 欧美黄色一级视频| 尤物在线精品| 日韩亚洲在线观看| 老司机一区二区三区| 国产精品九色蝌蚪自拍| 91久久夜色精品国产九色| 韩国一区二区在线观看| 亚洲一区二区动漫| 亚洲一区二区三区视频| 欧美激情精品久久久六区热门| 老司机免费视频一区二区| 国产欧美一区二区三区国产幕精品 | 激情久久久久久久| 欧美在线高清视频| 久久精品日韩一区二区三区| 国产精品高清在线| 亚洲性线免费观看视频成熟| 亚洲视频一区| 欧美体内谢she精2性欧美| 亚洲精品小视频在线观看| 亚洲精品小视频| 欧美极品在线观看| 亚洲国产天堂久久综合网| 91久久精品国产91性色| 男男成人高潮片免费网站| 欧美不卡一区| 亚洲日本在线视频观看| 欧美激情国产日韩| 亚洲区第一页| 亚洲一区精彩视频| 国产精品系列在线| 欧美一区二区三区四区高清| 久久网站免费| 亚洲国产日韩欧美在线图片| 久久综合网色—综合色88| 亚洲第一页在线| 在线视频精品| 国产精品亚洲一区二区三区在线| 亚洲午夜久久久| 久久久久久久一区二区| 亚洲国产成人精品视频| 欧美全黄视频| 欧美一区91| 亚洲国产精品美女| 亚洲一区视频在线| 国产亚洲精品bt天堂精选| 免费亚洲一区| 亚洲免费视频观看| 欧美成人精品在线| 亚洲一区三区视频在线观看| 国产一区二区三区免费不卡| 老司机精品导航| 中文日韩电影网站| 免费中文日韩| 亚洲免费视频观看| 亚洲国产成人一区| 国产精品成人午夜| 美女视频一区免费观看| 日韩一级黄色av| 久久这里只有| 亚洲欧美在线一区| 亚洲人成艺术| 国产亚洲欧美另类中文| 欧美日韩国产一区| 久久在线播放| 午夜激情综合网| 9i看片成人免费高清| 男人的天堂亚洲在线| 欧美亚洲专区| 亚洲人体1000| 欧美四级在线观看| 亚洲一区二区三区精品在线观看| 亚洲综合视频网| 红桃av永久久久| 欧美色中文字幕| 麻豆精品视频| 亚洲女人天堂av| 最新日韩欧美| 蜜桃av噜噜一区二区三区| 亚洲专区免费| av成人免费在线观看| 精品动漫3d一区二区三区免费版| 欧美视频亚洲视频| 猛男gaygay欧美视频|