descriptor.proto 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // http://code.google.com/p/protobuf/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. //
  34. // The messages in this file describe the definitions found in .proto files.
  35. // A valid .proto file can be translated directly to a FileDescriptorProto
  36. // without any other information (e.g. without reading its imports).
  37. package google.protobuf;
  38. option java_package = "com.google.protobuf";
  39. option java_outer_classname = "DescriptorProtos";
  40. // descriptor.proto must be optimized for speed because reflection-based
  41. // algorithms don't work during bootstrapping.
  42. option optimize_for = SPEED;
  43. // The protocol compiler can output a FileDescriptorSet containing the .proto
  44. // files it parses.
  45. message FileDescriptorSet {
  46. repeated FileDescriptorProto file = 1;
  47. }
  48. // Describes a complete .proto file.
  49. message FileDescriptorProto {
  50. optional string name = 1; // file name, relative to root of source tree
  51. optional string package = 2; // e.g. "foo", "foo.bar", etc.
  52. // Names of files imported by this file.
  53. repeated string dependency = 3;
  54. // All top-level definitions in this file.
  55. repeated DescriptorProto message_type = 4;
  56. repeated EnumDescriptorProto enum_type = 5;
  57. repeated ServiceDescriptorProto service = 6;
  58. repeated FieldDescriptorProto extension = 7;
  59. optional FileOptions options = 8;
  60. }
  61. // Describes a message type.
  62. message DescriptorProto {
  63. optional string name = 1;
  64. repeated FieldDescriptorProto field = 2;
  65. repeated FieldDescriptorProto extension = 6;
  66. repeated DescriptorProto nested_type = 3;
  67. repeated EnumDescriptorProto enum_type = 4;
  68. message ExtensionRange {
  69. optional int32 start = 1;
  70. optional int32 end = 2;
  71. }
  72. repeated ExtensionRange extension_range = 5;
  73. optional MessageOptions options = 7;
  74. }
  75. // Describes a field within a message.
  76. message FieldDescriptorProto {
  77. enum Type {
  78. // 0 is reserved for errors.
  79. // Order is weird for historical reasons.
  80. TYPE_DOUBLE = 1;
  81. TYPE_FLOAT = 2;
  82. TYPE_INT64 = 3; // Not ZigZag encoded. Negative numbers
  83. // take 10 bytes. Use TYPE_SINT64 if negative
  84. // values are likely.
  85. TYPE_UINT64 = 4;
  86. TYPE_INT32 = 5; // Not ZigZag encoded. Negative numbers
  87. // take 10 bytes. Use TYPE_SINT32 if negative
  88. // values are likely.
  89. TYPE_FIXED64 = 6;
  90. TYPE_FIXED32 = 7;
  91. TYPE_BOOL = 8;
  92. TYPE_STRING = 9;
  93. TYPE_GROUP = 10; // Tag-delimited aggregate.
  94. TYPE_MESSAGE = 11; // Length-delimited aggregate.
  95. // New in version 2.
  96. TYPE_BYTES = 12;
  97. TYPE_UINT32 = 13;
  98. TYPE_ENUM = 14;
  99. TYPE_SFIXED32 = 15;
  100. TYPE_SFIXED64 = 16;
  101. TYPE_SINT32 = 17; // Uses ZigZag encoding.
  102. TYPE_SINT64 = 18; // Uses ZigZag encoding.
  103. };
  104. enum Label {
  105. // 0 is reserved for errors
  106. LABEL_OPTIONAL = 1;
  107. LABEL_REQUIRED = 2;
  108. LABEL_REPEATED = 3;
  109. // TODO(sanjay): Should we add LABEL_MAP?
  110. };
  111. optional string name = 1;
  112. optional int32 number = 3;
  113. optional Label label = 4;
  114. // If type_name is set, this need not be set. If both this and type_name
  115. // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
  116. optional Type type = 5;
  117. // For message and enum types, this is the name of the type. If the name
  118. // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
  119. // rules are used to find the type (i.e. first the nested types within this
  120. // message are searched, then within the parent, on up to the root
  121. // namespace).
  122. optional string type_name = 6;
  123. // For extensions, this is the name of the type being extended. It is
  124. // resolved in the same manner as type_name.
  125. optional string extendee = 2;
  126. // For numeric types, contains the original text representation of the value.
  127. // For booleans, "true" or "false".
  128. // For strings, contains the default text contents (not escaped in any way).
  129. // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
  130. // TODO(kenton): Base-64 encode?
  131. optional string default_value = 7;
  132. optional FieldOptions options = 8;
  133. }
  134. // Describes an enum type.
  135. message EnumDescriptorProto {
  136. optional string name = 1;
  137. repeated EnumValueDescriptorProto value = 2;
  138. optional EnumOptions options = 3;
  139. }
  140. // Describes a value within an enum.
  141. message EnumValueDescriptorProto {
  142. optional string name = 1;
  143. optional int32 number = 2;
  144. optional EnumValueOptions options = 3;
  145. }
  146. // Describes a service.
  147. message ServiceDescriptorProto {
  148. optional string name = 1;
  149. repeated MethodDescriptorProto method = 2;
  150. optional ServiceOptions options = 3;
  151. }
  152. // Describes a method of a service.
  153. message MethodDescriptorProto {
  154. optional string name = 1;
  155. // Input and output type names. These are resolved in the same way as
  156. // FieldDescriptorProto.type_name, but must refer to a message type.
  157. optional string input_type = 2;
  158. optional string output_type = 3;
  159. optional MethodOptions options = 4;
  160. }
  161. // ===================================================================
  162. // Options
  163. // Each of the definitions above may have "options" attached. These are
  164. // just annotations which may cause code to be generated slightly differently
  165. // or may contain hints for code that manipulates protocol messages.
  166. //
  167. // Clients may define custom options as extensions of the *Options messages.
  168. // These extensions may not yet be known at parsing time, so the parser cannot
  169. // store the values in them. Instead it stores them in a field in the *Options
  170. // message called uninterpreted_option. This field must have the same name
  171. // across all *Options messages. We then use this field to populate the
  172. // extensions when we build a descriptor, at which point all protos have been
  173. // parsed and so all extensions are known.
  174. //
  175. // Extension numbers for custom options may be chosen as follows:
  176. // * For options which will only be used within a single application or
  177. // organization, or for experimental options, use field numbers 50000
  178. // through 99999. It is up to you to ensure that you do not use the
  179. // same number for multiple options.
  180. // * For options which will be published and used publicly by multiple
  181. // independent entities, e-mail kenton@google.com to reserve extension
  182. // numbers. Simply tell me how many you need and I'll send you back a
  183. // set of numbers to use -- there's no need to explain how you intend to
  184. // use them. If this turns out to be popular, a web service will be set up
  185. // to automatically assign option numbers.
  186. message FileOptions {
  187. // Sets the Java package where classes generated from this .proto will be
  188. // placed. By default, the proto package is used, but this is often
  189. // inappropriate because proto packages do not normally start with backwards
  190. // domain names.
  191. optional string java_package = 1;
  192. // If set, all the classes from the .proto file are wrapped in a single
  193. // outer class with the given name. This applies to both Proto1
  194. // (equivalent to the old "--one_java_file" option) and Proto2 (where
  195. // a .proto always translates to a single class, but you may want to
  196. // explicitly choose the class name).
  197. optional string java_outer_classname = 8;
  198. // If set true, then the Java code generator will generate a separate .java
  199. // file for each top-level message, enum, and service defined in the .proto
  200. // file. Thus, these types will *not* be nested inside the outer class
  201. // named by java_outer_classname. However, the outer class will still be
  202. // generated to contain the file's getDescriptor() method as well as any
  203. // top-level extensions defined in the file.
  204. optional bool java_multiple_files = 10 [default=false];
  205. // Generated classes can be optimized for speed or code size.
  206. enum OptimizeMode {
  207. SPEED = 1; // Generate complete code for parsing, serialization, etc.
  208. CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
  209. }
  210. optional OptimizeMode optimize_for = 9 [default=SPEED];
  211. // The parser stores options it doesn't recognize here. See above.
  212. repeated UninterpretedOption uninterpreted_option = 999;
  213. // Clients can define custom options in extensions of this message. See above.
  214. extensions 1000 to max;
  215. }
  216. message MessageOptions {
  217. // Set true to use the old proto1 MessageSet wire format for extensions.
  218. // This is provided for backwards-compatibility with the MessageSet wire
  219. // format. You should not use this for any other reason: It's less
  220. // efficient, has fewer features, and is more complicated.
  221. //
  222. // The message must be defined exactly as follows:
  223. // message Foo {
  224. // option message_set_wire_format = true;
  225. // extensions 4 to max;
  226. // }
  227. // Note that the message cannot have any defined fields; MessageSets only
  228. // have extensions.
  229. //
  230. // All extensions of your type must be singular messages; e.g. they cannot
  231. // be int32s, enums, or repeated messages.
  232. //
  233. // Because this is an option, the above two restrictions are not enforced by
  234. // the protocol compiler.
  235. optional bool message_set_wire_format = 1 [default=false];
  236. // The parser stores options it doesn't recognize here. See above.
  237. repeated UninterpretedOption uninterpreted_option = 999;
  238. // Clients can define custom options in extensions of this message. See above.
  239. extensions 1000 to max;
  240. }
  241. message FieldOptions {
  242. // The ctype option instructs the C++ code generator to use a different
  243. // representation of the field than it normally would. See the specific
  244. // options below. This option is not yet implemented in the open source
  245. // release -- sorry, we'll try to include it in a future version!
  246. optional CType ctype = 1;
  247. enum CType {
  248. CORD = 1;
  249. STRING_PIECE = 2;
  250. }
  251. // The packed option can be enabled for repeated primitive fields to enable
  252. // a more efficient representation on the wire. Rather than repeatedly
  253. // writing the tag and type for each element, the entire array is encoded as
  254. // a single length-delimited blob.
  255. optional bool packed = 2;
  256. // Is this field deprecated?
  257. // Depending on the target platform, this can emit Deprecated annotations
  258. // for accessors, or it will be completely ignored; in the very least, this
  259. // is a formalization for deprecating fields.
  260. optional bool deprecated = 3 [default=false];
  261. // EXPERIMENTAL. DO NOT USE.
  262. // For "map" fields, the name of the field in the enclosed type that
  263. // is the key for this map. For example, suppose we have:
  264. // message Item {
  265. // required string name = 1;
  266. // required string value = 2;
  267. // }
  268. // message Config {
  269. // repeated Item items = 1 [experimental_map_key="name"];
  270. // }
  271. // In this situation, the map key for Item will be set to "name".
  272. // TODO: Fully-implement this, then remove the "experimental_" prefix.
  273. optional string experimental_map_key = 9;
  274. // The parser stores options it doesn't recognize here. See above.
  275. repeated UninterpretedOption uninterpreted_option = 999;
  276. // Clients can define custom options in extensions of this message. See above.
  277. extensions 1000 to max;
  278. }
  279. message EnumOptions {
  280. // The parser stores options it doesn't recognize here. See above.
  281. repeated UninterpretedOption uninterpreted_option = 999;
  282. // Clients can define custom options in extensions of this message. See above.
  283. extensions 1000 to max;
  284. }
  285. message EnumValueOptions {
  286. // The parser stores options it doesn't recognize here. See above.
  287. repeated UninterpretedOption uninterpreted_option = 999;
  288. // Clients can define custom options in extensions of this message. See above.
  289. extensions 1000 to max;
  290. }
  291. message ServiceOptions {
  292. // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
  293. // framework. We apologize for hoarding these numbers to ourselves, but
  294. // we were already using them long before we decided to release Protocol
  295. // Buffers.
  296. // The parser stores options it doesn't recognize here. See above.
  297. repeated UninterpretedOption uninterpreted_option = 999;
  298. // Clients can define custom options in extensions of this message. See above.
  299. extensions 1000 to max;
  300. }
  301. message MethodOptions {
  302. // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
  303. // framework. We apologize for hoarding these numbers to ourselves, but
  304. // we were already using them long before we decided to release Protocol
  305. // Buffers.
  306. // The parser stores options it doesn't recognize here. See above.
  307. repeated UninterpretedOption uninterpreted_option = 999;
  308. // Clients can define custom options in extensions of this message. See above.
  309. extensions 1000 to max;
  310. }
  311. // A message representing a option the parser does not recognize. This only
  312. // appears in options protos created by the compiler::Parser class.
  313. // DescriptorPool resolves these when building Descriptor objects. Therefore,
  314. // options protos in descriptor objects (e.g. returned by Descriptor::options(),
  315. // or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
  316. // in them.
  317. message UninterpretedOption {
  318. // The name of the uninterpreted option. Each string represents a segment in
  319. // a dot-separated name. is_extension is true iff a segment represents an
  320. // extension (denoted with parentheses in options specs in .proto files).
  321. // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
  322. // "foo.(bar.baz).qux".
  323. message NamePart {
  324. required string name_part = 1;
  325. required bool is_extension = 2;
  326. }
  327. repeated NamePart name = 2;
  328. // The value of the uninterpreted option, in whatever type the tokenizer
  329. // identified it as during parsing. Exactly one of these should be set.
  330. optional string identifier_value = 3;
  331. optional uint64 positive_int_value = 4;
  332. optional int64 negative_int_value = 5;
  333. optional double double_value = 6;
  334. optional bytes string_value = 7;
  335. }