descriptor.proto 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 protobuf-global-extension-registry@google.com
  187. // to reserve extension numbers. Simply provide your project name (e.g.
  188. // Object-C plugin) and your porject website (if available) -- there's no need
  189. // to explain how you intend to use them. Usually you only need one extension
  190. // number. You can declare multiple options with only one extension number by
  191. // putting them in a sub-message. See the Custom Options section of the docs
  192. // for examples:
  193. // http://code.google.com/apis/protocolbuffers/docs/proto.html#options
  194. // If this turns out to be popular, a web service will be set up
  195. // to automatically assign option numbers.
  196. message FileOptions {
  197. // Sets the Java package where classes generated from this .proto will be
  198. // placed. By default, the proto package is used, but this is often
  199. // inappropriate because proto packages do not normally start with backwards
  200. // domain names.
  201. optional string java_package = 1;
  202. // If set, all the classes from the .proto file are wrapped in a single
  203. // outer class with the given name. This applies to both Proto1
  204. // (equivalent to the old "--one_java_file" option) and Proto2 (where
  205. // a .proto always translates to a single class, but you may want to
  206. // explicitly choose the class name).
  207. optional string java_outer_classname = 8;
  208. // If set true, then the Java code generator will generate a separate .java
  209. // file for each top-level message, enum, and service defined in the .proto
  210. // file. Thus, these types will *not* be nested inside the outer class
  211. // named by java_outer_classname. However, the outer class will still be
  212. // generated to contain the file's getDescriptor() method as well as any
  213. // top-level extensions defined in the file.
  214. optional bool java_multiple_files = 10 [default=false];
  215. // If set true, then the Java code generator will generate equals() and
  216. // hashCode() methods for all messages defined in the .proto file. This is
  217. // purely a speed optimization, as the AbstractMessage base class includes
  218. // reflection-based implementations of these methods.
  219. optional bool java_generate_equals_and_hash = 20 [default=false];
  220. // Generated classes can be optimized for speed or code size.
  221. enum OptimizeMode {
  222. SPEED = 1; // Generate complete code for parsing, serialization,
  223. // etc.
  224. CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
  225. LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
  226. }
  227. optional OptimizeMode optimize_for = 9 [default=SPEED];
  228. // Should generic services be generated in each language? "Generic" services
  229. // are not specific to any particular RPC system. They are generated by the
  230. // main code generators in each language (without additional plugins).
  231. // Generic services were the only kind of service generation supported by
  232. // early versions of proto2.
  233. //
  234. // Generic services are now considered deprecated in favor of using plugins
  235. // that generate code specific to your particular RPC system. Therefore,
  236. // these default to false. Old code which depends on generic services should
  237. // explicitly set them to true.
  238. optional bool cc_generic_services = 16 [default=false];
  239. optional bool java_generic_services = 17 [default=false];
  240. optional bool py_generic_services = 18 [default=false];
  241. // The parser stores options it doesn't recognize here. See above.
  242. repeated UninterpretedOption uninterpreted_option = 999;
  243. // Clients can define custom options in extensions of this message. See above.
  244. extensions 1000 to max;
  245. }
  246. message MessageOptions {
  247. // Set true to use the old proto1 MessageSet wire format for extensions.
  248. // This is provided for backwards-compatibility with the MessageSet wire
  249. // format. You should not use this for any other reason: It's less
  250. // efficient, has fewer features, and is more complicated.
  251. //
  252. // The message must be defined exactly as follows:
  253. // message Foo {
  254. // option message_set_wire_format = true;
  255. // extensions 4 to max;
  256. // }
  257. // Note that the message cannot have any defined fields; MessageSets only
  258. // have extensions.
  259. //
  260. // All extensions of your type must be singular messages; e.g. they cannot
  261. // be int32s, enums, or repeated messages.
  262. //
  263. // Because this is an option, the above two restrictions are not enforced by
  264. // the protocol compiler.
  265. optional bool message_set_wire_format = 1 [default=false];
  266. // Disables the generation of the standard "descriptor()" accessor, which can
  267. // conflict with a field of the same name. This is meant to make migration
  268. // from proto1 easier; new code should avoid fields named "descriptor".
  269. optional bool no_standard_descriptor_accessor = 2 [default=false];
  270. // The parser stores options it doesn't recognize here. See above.
  271. repeated UninterpretedOption uninterpreted_option = 999;
  272. // Clients can define custom options in extensions of this message. See above.
  273. extensions 1000 to max;
  274. }
  275. message FieldOptions {
  276. // The ctype option instructs the C++ code generator to use a different
  277. // representation of the field than it normally would. See the specific
  278. // options below. This option is not yet implemented in the open source
  279. // release -- sorry, we'll try to include it in a future version!
  280. optional CType ctype = 1 [default = STRING];
  281. enum CType {
  282. // Default mode.
  283. STRING = 0;
  284. CORD = 1;
  285. STRING_PIECE = 2;
  286. }
  287. // The packed option can be enabled for repeated primitive fields to enable
  288. // a more efficient representation on the wire. Rather than repeatedly
  289. // writing the tag and type for each element, the entire array is encoded as
  290. // a single length-delimited blob.
  291. optional bool packed = 2;
  292. // Is this field deprecated?
  293. // Depending on the target platform, this can emit Deprecated annotations
  294. // for accessors, or it will be completely ignored; in the very least, this
  295. // is a formalization for deprecating fields.
  296. optional bool deprecated = 3 [default=false];
  297. // EXPERIMENTAL. DO NOT USE.
  298. // For "map" fields, the name of the field in the enclosed type that
  299. // is the key for this map. For example, suppose we have:
  300. // message Item {
  301. // required string name = 1;
  302. // required string value = 2;
  303. // }
  304. // message Config {
  305. // repeated Item items = 1 [experimental_map_key="name"];
  306. // }
  307. // In this situation, the map key for Item will be set to "name".
  308. // TODO: Fully-implement this, then remove the "experimental_" prefix.
  309. optional string experimental_map_key = 9;
  310. // The parser stores options it doesn't recognize here. See above.
  311. repeated UninterpretedOption uninterpreted_option = 999;
  312. // Clients can define custom options in extensions of this message. See above.
  313. extensions 1000 to max;
  314. }
  315. message EnumOptions {
  316. // The parser stores options it doesn't recognize here. See above.
  317. repeated UninterpretedOption uninterpreted_option = 999;
  318. // Clients can define custom options in extensions of this message. See above.
  319. extensions 1000 to max;
  320. }
  321. message EnumValueOptions {
  322. // The parser stores options it doesn't recognize here. See above.
  323. repeated UninterpretedOption uninterpreted_option = 999;
  324. // Clients can define custom options in extensions of this message. See above.
  325. extensions 1000 to max;
  326. }
  327. message ServiceOptions {
  328. // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
  329. // framework. We apologize for hoarding these numbers to ourselves, but
  330. // we were already using them long before we decided to release Protocol
  331. // Buffers.
  332. // The parser stores options it doesn't recognize here. See above.
  333. repeated UninterpretedOption uninterpreted_option = 999;
  334. // Clients can define custom options in extensions of this message. See above.
  335. extensions 1000 to max;
  336. }
  337. message MethodOptions {
  338. // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
  339. // framework. We apologize for hoarding these numbers to ourselves, but
  340. // we were already using them long before we decided to release Protocol
  341. // Buffers.
  342. // The parser stores options it doesn't recognize here. See above.
  343. repeated UninterpretedOption uninterpreted_option = 999;
  344. // Clients can define custom options in extensions of this message. See above.
  345. extensions 1000 to max;
  346. }
  347. // A message representing a option the parser does not recognize. This only
  348. // appears in options protos created by the compiler::Parser class.
  349. // DescriptorPool resolves these when building Descriptor objects. Therefore,
  350. // options protos in descriptor objects (e.g. returned by Descriptor::options(),
  351. // or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
  352. // in them.
  353. message UninterpretedOption {
  354. // The name of the uninterpreted option. Each string represents a segment in
  355. // a dot-separated name. is_extension is true iff a segment represents an
  356. // extension (denoted with parentheses in options specs in .proto files).
  357. // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
  358. // "foo.(bar.baz).qux".
  359. message NamePart {
  360. required string name_part = 1;
  361. required bool is_extension = 2;
  362. }
  363. repeated NamePart name = 2;
  364. // The value of the uninterpreted option, in whatever type the tokenizer
  365. // identified it as during parsing. Exactly one of these should be set.
  366. optional string identifier_value = 3;
  367. optional uint64 positive_int_value = 4;
  368. optional int64 negative_int_value = 5;
  369. optional double double_value = 6;
  370. optional bytes string_value = 7;
  371. optional string aggregate_value = 8;
  372. }
  373. // ===================================================================
  374. // Optional source code info
  375. // Encapsulates information about the original source file from which a
  376. // FileDescriptorProto was generated.
  377. message SourceCodeInfo {
  378. // A Location identifies a piece of source code in a .proto file which
  379. // corresponds to a particular definition. This information is intended
  380. // to be useful to IDEs, code indexers, documentation generators, and similar
  381. // tools.
  382. //
  383. // For example, say we have a file like:
  384. // message Foo {
  385. // optional string foo = 1;
  386. // }
  387. // Let's look at just the field definition:
  388. // optional string foo = 1;
  389. // ^ ^^ ^^ ^ ^^^
  390. // a bc de f ghi
  391. // We have the following locations:
  392. // span path represents
  393. // [a,i) [ 4, 0, 2, 0 ] The whole field definition.
  394. // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
  395. // [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
  396. // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
  397. // [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
  398. //
  399. // Notes:
  400. // - A location may refer to a repeated field itself (i.e. not to any
  401. // particular index within it). This is used whenever a set of elements are
  402. // logically enclosed in a single code segment. For example, an entire
  403. // extend block (possibly containing multiple extension definitions) will
  404. // have an outer location whose path refers to the "extensions" repeated
  405. // field without an index.
  406. // - Multiple locations may have the same path. This happens when a single
  407. // logical declaration is spread out across multiple places. The most
  408. // obvious example is the "extend" block again -- there may be multiple
  409. // extend blocks in the same scope, each of which will have the same path.
  410. // - A location's span is not always a subset of its parent's span. For
  411. // example, the "extendee" of an extension declaration appears at the
  412. // beginning of the "extend" block and is shared by all extensions within
  413. // the block.
  414. // - Just because a location's span is a subset of some other location's span
  415. // does not mean that it is a descendent. For example, a "group" defines
  416. // both a type and a field in a single declaration. Thus, the locations
  417. // corresponding to the type and field and their components will overlap.
  418. // - Code which tries to interpret locations should probably be designed to
  419. // ignore those that it doesn't understand, as more types of locations could
  420. // be recorded in the future.
  421. repeated Location location = 1;
  422. message Location {
  423. // Identifies which part of the FileDescriptorProto was defined at this
  424. // location.
  425. //
  426. // Each element is a field number or an index. They form a path from
  427. // the root FileDescriptorProto to the place where the definition. For
  428. // example, this path:
  429. // [ 4, 3, 2, 7, 1 ]
  430. // refers to:
  431. // file.message_type(3) // 4, 3
  432. // .field(7) // 2, 7
  433. // .name() // 1
  434. // This is because FileDescriptorProto.message_type has field number 4:
  435. // repeated DescriptorProto message_type = 4;
  436. // and DescriptorProto.field has field number 2:
  437. // repeated FieldDescriptorProto field = 2;
  438. // and FieldDescriptorProto.name has field number 1:
  439. // optional string name = 1;
  440. //
  441. // Thus, the above path gives the location of a field name. If we removed
  442. // the last element:
  443. // [ 4, 3, 2, 7 ]
  444. // this path refers to the whole field declaration (from the beginning
  445. // of the label to the terminating semicolon).
  446. repeated int32 path = 1 [packed=true];
  447. // Always has exactly three or four elements: start line, start column,
  448. // end line (optional, otherwise assumed same as start line), end column.
  449. // These are packed into a single field for efficiency. Note that line
  450. // and column numbers are zero-based -- typically you will want to add
  451. // 1 to each before displaying to a user.
  452. repeated int32 span = 2 [packed=true];
  453. // TODO(kenton): Record comments appearing before and after the
  454. // declaration.
  455. }
  456. }