1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // http://code.google.com/p/protobuf/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
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
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.
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.
31 // Author: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
35 // The messages in this file describe the definitions found in .proto files.
36 // A valid .proto file can be translated directly to a FileDescriptorProto
37 // without any other information (e.g. without reading its imports).
41 package google.protobuf;
42 option java_package = "com.google.protobuf";
43 option java_outer_classname = "DescriptorProtos";
45 // descriptor.proto must be optimized for speed because reflection-based
46 // algorithms don't work during bootstrapping.
47 option optimize_for = SPEED;
49 // The protocol compiler can output a FileDescriptorSet containing the .proto
51 message FileDescriptorSet {
52 repeated FileDescriptorProto file = 1;
55 // Describes a complete .proto file.
56 message FileDescriptorProto {
57 optional string name = 1; // file name, relative to root of source tree
58 optional string package = 2; // e.g. "foo", "foo.bar", etc.
60 // Names of files imported by this file.
61 repeated string dependency = 3;
62 // Indexes of the public imported files in the dependency list above.
63 repeated int32 public_dependency = 10;
64 // Indexes of the weak imported files in the dependency list.
65 // For Google-internal migration only. Do not use.
66 repeated int32 weak_dependency = 11;
68 // All top-level definitions in this file.
69 repeated DescriptorProto message_type = 4;
70 repeated EnumDescriptorProto enum_type = 5;
71 repeated ServiceDescriptorProto service = 6;
72 repeated FieldDescriptorProto extension = 7;
74 optional FileOptions options = 8;
76 // This field contains optional information about the original source code.
77 // You may safely remove this entire field whithout harming runtime
78 // functionality of the descriptors -- the information is needed only by
80 optional SourceCodeInfo source_code_info = 9;
83 // Describes a message type.
84 message DescriptorProto {
85 optional string name = 1;
87 repeated FieldDescriptorProto field = 2;
88 repeated FieldDescriptorProto extension = 6;
90 repeated DescriptorProto nested_type = 3;
91 repeated EnumDescriptorProto enum_type = 4;
93 message ExtensionRange {
94 optional int32 start = 1;
95 optional int32 end = 2;
97 repeated ExtensionRange extension_range = 5;
99 optional MessageOptions options = 7;
102 // Describes a field within a message.
103 message FieldDescriptorProto {
105 // 0 is reserved for errors.
106 // Order is weird for historical reasons.
109 // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
110 // negative values are likely.
113 // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
114 // negative values are likely.
120 TYPE_GROUP = 10; // Tag-delimited aggregate.
121 TYPE_MESSAGE = 11; // Length-delimited aggregate.
129 TYPE_SINT32 = 17; // Uses ZigZag encoding.
130 TYPE_SINT64 = 18; // Uses ZigZag encoding.
134 // 0 is reserved for errors
138 // TODO(sanjay): Should we add LABEL_MAP?
141 optional string name = 1;
142 optional int32 number = 3;
143 optional Label label = 4;
145 // If type_name is set, this need not be set. If both this and type_name
146 // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
147 optional Type type = 5;
149 // For message and enum types, this is the name of the type. If the name
150 // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
151 // rules are used to find the type (i.e. first the nested types within this
152 // message are searched, then within the parent, on up to the root
154 optional string type_name = 6;
156 // For extensions, this is the name of the type being extended. It is
157 // resolved in the same manner as type_name.
158 optional string extendee = 2;
160 // For numeric types, contains the original text representation of the value.
161 // For booleans, "true" or "false".
162 // For strings, contains the default text contents (not escaped in any way).
163 // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
164 // TODO(kenton): Base-64 encode?
165 optional string default_value = 7;
167 optional FieldOptions options = 8;
170 // Describes an enum type.
171 message EnumDescriptorProto {
172 optional string name = 1;
174 repeated EnumValueDescriptorProto value = 2;
176 optional EnumOptions options = 3;
179 // Describes a value within an enum.
180 message EnumValueDescriptorProto {
181 optional string name = 1;
182 optional int32 number = 2;
184 optional EnumValueOptions options = 3;
187 // Describes a service.
188 message ServiceDescriptorProto {
189 optional string name = 1;
190 repeated MethodDescriptorProto method = 2;
192 optional ServiceOptions options = 3;
195 // Describes a method of a service.
196 message MethodDescriptorProto {
197 optional string name = 1;
199 // Input and output type names. These are resolved in the same way as
200 // FieldDescriptorProto.type_name, but must refer to a message type.
201 optional string input_type = 2;
202 optional string output_type = 3;
204 optional MethodOptions options = 4;
208 // ===================================================================
211 // Each of the definitions above may have "options" attached. These are
212 // just annotations which may cause code to be generated slightly differently
213 // or may contain hints for code that manipulates protocol messages.
215 // Clients may define custom options as extensions of the *Options messages.
216 // These extensions may not yet be known at parsing time, so the parser cannot
217 // store the values in them. Instead it stores them in a field in the *Options
218 // message called uninterpreted_option. This field must have the same name
219 // across all *Options messages. We then use this field to populate the
220 // extensions when we build a descriptor, at which point all protos have been
221 // parsed and so all extensions are known.
223 // Extension numbers for custom options may be chosen as follows:
224 // * For options which will only be used within a single application or
225 // organization, or for experimental options, use field numbers 50000
226 // through 99999. It is up to you to ensure that you do not use the
227 // same number for multiple options.
228 // * For options which will be published and used publicly by multiple
229 // independent entities, e-mail protobuf-global-extension-registry@google.com
230 // to reserve extension numbers. Simply provide your project name (e.g.
231 // Object-C plugin) and your porject website (if available) -- there's no need
232 // to explain how you intend to use them. Usually you only need one extension
233 // number. You can declare multiple options with only one extension number by
234 // putting them in a sub-message. See the Custom Options section of the docs
236 // http://code.google.com/apis/protocolbuffers/docs/proto.html#options
237 // If this turns out to be popular, a web service will be set up
238 // to automatically assign option numbers.
241 message FileOptions {
243 // Sets the Java package where classes generated from this .proto will be
244 // placed. By default, the proto package is used, but this is often
245 // inappropriate because proto packages do not normally start with backwards
247 optional string java_package = 1;
250 // If set, all the classes from the .proto file are wrapped in a single
251 // outer class with the given name. This applies to both Proto1
252 // (equivalent to the old "--one_java_file" option) and Proto2 (where
253 // a .proto always translates to a single class, but you may want to
254 // explicitly choose the class name).
255 optional string java_outer_classname = 8;
257 // If set true, then the Java code generator will generate a separate .java
258 // file for each top-level message, enum, and service defined in the .proto
259 // file. Thus, these types will *not* be nested inside the outer class
260 // named by java_outer_classname. However, the outer class will still be
261 // generated to contain the file's getDescriptor() method as well as any
262 // top-level extensions defined in the file.
263 optional bool java_multiple_files = 10 [default=false];
265 // If set true, then the Java code generator will generate equals() and
266 // hashCode() methods for all messages defined in the .proto file. This is
267 // purely a speed optimization, as the AbstractMessage base class includes
268 // reflection-based implementations of these methods.
269 optional bool java_generate_equals_and_hash = 20 [default=false];
271 // Generated classes can be optimized for speed or code size.
273 SPEED = 1; // Generate complete code for parsing, serialization,
275 CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
276 LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
278 optional OptimizeMode optimize_for = 9 [default=SPEED];
280 // Sets the Go package where structs generated from this .proto will be
281 // placed. There is no default.
282 optional string go_package = 11;
286 // Should generic services be generated in each language? "Generic" services
287 // are not specific to any particular RPC system. They are generated by the
288 // main code generators in each language (without additional plugins).
289 // Generic services were the only kind of service generation supported by
290 // early versions of proto2.
292 // Generic services are now considered deprecated in favor of using plugins
293 // that generate code specific to your particular RPC system. Therefore,
294 // these default to false. Old code which depends on generic services should
295 // explicitly set them to true.
296 optional bool cc_generic_services = 16 [default=false];
297 optional bool java_generic_services = 17 [default=false];
298 optional bool py_generic_services = 18 [default=false];
300 // The parser stores options it doesn't recognize here. See above.
301 repeated UninterpretedOption uninterpreted_option = 999;
303 // Clients can define custom options in extensions of this message. See above.
304 extensions 1000 to max;
307 message MessageOptions {
308 // Set true to use the old proto1 MessageSet wire format for extensions.
309 // This is provided for backwards-compatibility with the MessageSet wire
310 // format. You should not use this for any other reason: It's less
311 // efficient, has fewer features, and is more complicated.
313 // The message must be defined exactly as follows:
315 // option message_set_wire_format = true;
316 // extensions 4 to max;
318 // Note that the message cannot have any defined fields; MessageSets only
321 // All extensions of your type must be singular messages; e.g. they cannot
322 // be int32s, enums, or repeated messages.
324 // Because this is an option, the above two restrictions are not enforced by
325 // the protocol compiler.
326 optional bool message_set_wire_format = 1 [default=false];
328 // Disables the generation of the standard "descriptor()" accessor, which can
329 // conflict with a field of the same name. This is meant to make migration
330 // from proto1 easier; new code should avoid fields named "descriptor".
331 optional bool no_standard_descriptor_accessor = 2 [default=false];
333 // The parser stores options it doesn't recognize here. See above.
334 repeated UninterpretedOption uninterpreted_option = 999;
336 // Clients can define custom options in extensions of this message. See above.
337 extensions 1000 to max;
340 message FieldOptions {
341 // The ctype option instructs the C++ code generator to use a different
342 // representation of the field than it normally would. See the specific
343 // options below. This option is not yet implemented in the open source
344 // release -- sorry, we'll try to include it in a future version!
345 optional CType ctype = 1 [default = STRING];
354 // The packed option can be enabled for repeated primitive fields to enable
355 // a more efficient representation on the wire. Rather than repeatedly
356 // writing the tag and type for each element, the entire array is encoded as
357 // a single length-delimited blob.
358 optional bool packed = 2;
362 // Should this field be parsed lazily? Lazy applies only to message-type
363 // fields. It means that when the outer message is initially parsed, the
364 // inner message's contents will not be parsed but instead stored in encoded
365 // form. The inner message will actually be parsed when it is first accessed.
367 // This is only a hint. Implementations are free to choose whether to use
368 // eager or lazy parsing regardless of the value of this option. However,
369 // setting this option true suggests that the protocol author believes that
370 // using lazy parsing on this field is worth the additional bookkeeping
371 // overhead typically needed to implement it.
373 // This option does not affect the public interface of any generated code;
374 // all method signatures remain the same. Furthermore, thread-safety of the
375 // interface is not affected by this option; const methods remain safe to
376 // call from multiple threads concurrently, while non-const methods continue
377 // to require exclusive access.
380 // Note that implementations may choose not to check required fields within
381 // a lazy sub-message. That is, calling IsInitialized() on the outher message
382 // may return true even if the inner message has missing required fields.
383 // This is necessary because otherwise the inner message would have to be
384 // parsed in order to perform the check, defeating the purpose of lazy
385 // parsing. An implementation which chooses not to check required fields
386 // must be consistent about it. That is, for any particular sub-message, the
387 // implementation must either *always* check its required fields, or *never*
388 // check its required fields, regardless of whether or not the message has
390 optional bool lazy = 5 [default=false];
392 // Is this field deprecated?
393 // Depending on the target platform, this can emit Deprecated annotations
394 // for accessors, or it will be completely ignored; in the very least, this
395 // is a formalization for deprecating fields.
396 optional bool deprecated = 3 [default=false];
398 // EXPERIMENTAL. DO NOT USE.
399 // For "map" fields, the name of the field in the enclosed type that
400 // is the key for this map. For example, suppose we have:
402 // required string name = 1;
403 // required string value = 2;
406 // repeated Item items = 1 [experimental_map_key="name"];
408 // In this situation, the map key for Item will be set to "name".
409 // TODO: Fully-implement this, then remove the "experimental_" prefix.
410 optional string experimental_map_key = 9;
412 // For Google-internal migration only. Do not use.
413 optional bool weak = 10 [default=false];
415 // The parser stores options it doesn't recognize here. See above.
416 repeated UninterpretedOption uninterpreted_option = 999;
418 // Clients can define custom options in extensions of this message. See above.
419 extensions 1000 to max;
422 message EnumOptions {
424 // Set this option to false to disallow mapping different tag names to a same
426 optional bool allow_alias = 2 [default=true];
428 // The parser stores options it doesn't recognize here. See above.
429 repeated UninterpretedOption uninterpreted_option = 999;
431 // Clients can define custom options in extensions of this message. See above.
432 extensions 1000 to max;
435 message EnumValueOptions {
436 // The parser stores options it doesn't recognize here. See above.
437 repeated UninterpretedOption uninterpreted_option = 999;
439 // Clients can define custom options in extensions of this message. See above.
440 extensions 1000 to max;
443 message ServiceOptions {
445 // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
446 // framework. We apologize for hoarding these numbers to ourselves, but
447 // we were already using them long before we decided to release Protocol
450 // The parser stores options it doesn't recognize here. See above.
451 repeated UninterpretedOption uninterpreted_option = 999;
453 // Clients can define custom options in extensions of this message. See above.
454 extensions 1000 to max;
457 message MethodOptions {
459 // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
460 // framework. We apologize for hoarding these numbers to ourselves, but
461 // we were already using them long before we decided to release Protocol
464 // The parser stores options it doesn't recognize here. See above.
465 repeated UninterpretedOption uninterpreted_option = 999;
467 // Clients can define custom options in extensions of this message. See above.
468 extensions 1000 to max;
472 // A message representing a option the parser does not recognize. This only
473 // appears in options protos created by the compiler::Parser class.
474 // DescriptorPool resolves these when building Descriptor objects. Therefore,
475 // options protos in descriptor objects (e.g. returned by Descriptor::options(),
476 // or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
478 message UninterpretedOption {
479 // The name of the uninterpreted option. Each string represents a segment in
480 // a dot-separated name. is_extension is true iff a segment represents an
481 // extension (denoted with parentheses in options specs in .proto files).
482 // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
483 // "foo.(bar.baz).qux".
485 required string name_part = 1;
486 required bool is_extension = 2;
488 repeated NamePart name = 2;
490 // The value of the uninterpreted option, in whatever type the tokenizer
491 // identified it as during parsing. Exactly one of these should be set.
492 optional string identifier_value = 3;
493 optional uint64 positive_int_value = 4;
494 optional int64 negative_int_value = 5;
495 optional double double_value = 6;
496 optional bytes string_value = 7;
497 optional string aggregate_value = 8;
500 // ===================================================================
501 // Optional source code info
503 // Encapsulates information about the original source file from which a
504 // FileDescriptorProto was generated.
505 message SourceCodeInfo {
506 // A Location identifies a piece of source code in a .proto file which
507 // corresponds to a particular definition. This information is intended
508 // to be useful to IDEs, code indexers, documentation generators, and similar
511 // For example, say we have a file like:
513 // optional string foo = 1;
515 // Let's look at just the field definition:
516 // optional string foo = 1;
519 // We have the following locations:
520 // span path represents
521 // [a,i) [ 4, 0, 2, 0 ] The whole field definition.
522 // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
523 // [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
524 // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
525 // [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
528 // - A location may refer to a repeated field itself (i.e. not to any
529 // particular index within it). This is used whenever a set of elements are
530 // logically enclosed in a single code segment. For example, an entire
531 // extend block (possibly containing multiple extension definitions) will
532 // have an outer location whose path refers to the "extensions" repeated
533 // field without an index.
534 // - Multiple locations may have the same path. This happens when a single
535 // logical declaration is spread out across multiple places. The most
536 // obvious example is the "extend" block again -- there may be multiple
537 // extend blocks in the same scope, each of which will have the same path.
538 // - A location's span is not always a subset of its parent's span. For
539 // example, the "extendee" of an extension declaration appears at the
540 // beginning of the "extend" block and is shared by all extensions within
542 // - Just because a location's span is a subset of some other location's span
543 // does not mean that it is a descendent. For example, a "group" defines
544 // both a type and a field in a single declaration. Thus, the locations
545 // corresponding to the type and field and their components will overlap.
546 // - Code which tries to interpret locations should probably be designed to
547 // ignore those that it doesn't understand, as more types of locations could
548 // be recorded in the future.
549 repeated Location location = 1;
551 // Identifies which part of the FileDescriptorProto was defined at this
554 // Each element is a field number or an index. They form a path from
555 // the root FileDescriptorProto to the place where the definition. For
556 // example, this path:
559 // file.message_type(3) // 4, 3
562 // This is because FileDescriptorProto.message_type has field number 4:
563 // repeated DescriptorProto message_type = 4;
564 // and DescriptorProto.field has field number 2:
565 // repeated FieldDescriptorProto field = 2;
566 // and FieldDescriptorProto.name has field number 1:
567 // optional string name = 1;
569 // Thus, the above path gives the location of a field name. If we removed
572 // this path refers to the whole field declaration (from the beginning
573 // of the label to the terminating semicolon).
574 repeated int32 path = 1 [packed=true];
576 // Always has exactly three or four elements: start line, start column,
577 // end line (optional, otherwise assumed same as start line), end column.
578 // These are packed into a single field for efficiency. Note that line
579 // and column numbers are zero-based -- typically you will want to add
580 // 1 to each before displaying to a user.
581 repeated int32 span = 2 [packed=true];
583 // If this SourceCodeInfo represents a complete declaration, these are any
584 // comments appearing before and after the declaration which appear to be
585 // attached to the declaration.
587 // A series of line comments appearing on consecutive lines, with no other
588 // tokens appearing on those lines, will be treated as a single comment.
590 // Only the comment content is provided; comment markers (e.g. //) are
591 // stripped out. For block comments, leading whitespace and an asterisk
592 // will be stripped from the beginning of each line other than the first.
593 // Newlines are included in the output.
597 // optional int32 foo = 1; // Comment attached to foo.
598 // // Comment attached to bar.
599 // optional int32 bar = 2;
601 // optional string baz = 3;
602 // // Comment attached to baz.
603 // // Another line attached to baz.
605 // // Comment attached to qux.
607 // // Another line attached to qux.
608 // optional double qux = 4;
610 // optional string corge = 5;
611 // /* Block comment attached
612 // * to corge. Leading asterisks
613 // * will be removed. */
614 // /* Block comment attached to
616 // optional int32 grault = 6;
617 optional string leading_comments = 3;
618 optional string trailing_comments = 4;