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

隨筆 - 70, 文章 - 0, 評論 - 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];

謹慎使用required描述符,因為在以后的擴展中,很難去掉該字段。建議全部使用optional和repeated來實現(xiàn)。

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

int32, sint32, int64, sint64
sint32, sint64支持負數(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) 遠程過程調用


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

評論

# re: Protocol Buffers (協(xié)議緩沖) 之 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>
            亚洲人午夜精品免费| 亚洲影院免费| 久久亚洲综合色| 亚洲第一二三四五区| 美国十次了思思久久精品导航| 午夜日韩福利| 影音先锋中文字幕一区二区| 免费成人黄色av| 欧美1级日本1级| 亚洲伊人一本大道中文字幕| 一区二区三区导航| 国产免费亚洲高清| 美国十次成人| 欧美日韩精品一区二区天天拍小说| 99精品免费网| 欧美亚洲三区| 亚洲国产中文字幕在线观看| 亚洲毛片在线看| 韩国三级在线一区| 欧美激情一二区| 欧美午夜精品一区| 久久久久网站| 欧美伦理视频网站| 久久久久久亚洲精品中文字幕 | 亚洲自拍偷拍视频| 香蕉国产精品偷在线观看不卡| 亚洲国产va精品久久久不卡综合| 欧美成人中文字幕| 久久国产日本精品| 欧美日韩精品免费观看| 亚洲欧美影院| 蜜臀av国产精品久久久久| 亚洲一区二区三区涩| 久久九九有精品国产23| 日韩视频免费| 久久国产精彩视频| 亚洲一区二区免费在线| 久久亚洲国产精品一区二区| 中文在线一区| 久久这里只有| 欧美亚洲一级| 欧美久久九九| 欧美激情aⅴ一区二区三区| 国产精品嫩草久久久久| 亚洲福利在线视频| 国产综合视频在线观看| 一区二区三区国产| 亚洲美女毛片| 猫咪成人在线观看| 久久久久网址| 国产欧美69| 亚洲一区二区影院| 亚洲一区二区三区四区五区午夜 | 香蕉乱码成人久久天堂爱免费| 亚洲精品乱码久久久久久日本蜜臀 | 久久久亚洲国产天美传媒修理工| 亚洲一区中文| 欧美日韩中文精品| 亚洲人成在线播放| 亚洲人午夜精品| 久久精品中文字幕一区| 久久国产日韩| 国产精品欧美经典| 亚洲视频一区在线| 亚洲免费在线视频| 欧美人妖另类| 亚洲免费高清视频| 99国产麻豆精品| 欧美成人久久| 亚洲欧洲日夜超级视频| 亚洲理伦电影| 欧美日韩精品系列| 亚洲美女视频网| 亚洲一区二区三区四区五区黄| 欧美日韩一级片在线观看| 洋洋av久久久久久久一区| 亚洲图片欧洲图片日韩av| 欧美日韩成人网| 一区二区三区 在线观看视频| 亚洲天堂成人| 国产精品久久久久久久久久尿| 在线亚洲欧美专区二区| 午夜免费日韩视频| 国产亚洲欧美日韩精品| 久久精品成人欧美大片古装| 麻豆精品在线播放| 亚洲精品小视频在线观看| 欧美区日韩区| 亚洲视频中文字幕| 久久精品国产亚洲一区二区三区| 狠狠久久亚洲欧美专区| 欧美国产免费| 亚洲美女电影在线| 性欧美8khd高清极品| 精东粉嫩av免费一区二区三区| 欧美成人69av| 亚洲天堂免费在线观看视频| 久久精品五月| 亚洲茄子视频| 国产精品一区视频| 欧美+亚洲+精品+三区| 亚洲系列中文字幕| 亚洲国产91| 久久国产精品久久国产精品| 亚洲国产成人精品久久久国产成人一区| 欧美国产精品一区| 欧美一站二站| 99视频精品全国免费| 噜噜噜躁狠狠躁狠狠精品视频| 日韩视频一区二区三区在线播放免费观看| 亚洲综合丁香| 狠狠综合久久av一区二区老牛| 欧美国产日韩一二三区| 欧美一区二区视频观看视频| 亚洲电影免费观看高清完整版在线| 午夜精品一区二区三区四区 | 国内精品伊人久久久久av一坑| 免播放器亚洲| 欧美一区二区三区久久精品茉莉花| 亚洲欧洲日韩女同| 久久综合国产精品台湾中文娱乐网 | 免费亚洲视频| 欧美亚洲在线播放| 99re66热这里只有精品4| 蜜臀av一级做a爰片久久| 亚洲综合精品一区二区| 亚洲人成亚洲人成在线观看| 国产乱码精品一区二区三区不卡| 欧美韩日精品| 美女日韩欧美| 久久久噜噜噜久噜久久| 亚洲在线黄色| 亚洲色图制服丝袜| 亚洲精品视频中文字幕| 欧美黄色一区| 欧美成人蜜桃| 免费成人美女女| 久热国产精品| 久久先锋影音| 久久久久久久性| 久久国产精品网站| 欧美一区二区三区精品电影| 亚洲无亚洲人成网站77777 | 国产精品综合av一区二区国产馆| 欧美日韩国产黄| 欧美女激情福利| 欧美精品在线看| 欧美日韩精品高清| 欧美日韩系列| 国产精品一二三四区| 国产乱人伦精品一区二区| 国产精品日韩欧美一区| 国产乱码精品一区二区三| 国产日韩欧美精品一区| 国产丝袜美腿一区二区三区| 国产亚洲福利一区| 国语自产精品视频在线看| 精品成人一区二区三区| 亚洲黄色一区| 99日韩精品| 亚洲一区二区高清| 久久精品视频播放| 欧美成人自拍视频| 亚洲美女91| 亚洲女性裸体视频| 久久久999国产| 欧美激情精品久久久久久久变态 | 欧美不卡在线| 欧美日韩精品| 国产一区二区三区在线观看精品| 韩国一区电影| 99re6热在线精品视频播放速度| 亚洲无玛一区| 久久亚洲午夜电影| 亚洲日本在线观看| 亚洲影视中文字幕| 免费日韩av片| 国产精品久久久久久久久久免费看 | 国产精品v欧美精品v日韩| 国产精品卡一卡二| 亚洲高清久久久| 亚洲一区二区三区色| 美女啪啪无遮挡免费久久网站| 亚洲国产美女| 亚洲欧美日韩国产成人| 噜噜噜91成人网| 国产精品私拍pans大尺度在线 | 国产精品天天看| 亚洲国产裸拍裸体视频在线观看乱了中文 | 国产亚洲欧美日韩日本| 日韩视频免费| 久久一区二区三区国产精品| 99re8这里有精品热视频免费| 久久成人免费日本黄色| 欧美另类视频在线| 在线观看视频欧美| 欧美一区二区三区免费观看| 亚洲韩国日本中文字幕| 久久精品官网| 国产精品午夜在线观看|