descriptor.proto 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. // This field contains optional information about the original source code.
  61. // You may safely remove this entire field whithout harming runtime
  62. // functionality of the descriptors -- the information is needed only by
  63. // development tools.
  64. optional SourceCodeInfo source_code_info = 9;
  65. }
  66. // Describes a message type.
  67. message DescriptorProto {
  68. optional string name = 1;
  69. repeated FieldDescriptorProto field = 2;
  70. repeated FieldDescriptorProto extension = 6;
  71. repeated DescriptorProto nested_type = 3;
  72. repeated EnumDescriptorProto enum_type = 4;
  73. message ExtensionRange {
  74. optional int32 start = 1;
  75. optional int32 end = 2;
  76. }
  77. repeated ExtensionRange extension_range = 5;
  78. optional MessageOptions options = 7;
  79. }
  80. // Describes a field within a message.
  81. message FieldDescriptorProto {
  82. enum Type {
  83. // 0 is reserved for errors.
  84. // Order is weird for historical reasons.
  85. TYPE_DOUBLE = 1;
  86. TYPE_FLOAT = 2;
  87. TYPE_INT64 = 3; // Not ZigZag encoded. Negative numbers
  88. // take 10 bytes. Use TYPE_SINT64 if negative
  89. // values are likely.
  90. TYPE_UINT64 = 4;
  91. TYPE_INT32 = 5; // Not ZigZag encoded. Negative numbers
  92. // take 10 bytes. Use TYPE_SINT32 if negative
  93. // values are likely.
  94. TYPE_FIXED64 = 6;
  95. TYPE_FIXED32 = 7;
  96. TYPE_BOOL = 8;
  97. TYPE_STRING = 9;
  98. TYPE_GROUP = 10; // Tag-delimited aggregate.
  99. TYPE_MESSAGE = 11; // Length-delimited aggregate.
  100. // New in version 2.
  101. TYPE_BYTES = 12;
  102. TYPE_UINT32 = 13;
  103. TYPE_ENUM = 14;
  104. TYPE_SFIXED32 = 15;
  105. TYPE_SFIXED64 = 16;
  106. TYPE_SINT32 = 17; // Uses ZigZag encoding.
  107. TYPE_SINT64 = 18; // Uses ZigZag encoding.
  108. };
  109. enum Label {
  110. // 0 is reserved for errors
  111. LABEL_OPTIONAL = 1;
  112. LABEL_REQUIRED = 2;
  113. LABEL_REPEATED = 3;
  114. // TODO(sanjay): Should we add LABEL_MAP?
  115. };
  116. optional string name = 1;
  117. optional int32 number = 3;
  118. optional Label label = 4;
  119. // If type_name is set, this need not be set. If both this and type_name
  120. // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
  121. optional Type type = 5;
  122. // For message and enum types, this is the name of the type. If the name
  123. // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
  124. // rules are used to find the type (i.e. first the nested types within this
  125. // message are searched, then within the parent, on up to the root
  126. // namespace).
  127. optional string type_name = 6;
  128. // For extensions, this is the name of the type being extended. It is
  129. // resolved in the same manner as type_name.
  130. optional string extendee = 2;
  131. // For numeric types, contains the original text representation of the value.
  132. // For booleans, "true" or "false".
  133. // For strings, contains the default text contents (not escaped in any way).
  134. // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
  135. // TODO(kenton): Base-64 encode?
  136. optional string default_value = 7;
  137. optional FieldOptions options = 8;
  138. }
  139. // Describes an enum type.
  140. message EnumDescriptorProto {
  141. optional string name = 1;
  142. repeated EnumValueDescriptorProto value = 2;
  143. optional EnumOptions options = 3;
  144. }
  145. // Describes a value within an enum.
  146. message EnumValueDescriptorProto {
  147. optional string name = 1;
  148. optional int32 number = 2;
  149. optional EnumValueOptions options = 3;
  150. }
  151. // Describes a service.
  152. message ServiceDescriptorProto {
  153. optional string name = 1;
  154. repeated MethodDescriptorProto method = 2;
  155. optional ServiceOptions options = 3;
  156. }
  157. // Describes a method of a service.
  158. message MethodDescriptorProto {
  159. optional string name = 1;
  160. // Input and output type names. These are resolved in the same way as
  161. // FieldDescriptorProto.type_name, but must refer to a message type.
  162. optional string input_type = 2;
  163. optional string output_type = 3;
  164. optional MethodOptions options = 4;
  165. }
  166. // ===================================================================
  167. // Options
  168. // Each of the definitions above may have "options" attached. These are
  169. // just annotations which may cause code to be generated slightly differently
  170. // or may contain hints for code that manipulates protocol messages.
  171. //
  172. // Clients may define custom options as extensions of the *Options messages.
  173. // These extensions may not yet be known at parsing time, so the parser cannot
  174. // store the values in them. Instead it stores them in a field in the *Options
  175. // message called uninterpreted_option. This field must have the same name
  176. // across all *Options messages. We then use this field to populate the
  177. // extensions when we build a descriptor, at which point all protos have been
  178. // parsed and so all extensions are known.
  179. //
  180. // Extension numbers for custom options may be chosen as follows:
  181. // * For options which will only be used within a single application or
  182. // organization, or for experimental options, use field numbers 50000
  183. // through 99999. It is up to you to ensure that you do not use the
  184. // same number for multiple options.
  185. // * For options which will be published and used publicly by multiple
  186. // independent entities, e-mail kenton@google.com to reserve extension
  187. // numbers. Simply tell me how many you need and I'll send you back a
  188. // set of numbers to use -- there's no need to explain how you intend to
  189. // use them. If this turns out to be popular, a web service will be set up
  190. // to automatically assign option numbers.
  191. message FileOptions {
  192. // Sets the Java package where classes generated from this .proto will be
  193. // placed. By default, the proto package is used, but this is often
  194. // inappropriate because proto packages do not normally start with backwards
  195. // domain names.
  196. optional string java_package = 1;
  197. // If set, all the classes from the .proto file are wrapped in a single
  198. // outer class with the given name. This applies to both Proto1
  199. // (equivalent to the old "--one_java_file" option) and Proto2 (where
  200. // a .proto always translates to a single class, but you may want to
  201. // explicitly choose the class name).
  202. optional string java_outer_classname = 8;
  203. // If set true, then the Java code generator will generate a separate .java
  204. // file for each top-level message, enum, and service defined in the .proto
  205. // file. Thus, these types will *not* be nested inside the outer class
  206. // named by java_outer_classname. However, the outer class will still be
  207. // generated to contain the file's getDescriptor() method as well as any
  208. // top-level extensions defined in the file.
  209. optional bool java_multiple_files = 10 [default=false];
  210. // If set true, then the Java code generator will generate equals() and
  211. // hashCode() methods for all messages defined in the .proto file. This is
  212. // purely a speed optimization, as the AbstractMessage base class includes
  213. // reflection-based implementations of these methods.
  214. optional bool java_generate_equals_and_hash = 20 [default=false];
  215. // Generated classes can be optimized for speed or code size.
  216. enum OptimizeMode {
  217. SPEED = 1; // Generate complete code for parsing, serialization,
  218. // etc.
  219. CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
  220. LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
  221. }
  222. optional OptimizeMode optimize_for = 9 [default=SPEED];
  223. // Should generic services be generated in each language? "Generic" services
  224. // are not specific to any particular RPC system. They are generated by the
  225. // main code generators in each language (without additional plugins).
  226. // Generic services were the only kind of service generation supported by
  227. // early versions of proto2.
  228. //
  229. // Generic services are now considered deprecated in favor of using plugins
  230. // that generate code specific to your particular RPC system. Therefore,
  231. // these default to false. Old code which depends on generic services should
  232. // explicitly set them to true.
  233. optional bool cc_generic_services = 16 [default=false];
  234. optional bool java_generic_services = 17 [default=false];
  235. optional bool py_generic_services = 18 [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 MessageOptions {
  242. // Set true to use the old proto1 MessageSet wire format for extensions.
  243. // This is provided for backwards-compatibility with the MessageSet wire
  244. // format. You should not use this for any other reason: It's less
  245. // efficient, has fewer features, and is more complicated.
  246. //
  247. // The message must be defined exactly as follows:
  248. // message Foo {
  249. // option message_set_wire_format = true;
  250. // extensions 4 to max;
  251. // }
  252. // Note that the message cannot have any defined fields; MessageSets only
  253. // have extensions.
  254. //
  255. // All extensions of your type must be singular messages; e.g. they cannot
  256. // be int32s, enums, or repeated messages.
  257. //
  258. // Because this is an option, the above two restrictions are not enforced by
  259. // the protocol compiler.
  260. optional bool message_set_wire_format = 1 [default=false];
  261. // Disables the generation of the standard "descriptor()" accessor, which can
  262. // conflict with a field of the same name. This is meant to make migration
  263. // from proto1 easier; new code should avoid fields named "descriptor".
  264. optional bool no_standard_descriptor_accessor = 2 [default=false];
  265. // The parser stores options it doesn't recognize here. See above.
  266. repeated UninterpretedOption uninterpreted_option = 999;
  267. // Clients can define custom options in extensions of this message. See above.
  268. extensions 1000 to max;
  269. }
  270. message FieldOptions {
  271. // The ctype option instructs the C++ code generator to use a different
  272. // representation of the field than it normally would. See the specific
  273. // options below. This option is not yet implemented in the open source
  274. // release -- sorry, we'll try to include it in a future version!
  275. optional CType ctype = 1 [default = STRING];
  276. enum CType {
  277. // Default mode.
  278. STRING = 0;
  279. CORD = 1;
  280. STRING_PIECE = 2;
  281. }
  282. // The packed option can be enabled for repeated primitive fields to enable
  283. // a more efficient representation on the wire. Rather than repeatedly
  284. // writing the tag and type for each element, the entire array is encoded as
  285. // a single length-delimited blob.
  286. optional bool packed = 2;
  287. // Is this field deprecated?
  288. // Depending on the target platform, this can emit Deprecated annotations
  289. // for accessors, or it will be completely ignored; in the very least, this
  290. // is a formalization for deprecating fields.
  291. optional bool deprecated = 3 [default=false];
  292. // EXPERIMENTAL. DO NOT USE.
  293. // For "map" fields, the name of the field in the enclosed type that
  294. // is the key for this map. For example, suppose we have:
  295. // message Item {
  296. // required string name = 1;
  297. // required string value = 2;
  298. // }
  299. // message Config {
  300. // repeated Item items = 1 [experimental_map_key="name"];
  301. // }
  302. // In this situation, the map key for Item will be set to "name".
  303. // TODO: Fully-implement this, then remove the "experimental_" prefix.
  304. optional string experimental_map_key = 9;
  305. // The parser stores options it doesn't recognize here. See above.
  306. repeated UninterpretedOption uninterpreted_option = 999;
  307. // Clients can define custom options in extensions of this message. See above.
  308. extensions 1000 to max;
  309. }
  310. message EnumOptions {
  311. // The parser stores options it doesn't recognize here. See above.
  312. repeated UninterpretedOption uninterpreted_option = 999;
  313. // Clients can define custom options in extensions of this message. See above.
  314. extensions 1000 to max;
  315. }
  316. message EnumValueOptions {
  317. // The parser stores options it doesn't recognize here. See above.
  318. repeated UninterpretedOption uninterpreted_option = 999;
  319. // Clients can define custom options in extensions of this message. See above.
  320. extensions 1000 to max;
  321. }
  322. message ServiceOptions {
  323. // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
  324. // framework. We apologize for hoarding these numbers to ourselves, but
  325. // we were already using them long before we decided to release Protocol
  326. // Buffers.
  327. // The parser stores options it doesn't recognize here. See above.
  328. repeated UninterpretedOption uninterpreted_option = 999;
  329. // Clients can define custom options in extensions of this message. See above.
  330. extensions 1000 to max;
  331. }
  332. message MethodOptions {
  333. // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
  334. // framework. We apologize for hoarding these numbers to ourselves, but
  335. // we were already using them long before we decided to release Protocol
  336. // Buffers.
  337. // The parser stores options it doesn't recognize here. See above.
  338. repeated UninterpretedOption uninterpreted_option = 999;
  339. // Clients can define custom options in extensions of this message. See above.
  340. extensions 1000 to max;
  341. }
  342. // A message representing a option the parser does not recognize. This only
  343. // appears in options protos created by the compiler::Parser class.
  344. // DescriptorPool resolves these when building Descriptor objects. Therefore,
  345. // options protos in descriptor objects (e.g. returned by Descriptor::options(),
  346. // or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
  347. // in them.
  348. message UninterpretedOption {
  349. // The name of the uninterpreted option. Each string represents a segment in
  350. // a dot-separated name. is_extension is true iff a segment represents an
  351. // extension (denoted with parentheses in options specs in .proto files).
  352. // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
  353. // "foo.(bar.baz).qux".
  354. message NamePart {
  355. required string name_part = 1;
  356. required bool is_extension = 2;
  357. }
  358. repeated NamePart name = 2;
  359. // The value of the uninterpreted option, in whatever type the tokenizer
  360. // identified it as during parsing. Exactly one of these should be set.
  361. optional string identifier_value = 3;
  362. optional uint64 positive_int_value = 4;
  363. optional int64 negative_int_value = 5;
  364. optional double double_value = 6;
  365. optional bytes string_value = 7;
  366. optional string aggregate_value = 8;
  367. }
  368. // ===================================================================
  369. // Optional source code info
  370. // Encapsulates information about the original source file from which a
  371. // FileDescriptorProto was generated.
  372. message SourceCodeInfo {
  373. // A Location identifies a piece of source code in a .proto file which
  374. // corresponds to a particular definition. This information is intended
  375. // to be useful to IDEs, code indexers, documentation generators, and similar
  376. // tools.
  377. //
  378. // For example, say we have a file like:
  379. // message Foo {
  380. // optional string foo = 1;
  381. // }
  382. // Let's look at just the field definition:
  383. // optional string foo = 1;
  384. // ^ ^^ ^^ ^ ^^^
  385. // a bc de f ghi
  386. // We have the following locations:
  387. // span path represents
  388. // [a,i) [ 4, 0, 2, 0 ] The whole field definition.
  389. // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
  390. // [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
  391. // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
  392. // [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
  393. //
  394. // Notes:
  395. // - A location may refer to a repeated field itself (i.e. not to any
  396. // particular index within it). This is used whenever a set of elements are
  397. // logically enclosed in a single code segment. For example, an entire
  398. // extend block (possibly containing multiple extension definitions) will
  399. // have an outer location whose path refers to the "extensions" repeated
  400. // field without an index.
  401. // - Multiple locations may have the same path. This happens when a single
  402. // logical declaration is spread out across multiple places. The most
  403. // obvious example is the "extend" block again -- there may be multiple
  404. // extend blocks in the same scope, each of which will have the same path.
  405. // - A location's span is not always a subset of its parent's span. For
  406. // example, the "extendee" of an extension declaration appears at the
  407. // beginning of the "extend" block and is shared by all extensions within
  408. // the block.
  409. // - Just because a location's span is a subset of some other location's span
  410. // does not mean that it is a descendent. For example, a "group" defines
  411. // both a type and a field in a single declaration. Thus, the locations
  412. // corresponding to the type and field and their components will overlap.
  413. // - Code which tries to interpret locations should probably be designed to
  414. // ignore those that it doesn't understand, as more types of locations could
  415. // be recorded in the future.
  416. repeated Location location = 1;
  417. message Location {
  418. // Identifies which part of the FileDescriptorProto was defined at this
  419. // location.
  420. //
  421. // Each element is a field number or an index. They form a path from
  422. // the root FileDescriptorProto to the place where the definition. For
  423. // example, this path:
  424. // [ 4, 3, 2, 7, 1 ]
  425. // refers to:
  426. // file.message_type(3) // 4, 3
  427. // .field(7) // 2, 7
  428. // .name() // 1
  429. // This is because FileDescriptorProto.message_type has field number 4:
  430. // repeated DescriptorProto message_type = 4;
  431. // and DescriptorProto.field has field number 2:
  432. // repeated FieldDescriptorProto field = 2;
  433. // and FieldDescriptorProto.name has field number 1:
  434. // optional string name = 1;
  435. //
  436. // Thus, the above path gives the location of a field name. If we removed
  437. // the last element:
  438. // [ 4, 3, 2, 7 ]
  439. // this path refers to the whole field declaration (from the beginning
  440. // of the label to the terminating semicolon).
  441. repeated int32 path = 1 [packed=true];
  442. // Always has exactly three or four elements: start line, start column,
  443. // end line (optional, otherwise assumed same as start line), end column.
  444. // These are packed into a single field for efficiency. Note that line
  445. // and column numbers are zero-based -- typically you will want to add
  446. // 1 to each before displaying to a user.
  447. repeated int32 span = 2 [packed=true];
  448. // TODO(kenton): Record comments appearing before and after the
  449. // declaration.
  450. }
  451. }