descriptor.proto 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  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. // Indexes of the public imported files in the dependency list above.
  55. repeated int32 public_dependency = 10;
  56. // Indexes of the weak imported files in the dependency list.
  57. // For Google-internal migration only. Do not use.
  58. repeated int32 weak_dependency = 11;
  59. // All top-level definitions in this file.
  60. repeated DescriptorProto message_type = 4;
  61. repeated EnumDescriptorProto enum_type = 5;
  62. repeated ServiceDescriptorProto service = 6;
  63. repeated FieldDescriptorProto extension = 7;
  64. optional FileOptions options = 8;
  65. // This field contains optional information about the original source code.
  66. // You may safely remove this entire field whithout harming runtime
  67. // functionality of the descriptors -- the information is needed only by
  68. // development tools.
  69. optional SourceCodeInfo source_code_info = 9;
  70. }
  71. // Describes a message type.
  72. message DescriptorProto {
  73. optional string name = 1;
  74. repeated FieldDescriptorProto field = 2;
  75. repeated FieldDescriptorProto extension = 6;
  76. repeated DescriptorProto nested_type = 3;
  77. repeated EnumDescriptorProto enum_type = 4;
  78. message ExtensionRange {
  79. optional int32 start = 1;
  80. optional int32 end = 2;
  81. }
  82. repeated ExtensionRange extension_range = 5;
  83. repeated OneofDescriptorProto oneof_decl = 8;
  84. optional MessageOptions options = 7;
  85. }
  86. // Describes a field within a message.
  87. message FieldDescriptorProto {
  88. enum Type {
  89. // 0 is reserved for errors.
  90. // Order is weird for historical reasons.
  91. TYPE_DOUBLE = 1;
  92. TYPE_FLOAT = 2;
  93. // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
  94. // negative values are likely.
  95. TYPE_INT64 = 3;
  96. TYPE_UINT64 = 4;
  97. // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
  98. // negative values are likely.
  99. TYPE_INT32 = 5;
  100. TYPE_FIXED64 = 6;
  101. TYPE_FIXED32 = 7;
  102. TYPE_BOOL = 8;
  103. TYPE_STRING = 9;
  104. TYPE_GROUP = 10; // Tag-delimited aggregate.
  105. TYPE_MESSAGE = 11; // Length-delimited aggregate.
  106. // New in version 2.
  107. TYPE_BYTES = 12;
  108. TYPE_UINT32 = 13;
  109. TYPE_ENUM = 14;
  110. TYPE_SFIXED32 = 15;
  111. TYPE_SFIXED64 = 16;
  112. TYPE_SINT32 = 17; // Uses ZigZag encoding.
  113. TYPE_SINT64 = 18; // Uses ZigZag encoding.
  114. };
  115. enum Label {
  116. // 0 is reserved for errors
  117. LABEL_OPTIONAL = 1;
  118. LABEL_REQUIRED = 2;
  119. LABEL_REPEATED = 3;
  120. // TODO(sanjay): Should we add LABEL_MAP?
  121. };
  122. optional string name = 1;
  123. optional int32 number = 3;
  124. optional Label label = 4;
  125. // If type_name is set, this need not be set. If both this and type_name
  126. // are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
  127. optional Type type = 5;
  128. // For message and enum types, this is the name of the type. If the name
  129. // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
  130. // rules are used to find the type (i.e. first the nested types within this
  131. // message are searched, then within the parent, on up to the root
  132. // namespace).
  133. optional string type_name = 6;
  134. // For extensions, this is the name of the type being extended. It is
  135. // resolved in the same manner as type_name.
  136. optional string extendee = 2;
  137. // For numeric types, contains the original text representation of the value.
  138. // For booleans, "true" or "false".
  139. // For strings, contains the default text contents (not escaped in any way).
  140. // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
  141. // TODO(kenton): Base-64 encode?
  142. optional string default_value = 7;
  143. // If set, gives the index of a oneof in the containing type's oneof_decl
  144. // list. This field is a member of that oneof. Extensions of a oneof should
  145. // not set this since the oneof to which they belong will be inferred based
  146. // on the extension range containing the extension's field number.
  147. optional int32 oneof_index = 9;
  148. optional FieldOptions options = 8;
  149. }
  150. // Describes a oneof.
  151. message OneofDescriptorProto {
  152. optional string name = 1;
  153. }
  154. // Describes an enum type.
  155. message EnumDescriptorProto {
  156. optional string name = 1;
  157. repeated EnumValueDescriptorProto value = 2;
  158. optional EnumOptions options = 3;
  159. }
  160. // Describes a value within an enum.
  161. message EnumValueDescriptorProto {
  162. optional string name = 1;
  163. optional int32 number = 2;
  164. optional EnumValueOptions options = 3;
  165. }
  166. // Describes a service.
  167. message ServiceDescriptorProto {
  168. optional string name = 1;
  169. repeated MethodDescriptorProto method = 2;
  170. optional ServiceOptions options = 3;
  171. }
  172. // Describes a method of a service.
  173. message MethodDescriptorProto {
  174. optional string name = 1;
  175. // Input and output type names. These are resolved in the same way as
  176. // FieldDescriptorProto.type_name, but must refer to a message type.
  177. optional string input_type = 2;
  178. optional string output_type = 3;
  179. optional MethodOptions options = 4;
  180. }
  181. // ===================================================================
  182. // Options
  183. // Each of the definitions above may have "options" attached. These are
  184. // just annotations which may cause code to be generated slightly differently
  185. // or may contain hints for code that manipulates protocol messages.
  186. //
  187. // Clients may define custom options as extensions of the *Options messages.
  188. // These extensions may not yet be known at parsing time, so the parser cannot
  189. // store the values in them. Instead it stores them in a field in the *Options
  190. // message called uninterpreted_option. This field must have the same name
  191. // across all *Options messages. We then use this field to populate the
  192. // extensions when we build a descriptor, at which point all protos have been
  193. // parsed and so all extensions are known.
  194. //
  195. // Extension numbers for custom options may be chosen as follows:
  196. // * For options which will only be used within a single application or
  197. // organization, or for experimental options, use field numbers 50000
  198. // through 99999. It is up to you to ensure that you do not use the
  199. // same number for multiple options.
  200. // * For options which will be published and used publicly by multiple
  201. // independent entities, e-mail protobuf-global-extension-registry@google.com
  202. // to reserve extension numbers. Simply provide your project name (e.g.
  203. // Object-C plugin) and your porject website (if available) -- there's no need
  204. // to explain how you intend to use them. Usually you only need one extension
  205. // number. You can declare multiple options with only one extension number by
  206. // putting them in a sub-message. See the Custom Options section of the docs
  207. // for examples:
  208. // https://developers.google.com/protocol-buffers/docs/proto#options
  209. // If this turns out to be popular, a web service will be set up
  210. // to automatically assign option numbers.
  211. message FileOptions {
  212. // Sets the Java package where classes generated from this .proto will be
  213. // placed. By default, the proto package is used, but this is often
  214. // inappropriate because proto packages do not normally start with backwards
  215. // domain names.
  216. optional string java_package = 1;
  217. // If set, all the classes from the .proto file are wrapped in a single
  218. // outer class with the given name. This applies to both Proto1
  219. // (equivalent to the old "--one_java_file" option) and Proto2 (where
  220. // a .proto always translates to a single class, but you may want to
  221. // explicitly choose the class name).
  222. optional string java_outer_classname = 8;
  223. // If set true, then the Java code generator will generate a separate .java
  224. // file for each top-level message, enum, and service defined in the .proto
  225. // file. Thus, these types will *not* be nested inside the outer class
  226. // named by java_outer_classname. However, the outer class will still be
  227. // generated to contain the file's getDescriptor() method as well as any
  228. // top-level extensions defined in the file.
  229. optional bool java_multiple_files = 10 [default=false];
  230. // If set true, then the Java code generator will generate equals() and
  231. // hashCode() methods for all messages defined in the .proto file.
  232. // - In the full runtime, this is purely a speed optimization, as the
  233. // AbstractMessage base class includes reflection-based implementations of
  234. // these methods.
  235. //- In the lite runtime, setting this option changes the semantics of
  236. // equals() and hashCode() to more closely match those of the full runtime;
  237. // the generated methods compute their results based on field values rather
  238. // than object identity. (Implementations should not assume that hashcodes
  239. // will be consistent across runtimes or versions of the protocol compiler.)
  240. optional bool java_generate_equals_and_hash = 20 [default=false];
  241. // If set true, then the Java2 code generator will generate code that
  242. // throws an exception whenever an attempt is made to assign a non-UTF-8
  243. // byte sequence to a string field.
  244. // Message reflection will do the same.
  245. // However, an extension field still accepts non-UTF-8 byte sequences.
  246. // This option has no effect on when used with the lite runtime.
  247. optional bool java_string_check_utf8 = 27 [default=false];
  248. // Generated classes can be optimized for speed or code size.
  249. enum OptimizeMode {
  250. SPEED = 1; // Generate complete code for parsing, serialization,
  251. // etc.
  252. CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
  253. LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
  254. }
  255. optional OptimizeMode optimize_for = 9 [default=SPEED];
  256. // Sets the Go package where structs generated from this .proto will be
  257. // placed. There is no default.
  258. optional string go_package = 11;
  259. // Should generic services be generated in each language? "Generic" services
  260. // are not specific to any particular RPC system. They are generated by the
  261. // main code generators in each language (without additional plugins).
  262. // Generic services were the only kind of service generation supported by
  263. // early versions of proto2.
  264. //
  265. // Generic services are now considered deprecated in favor of using plugins
  266. // that generate code specific to your particular RPC system. Therefore,
  267. // these default to false. Old code which depends on generic services should
  268. // explicitly set them to true.
  269. optional bool cc_generic_services = 16 [default=false];
  270. optional bool java_generic_services = 17 [default=false];
  271. optional bool py_generic_services = 18 [default=false];
  272. // Is this file deprecated?
  273. // Depending on the target platform, this can emit Deprecated annotations
  274. // for everything in the file, or it will be completely ignored; in the very
  275. // least, this is a formalization for deprecating files.
  276. optional bool deprecated = 23 [default=false];
  277. // The parser stores options it doesn't recognize here. See above.
  278. repeated UninterpretedOption uninterpreted_option = 999;
  279. // Clients can define custom options in extensions of this message. See above.
  280. extensions 1000 to max;
  281. }
  282. message MessageOptions {
  283. // Set true to use the old proto1 MessageSet wire format for extensions.
  284. // This is provided for backwards-compatibility with the MessageSet wire
  285. // format. You should not use this for any other reason: It's less
  286. // efficient, has fewer features, and is more complicated.
  287. //
  288. // The message must be defined exactly as follows:
  289. // message Foo {
  290. // option message_set_wire_format = true;
  291. // extensions 4 to max;
  292. // }
  293. // Note that the message cannot have any defined fields; MessageSets only
  294. // have extensions.
  295. //
  296. // All extensions of your type must be singular messages; e.g. they cannot
  297. // be int32s, enums, or repeated messages.
  298. //
  299. // Because this is an option, the above two restrictions are not enforced by
  300. // the protocol compiler.
  301. optional bool message_set_wire_format = 1 [default=false];
  302. // Disables the generation of the standard "descriptor()" accessor, which can
  303. // conflict with a field of the same name. This is meant to make migration
  304. // from proto1 easier; new code should avoid fields named "descriptor".
  305. optional bool no_standard_descriptor_accessor = 2 [default=false];
  306. // Is this message deprecated?
  307. // Depending on the target platform, this can emit Deprecated annotations
  308. // for the message, or it will be completely ignored; in the very least,
  309. // this is a formalization for deprecating messages.
  310. optional bool deprecated = 3 [default=false];
  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 FieldOptions {
  317. // The ctype option instructs the C++ code generator to use a different
  318. // representation of the field than it normally would. See the specific
  319. // options below. This option is not yet implemented in the open source
  320. // release -- sorry, we'll try to include it in a future version!
  321. optional CType ctype = 1 [default = STRING];
  322. enum CType {
  323. // Default mode.
  324. STRING = 0;
  325. CORD = 1;
  326. STRING_PIECE = 2;
  327. }
  328. // The packed option can be enabled for repeated primitive fields to enable
  329. // a more efficient representation on the wire. Rather than repeatedly
  330. // writing the tag and type for each element, the entire array is encoded as
  331. // a single length-delimited blob.
  332. optional bool packed = 2;
  333. // Should this field be parsed lazily? Lazy applies only to message-type
  334. // fields. It means that when the outer message is initially parsed, the
  335. // inner message's contents will not be parsed but instead stored in encoded
  336. // form. The inner message will actually be parsed when it is first accessed.
  337. //
  338. // This is only a hint. Implementations are free to choose whether to use
  339. // eager or lazy parsing regardless of the value of this option. However,
  340. // setting this option true suggests that the protocol author believes that
  341. // using lazy parsing on this field is worth the additional bookkeeping
  342. // overhead typically needed to implement it.
  343. //
  344. // This option does not affect the public interface of any generated code;
  345. // all method signatures remain the same. Furthermore, thread-safety of the
  346. // interface is not affected by this option; const methods remain safe to
  347. // call from multiple threads concurrently, while non-const methods continue
  348. // to require exclusive access.
  349. //
  350. //
  351. // Note that implementations may choose not to check required fields within
  352. // a lazy sub-message. That is, calling IsInitialized() on the outher message
  353. // may return true even if the inner message has missing required fields.
  354. // This is necessary because otherwise the inner message would have to be
  355. // parsed in order to perform the check, defeating the purpose of lazy
  356. // parsing. An implementation which chooses not to check required fields
  357. // must be consistent about it. That is, for any particular sub-message, the
  358. // implementation must either *always* check its required fields, or *never*
  359. // check its required fields, regardless of whether or not the message has
  360. // been parsed.
  361. optional bool lazy = 5 [default=false];
  362. // Is this field deprecated?
  363. // Depending on the target platform, this can emit Deprecated annotations
  364. // for accessors, or it will be completely ignored; in the very least, this
  365. // is a formalization for deprecating fields.
  366. optional bool deprecated = 3 [default=false];
  367. // EXPERIMENTAL. DO NOT USE.
  368. // For "map" fields, the name of the field in the enclosed type that
  369. // is the key for this map. For example, suppose we have:
  370. // message Item {
  371. // required string name = 1;
  372. // required string value = 2;
  373. // }
  374. // message Config {
  375. // repeated Item items = 1 [experimental_map_key="name"];
  376. // }
  377. // In this situation, the map key for Item will be set to "name".
  378. // TODO: Fully-implement this, then remove the "experimental_" prefix.
  379. optional string experimental_map_key = 9;
  380. // For Google-internal migration only. Do not use.
  381. optional bool weak = 10 [default=false];
  382. // The parser stores options it doesn't recognize here. See above.
  383. repeated UninterpretedOption uninterpreted_option = 999;
  384. // Clients can define custom options in extensions of this message. See above.
  385. extensions 1000 to max;
  386. }
  387. message EnumOptions {
  388. // Set this option to true to allow mapping different tag names to the same
  389. // value.
  390. optional bool allow_alias = 2;
  391. // Is this enum deprecated?
  392. // Depending on the target platform, this can emit Deprecated annotations
  393. // for the enum, or it will be completely ignored; in the very least, this
  394. // is a formalization for deprecating enums.
  395. optional bool deprecated = 3 [default=false];
  396. // The parser stores options it doesn't recognize here. See above.
  397. repeated UninterpretedOption uninterpreted_option = 999;
  398. // Clients can define custom options in extensions of this message. See above.
  399. extensions 1000 to max;
  400. }
  401. message EnumValueOptions {
  402. // Is this enum value deprecated?
  403. // Depending on the target platform, this can emit Deprecated annotations
  404. // for the enum value, or it will be completely ignored; in the very least,
  405. // this is a formalization for deprecating enum values.
  406. optional bool deprecated = 1 [default=false];
  407. // The parser stores options it doesn't recognize here. See above.
  408. repeated UninterpretedOption uninterpreted_option = 999;
  409. // Clients can define custom options in extensions of this message. See above.
  410. extensions 1000 to max;
  411. }
  412. message ServiceOptions {
  413. // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
  414. // framework. We apologize for hoarding these numbers to ourselves, but
  415. // we were already using them long before we decided to release Protocol
  416. // Buffers.
  417. // Is this service deprecated?
  418. // Depending on the target platform, this can emit Deprecated annotations
  419. // for the service, or it will be completely ignored; in the very least,
  420. // this is a formalization for deprecating services.
  421. optional bool deprecated = 33 [default=false];
  422. // The parser stores options it doesn't recognize here. See above.
  423. repeated UninterpretedOption uninterpreted_option = 999;
  424. // Clients can define custom options in extensions of this message. See above.
  425. extensions 1000 to max;
  426. }
  427. message MethodOptions {
  428. // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
  429. // framework. We apologize for hoarding these numbers to ourselves, but
  430. // we were already using them long before we decided to release Protocol
  431. // Buffers.
  432. // Is this method deprecated?
  433. // Depending on the target platform, this can emit Deprecated annotations
  434. // for the method, or it will be completely ignored; in the very least,
  435. // this is a formalization for deprecating methods.
  436. optional bool deprecated = 33 [default=false];
  437. // The parser stores options it doesn't recognize here. See above.
  438. repeated UninterpretedOption uninterpreted_option = 999;
  439. // Clients can define custom options in extensions of this message. See above.
  440. extensions 1000 to max;
  441. }
  442. // A message representing a option the parser does not recognize. This only
  443. // appears in options protos created by the compiler::Parser class.
  444. // DescriptorPool resolves these when building Descriptor objects. Therefore,
  445. // options protos in descriptor objects (e.g. returned by Descriptor::options(),
  446. // or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
  447. // in them.
  448. message UninterpretedOption {
  449. // The name of the uninterpreted option. Each string represents a segment in
  450. // a dot-separated name. is_extension is true iff a segment represents an
  451. // extension (denoted with parentheses in options specs in .proto files).
  452. // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
  453. // "foo.(bar.baz).qux".
  454. message NamePart {
  455. required string name_part = 1;
  456. required bool is_extension = 2;
  457. }
  458. repeated NamePart name = 2;
  459. // The value of the uninterpreted option, in whatever type the tokenizer
  460. // identified it as during parsing. Exactly one of these should be set.
  461. optional string identifier_value = 3;
  462. optional uint64 positive_int_value = 4;
  463. optional int64 negative_int_value = 5;
  464. optional double double_value = 6;
  465. optional bytes string_value = 7;
  466. optional string aggregate_value = 8;
  467. }
  468. // ===================================================================
  469. // Optional source code info
  470. // Encapsulates information about the original source file from which a
  471. // FileDescriptorProto was generated.
  472. message SourceCodeInfo {
  473. // A Location identifies a piece of source code in a .proto file which
  474. // corresponds to a particular definition. This information is intended
  475. // to be useful to IDEs, code indexers, documentation generators, and similar
  476. // tools.
  477. //
  478. // For example, say we have a file like:
  479. // message Foo {
  480. // optional string foo = 1;
  481. // }
  482. // Let's look at just the field definition:
  483. // optional string foo = 1;
  484. // ^ ^^ ^^ ^ ^^^
  485. // a bc de f ghi
  486. // We have the following locations:
  487. // span path represents
  488. // [a,i) [ 4, 0, 2, 0 ] The whole field definition.
  489. // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
  490. // [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
  491. // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
  492. // [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
  493. //
  494. // Notes:
  495. // - A location may refer to a repeated field itself (i.e. not to any
  496. // particular index within it). This is used whenever a set of elements are
  497. // logically enclosed in a single code segment. For example, an entire
  498. // extend block (possibly containing multiple extension definitions) will
  499. // have an outer location whose path refers to the "extensions" repeated
  500. // field without an index.
  501. // - Multiple locations may have the same path. This happens when a single
  502. // logical declaration is spread out across multiple places. The most
  503. // obvious example is the "extend" block again -- there may be multiple
  504. // extend blocks in the same scope, each of which will have the same path.
  505. // - A location's span is not always a subset of its parent's span. For
  506. // example, the "extendee" of an extension declaration appears at the
  507. // beginning of the "extend" block and is shared by all extensions within
  508. // the block.
  509. // - Just because a location's span is a subset of some other location's span
  510. // does not mean that it is a descendent. For example, a "group" defines
  511. // both a type and a field in a single declaration. Thus, the locations
  512. // corresponding to the type and field and their components will overlap.
  513. // - Code which tries to interpret locations should probably be designed to
  514. // ignore those that it doesn't understand, as more types of locations could
  515. // be recorded in the future.
  516. repeated Location location = 1;
  517. message Location {
  518. // Identifies which part of the FileDescriptorProto was defined at this
  519. // location.
  520. //
  521. // Each element is a field number or an index. They form a path from
  522. // the root FileDescriptorProto to the place where the definition. For
  523. // example, this path:
  524. // [ 4, 3, 2, 7, 1 ]
  525. // refers to:
  526. // file.message_type(3) // 4, 3
  527. // .field(7) // 2, 7
  528. // .name() // 1
  529. // This is because FileDescriptorProto.message_type has field number 4:
  530. // repeated DescriptorProto message_type = 4;
  531. // and DescriptorProto.field has field number 2:
  532. // repeated FieldDescriptorProto field = 2;
  533. // and FieldDescriptorProto.name has field number 1:
  534. // optional string name = 1;
  535. //
  536. // Thus, the above path gives the location of a field name. If we removed
  537. // the last element:
  538. // [ 4, 3, 2, 7 ]
  539. // this path refers to the whole field declaration (from the beginning
  540. // of the label to the terminating semicolon).
  541. repeated int32 path = 1 [packed=true];
  542. // Always has exactly three or four elements: start line, start column,
  543. // end line (optional, otherwise assumed same as start line), end column.
  544. // These are packed into a single field for efficiency. Note that line
  545. // and column numbers are zero-based -- typically you will want to add
  546. // 1 to each before displaying to a user.
  547. repeated int32 span = 2 [packed=true];
  548. // If this SourceCodeInfo represents a complete declaration, these are any
  549. // comments appearing before and after the declaration which appear to be
  550. // attached to the declaration.
  551. //
  552. // A series of line comments appearing on consecutive lines, with no other
  553. // tokens appearing on those lines, will be treated as a single comment.
  554. //
  555. // Only the comment content is provided; comment markers (e.g. //) are
  556. // stripped out. For block comments, leading whitespace and an asterisk
  557. // will be stripped from the beginning of each line other than the first.
  558. // Newlines are included in the output.
  559. //
  560. // Examples:
  561. //
  562. // optional int32 foo = 1; // Comment attached to foo.
  563. // // Comment attached to bar.
  564. // optional int32 bar = 2;
  565. //
  566. // optional string baz = 3;
  567. // // Comment attached to baz.
  568. // // Another line attached to baz.
  569. //
  570. // // Comment attached to qux.
  571. // //
  572. // // Another line attached to qux.
  573. // optional double qux = 4;
  574. //
  575. // optional string corge = 5;
  576. // /* Block comment attached
  577. // * to corge. Leading asterisks
  578. // * will be removed. */
  579. // /* Block comment attached to
  580. // * grault. */
  581. // optional int32 grault = 6;
  582. optional string leading_comments = 3;
  583. optional string trailing_comments = 4;
  584. }
  585. }