blob: 233f879410e92b77119e322828f325d16196b403 [file] [log] [blame]
temporal40ee5512008-07-10 02:12:20 +00001// Protocol Buffers - Google's data interchange format
kenton@google.com24bf56f2008-09-24 20:31:01 +00002// Copyright 2008 Google Inc. All rights reserved.
temporal40ee5512008-07-10 02:12:20 +00003// http://code.google.com/p/protobuf/
4//
kenton@google.com24bf56f2008-09-24 20:31:01 +00005// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
temporal40ee5512008-07-10 02:12:20 +00008//
kenton@google.com24bf56f2008-09-24 20:31:01 +00009// * 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.
temporal40ee5512008-07-10 02:12:20 +000018//
kenton@google.com24bf56f2008-09-24 20:31:01 +000019// 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.
temporal40ee5512008-07-10 02:12:20 +000030
31// Author: kenton@google.com (Kenton Varda)
32// Based on original Protocol Buffers design by
33// Sanjay Ghemawat, Jeff Dean, and others.
34//
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).
38
39
40
41package google.protobuf;
42option java_package = "com.google.protobuf";
43option java_outer_classname = "DescriptorProtos";
44
45// descriptor.proto must be optimized for speed because reflection-based
46// algorithms don't work during bootstrapping.
47option optimize_for = SPEED;
48
temporal779f61c2008-08-13 03:15:00 +000049// The protocol compiler can output a FileDescriptorSet containing the .proto
50// files it parses.
51message FileDescriptorSet {
52 repeated FileDescriptorProto file = 1;
53}
54
temporal40ee5512008-07-10 02:12:20 +000055// Describes a complete .proto file.
56message 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.
59
60 // Names of files imported by this file.
61 repeated string dependency = 3;
62
63 // All top-level definitions in this file.
64 repeated DescriptorProto message_type = 4;
65 repeated EnumDescriptorProto enum_type = 5;
66 repeated ServiceDescriptorProto service = 6;
67 repeated FieldDescriptorProto extension = 7;
68
69 optional FileOptions options = 8;
liujisi@google.com33165fe2010-11-02 13:14:58 +000070
71 // This field contains optional information about the original source code.
72 // You may safely remove this entire field whithout harming runtime
73 // functionality of the descriptors -- the information is needed only by
74 // development tools.
75 optional SourceCodeInfo source_code_info = 9;
temporal40ee5512008-07-10 02:12:20 +000076}
77
78// Describes a message type.
79message DescriptorProto {
80 optional string name = 1;
81
82 repeated FieldDescriptorProto field = 2;
83 repeated FieldDescriptorProto extension = 6;
84
85 repeated DescriptorProto nested_type = 3;
86 repeated EnumDescriptorProto enum_type = 4;
87
88 message ExtensionRange {
89 optional int32 start = 1;
90 optional int32 end = 2;
91 }
92 repeated ExtensionRange extension_range = 5;
93
94 optional MessageOptions options = 7;
95}
96
97// Describes a field within a message.
98message FieldDescriptorProto {
99 enum Type {
100 // 0 is reserved for errors.
101 // Order is weird for historical reasons.
102 TYPE_DOUBLE = 1;
103 TYPE_FLOAT = 2;
104 TYPE_INT64 = 3; // Not ZigZag encoded. Negative numbers
105 // take 10 bytes. Use TYPE_SINT64 if negative
106 // values are likely.
107 TYPE_UINT64 = 4;
108 TYPE_INT32 = 5; // Not ZigZag encoded. Negative numbers
109 // take 10 bytes. Use TYPE_SINT32 if negative
110 // values are likely.
111 TYPE_FIXED64 = 6;
112 TYPE_FIXED32 = 7;
113 TYPE_BOOL = 8;
114 TYPE_STRING = 9;
115 TYPE_GROUP = 10; // Tag-delimited aggregate.
116 TYPE_MESSAGE = 11; // Length-delimited aggregate.
117
118 // New in version 2.
119 TYPE_BYTES = 12;
120 TYPE_UINT32 = 13;
121 TYPE_ENUM = 14;
122 TYPE_SFIXED32 = 15;
123 TYPE_SFIXED64 = 16;
124 TYPE_SINT32 = 17; // Uses ZigZag encoding.
125 TYPE_SINT64 = 18; // Uses ZigZag encoding.
126 };
127
128 enum Label {
129 // 0 is reserved for errors
130 LABEL_OPTIONAL = 1;
131 LABEL_REQUIRED = 2;
132 LABEL_REPEATED = 3;
133 // TODO(sanjay): Should we add LABEL_MAP?
134 };
135
136 optional string name = 1;
137 optional int32 number = 3;
138 optional Label label = 4;
139
140 // If type_name is set, this need not be set. If both this and type_name
141 // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
142 optional Type type = 5;
143
144 // For message and enum types, this is the name of the type. If the name
145 // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
146 // rules are used to find the type (i.e. first the nested types within this
147 // message are searched, then within the parent, on up to the root
148 // namespace).
149 optional string type_name = 6;
150
151 // For extensions, this is the name of the type being extended. It is
152 // resolved in the same manner as type_name.
153 optional string extendee = 2;
154
155 // For numeric types, contains the original text representation of the value.
156 // For booleans, "true" or "false".
157 // For strings, contains the default text contents (not escaped in any way).
158 // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
159 // TODO(kenton): Base-64 encode?
160 optional string default_value = 7;
161
162 optional FieldOptions options = 8;
163}
164
165// Describes an enum type.
166message EnumDescriptorProto {
167 optional string name = 1;
168
169 repeated EnumValueDescriptorProto value = 2;
170
171 optional EnumOptions options = 3;
172}
173
174// Describes a value within an enum.
175message EnumValueDescriptorProto {
176 optional string name = 1;
177 optional int32 number = 2;
178
179 optional EnumValueOptions options = 3;
180}
181
182// Describes a service.
183message ServiceDescriptorProto {
184 optional string name = 1;
185 repeated MethodDescriptorProto method = 2;
186
187 optional ServiceOptions options = 3;
188}
189
190// Describes a method of a service.
191message MethodDescriptorProto {
192 optional string name = 1;
193
194 // Input and output type names. These are resolved in the same way as
195 // FieldDescriptorProto.type_name, but must refer to a message type.
196 optional string input_type = 2;
197 optional string output_type = 3;
198
199 optional MethodOptions options = 4;
200}
201
202// ===================================================================
203// Options
204
205// Each of the definitions above may have "options" attached. These are
206// just annotations which may cause code to be generated slightly differently
207// or may contain hints for code that manipulates protocol messages.
kenton@google.com24bf56f2008-09-24 20:31:01 +0000208//
209// Clients may define custom options as extensions of the *Options messages.
210// These extensions may not yet be known at parsing time, so the parser cannot
211// store the values in them. Instead it stores them in a field in the *Options
212// message called uninterpreted_option. This field must have the same name
213// across all *Options messages. We then use this field to populate the
214// extensions when we build a descriptor, at which point all protos have been
215// parsed and so all extensions are known.
216//
217// Extension numbers for custom options may be chosen as follows:
218// * For options which will only be used within a single application or
219// organization, or for experimental options, use field numbers 50000
220// through 99999. It is up to you to ensure that you do not use the
221// same number for multiple options.
222// * For options which will be published and used publicly by multiple
223// independent entities, e-mail kenton@google.com to reserve extension
224// numbers. Simply tell me how many you need and I'll send you back a
225// set of numbers to use -- there's no need to explain how you intend to
226// use them. If this turns out to be popular, a web service will be set up
227// to automatically assign option numbers.
temporal40ee5512008-07-10 02:12:20 +0000228
temporal40ee5512008-07-10 02:12:20 +0000229
230message FileOptions {
231
232 // Sets the Java package where classes generated from this .proto will be
233 // placed. By default, the proto package is used, but this is often
234 // inappropriate because proto packages do not normally start with backwards
235 // domain names.
236 optional string java_package = 1;
237
238
239 // If set, all the classes from the .proto file are wrapped in a single
240 // outer class with the given name. This applies to both Proto1
241 // (equivalent to the old "--one_java_file" option) and Proto2 (where
242 // a .proto always translates to a single class, but you may want to
243 // explicitly choose the class name).
244 optional string java_outer_classname = 8;
245
246 // If set true, then the Java code generator will generate a separate .java
247 // file for each top-level message, enum, and service defined in the .proto
248 // file. Thus, these types will *not* be nested inside the outer class
249 // named by java_outer_classname. However, the outer class will still be
250 // generated to contain the file's getDescriptor() method as well as any
251 // top-level extensions defined in the file.
252 optional bool java_multiple_files = 10 [default=false];
253
liujisi@google.com33165fe2010-11-02 13:14:58 +0000254 // If set true, then the Java code generator will generate equals() and
255 // hashCode() methods for all messages defined in the .proto file. This is
256 // purely a speed optimization, as the AbstractMessage base class includes
257 // reflection-based implementations of these methods.
258 optional bool java_generate_equals_and_hash = 20 [default=false];
259
temporal40ee5512008-07-10 02:12:20 +0000260 // Generated classes can be optimized for speed or code size.
261 enum OptimizeMode {
kenton@google.com80b1d622009-07-29 01:13:20 +0000262 SPEED = 1; // Generate complete code for parsing, serialization,
263 // etc.
264 CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
265 LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
temporal40ee5512008-07-10 02:12:20 +0000266 }
kenton@google.comd37d46d2009-04-25 02:53:47 +0000267 optional OptimizeMode optimize_for = 9 [default=SPEED];
kenton@google.com24bf56f2008-09-24 20:31:01 +0000268
kenton@google.com26bd9ee2008-11-21 00:06:27 +0000269
kenton@google.com2d6daa72009-01-22 01:27:00 +0000270
kenton@google.comfccb1462009-12-18 02:11:36 +0000271
272 // Should generic services be generated in each language? "Generic" services
273 // are not specific to any particular RPC system. They are generated by the
274 // main code generators in each language (without additional plugins).
275 // Generic services were the only kind of service generation supported by
276 // early versions of proto2.
277 //
278 // Generic services are now considered deprecated in favor of using plugins
liujisi@google.com33165fe2010-11-02 13:14:58 +0000279 // that generate code specific to your particular RPC system. Therefore,
280 // these default to false. Old code which depends on generic services should
281 // explicitly set them to true.
282 optional bool cc_generic_services = 16 [default=false];
283 optional bool java_generic_services = 17 [default=false];
284 optional bool py_generic_services = 18 [default=false];
kenton@google.comfccb1462009-12-18 02:11:36 +0000285
kenton@google.com24bf56f2008-09-24 20:31:01 +0000286 // The parser stores options it doesn't recognize here. See above.
287 repeated UninterpretedOption uninterpreted_option = 999;
288
289 // Clients can define custom options in extensions of this message. See above.
290 extensions 1000 to max;
temporal40ee5512008-07-10 02:12:20 +0000291}
292
293message MessageOptions {
294 // Set true to use the old proto1 MessageSet wire format for extensions.
295 // This is provided for backwards-compatibility with the MessageSet wire
296 // format. You should not use this for any other reason: It's less
297 // efficient, has fewer features, and is more complicated.
298 //
299 // The message must be defined exactly as follows:
300 // message Foo {
301 // option message_set_wire_format = true;
302 // extensions 4 to max;
303 // }
304 // Note that the message cannot have any defined fields; MessageSets only
305 // have extensions.
306 //
307 // All extensions of your type must be singular messages; e.g. they cannot
308 // be int32s, enums, or repeated messages.
309 //
310 // Because this is an option, the above two restrictions are not enforced by
311 // the protocol compiler.
312 optional bool message_set_wire_format = 1 [default=false];
kenton@google.com24bf56f2008-09-24 20:31:01 +0000313
kenton@google.com80b1d622009-07-29 01:13:20 +0000314 // Disables the generation of the standard "descriptor()" accessor, which can
315 // conflict with a field of the same name. This is meant to make migration
316 // from proto1 easier; new code should avoid fields named "descriptor".
317 optional bool no_standard_descriptor_accessor = 2 [default=false];
318
kenton@google.com24bf56f2008-09-24 20:31:01 +0000319 // The parser stores options it doesn't recognize here. See above.
320 repeated UninterpretedOption uninterpreted_option = 999;
321
322 // Clients can define custom options in extensions of this message. See above.
323 extensions 1000 to max;
temporal40ee5512008-07-10 02:12:20 +0000324}
325
326message FieldOptions {
327 // The ctype option instructs the C++ code generator to use a different
328 // representation of the field than it normally would. See the specific
329 // options below. This option is not yet implemented in the open source
330 // release -- sorry, we'll try to include it in a future version!
kenton@google.comfccb1462009-12-18 02:11:36 +0000331 optional CType ctype = 1 [default = STRING];
temporal40ee5512008-07-10 02:12:20 +0000332 enum CType {
kenton@google.comfccb1462009-12-18 02:11:36 +0000333 // Default mode.
334 STRING = 0;
335
temporal40ee5512008-07-10 02:12:20 +0000336 CORD = 1;
337
338 STRING_PIECE = 2;
339 }
kenton@google.com2d6daa72009-01-22 01:27:00 +0000340 // The packed option can be enabled for repeated primitive fields to enable
341 // a more efficient representation on the wire. Rather than repeatedly
342 // writing the tag and type for each element, the entire array is encoded as
343 // a single length-delimited blob.
344 optional bool packed = 2;
temporal40ee5512008-07-10 02:12:20 +0000345
kenton@google.comfccb1462009-12-18 02:11:36 +0000346
kenton@google.comd37d46d2009-04-25 02:53:47 +0000347 // Is this field deprecated?
348 // Depending on the target platform, this can emit Deprecated annotations
349 // for accessors, or it will be completely ignored; in the very least, this
350 // is a formalization for deprecating fields.
351 optional bool deprecated = 3 [default=false];
352
temporal40ee5512008-07-10 02:12:20 +0000353 // EXPERIMENTAL. DO NOT USE.
354 // For "map" fields, the name of the field in the enclosed type that
355 // is the key for this map. For example, suppose we have:
356 // message Item {
357 // required string name = 1;
358 // required string value = 2;
359 // }
360 // message Config {
361 // repeated Item items = 1 [experimental_map_key="name"];
362 // }
363 // In this situation, the map key for Item will be set to "name".
364 // TODO: Fully-implement this, then remove the "experimental_" prefix.
365 optional string experimental_map_key = 9;
kenton@google.com24bf56f2008-09-24 20:31:01 +0000366
367 // The parser stores options it doesn't recognize here. See above.
368 repeated UninterpretedOption uninterpreted_option = 999;
369
370 // Clients can define custom options in extensions of this message. See above.
371 extensions 1000 to max;
temporal40ee5512008-07-10 02:12:20 +0000372}
373
374message EnumOptions {
kenton@google.comd37d46d2009-04-25 02:53:47 +0000375
kenton@google.com24bf56f2008-09-24 20:31:01 +0000376 // The parser stores options it doesn't recognize here. See above.
377 repeated UninterpretedOption uninterpreted_option = 999;
378
379 // Clients can define custom options in extensions of this message. See above.
380 extensions 1000 to max;
temporal40ee5512008-07-10 02:12:20 +0000381}
382
383message EnumValueOptions {
kenton@google.com24bf56f2008-09-24 20:31:01 +0000384 // The parser stores options it doesn't recognize here. See above.
385 repeated UninterpretedOption uninterpreted_option = 999;
386
387 // Clients can define custom options in extensions of this message. See above.
388 extensions 1000 to max;
temporal40ee5512008-07-10 02:12:20 +0000389}
390
391message ServiceOptions {
392
393 // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
394 // framework. We apologize for hoarding these numbers to ourselves, but
395 // we were already using them long before we decided to release Protocol
396 // Buffers.
kenton@google.com24bf56f2008-09-24 20:31:01 +0000397
398 // The parser stores options it doesn't recognize here. See above.
399 repeated UninterpretedOption uninterpreted_option = 999;
400
401 // Clients can define custom options in extensions of this message. See above.
402 extensions 1000 to max;
temporal40ee5512008-07-10 02:12:20 +0000403}
404
405message MethodOptions {
406
407 // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
408 // framework. We apologize for hoarding these numbers to ourselves, but
409 // we were already using them long before we decided to release Protocol
410 // Buffers.
kenton@google.com24bf56f2008-09-24 20:31:01 +0000411
412 // The parser stores options it doesn't recognize here. See above.
413 repeated UninterpretedOption uninterpreted_option = 999;
414
415 // Clients can define custom options in extensions of this message. See above.
416 extensions 1000 to max;
417}
418
419// A message representing a option the parser does not recognize. This only
420// appears in options protos created by the compiler::Parser class.
421// DescriptorPool resolves these when building Descriptor objects. Therefore,
422// options protos in descriptor objects (e.g. returned by Descriptor::options(),
423// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
424// in them.
425message UninterpretedOption {
426 // The name of the uninterpreted option. Each string represents a segment in
427 // a dot-separated name. is_extension is true iff a segment represents an
428 // extension (denoted with parentheses in options specs in .proto files).
429 // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
430 // "foo.(bar.baz).qux".
431 message NamePart {
432 required string name_part = 1;
433 required bool is_extension = 2;
434 }
435 repeated NamePart name = 2;
436
437 // The value of the uninterpreted option, in whatever type the tokenizer
438 // identified it as during parsing. Exactly one of these should be set.
439 optional string identifier_value = 3;
440 optional uint64 positive_int_value = 4;
441 optional int64 negative_int_value = 5;
442 optional double double_value = 6;
443 optional bytes string_value = 7;
liujisi@google.com33165fe2010-11-02 13:14:58 +0000444 optional string aggregate_value = 8;
445}
446
447// ===================================================================
448// Optional source code info
449
450// Encapsulates information about the original source file from which a
451// FileDescriptorProto was generated.
452message SourceCodeInfo {
453 // A Location identifies a piece of source code in a .proto file which
454 // corresponds to a particular definition. This information is intended
455 // to be useful to IDEs, code indexers, documentation generators, and similar
456 // tools.
457 //
458 // For example, say we have a file like:
459 // message Foo {
460 // optional string foo = 1;
461 // }
462 // Let's look at just the field definition:
463 // optional string foo = 1;
464 // ^ ^^ ^^ ^ ^^^
465 // a bc de f ghi
466 // We have the following locations:
467 // span path represents
468 // [a,i) [ 4, 0, 2, 0 ] The whole field definition.
469 // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
470 // [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
471 // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
472 // [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
473 //
474 // Notes:
475 // - A location may refer to a repeated field itself (i.e. not to any
476 // particular index within it). This is used whenever a set of elements are
477 // logically enclosed in a single code segment. For example, an entire
478 // extend block (possibly containing multiple extension definitions) will
479 // have an outer location whose path refers to the "extensions" repeated
480 // field without an index.
481 // - Multiple locations may have the same path. This happens when a single
482 // logical declaration is spread out across multiple places. The most
483 // obvious example is the "extend" block again -- there may be multiple
484 // extend blocks in the same scope, each of which will have the same path.
485 // - A location's span is not always a subset of its parent's span. For
486 // example, the "extendee" of an extension declaration appears at the
487 // beginning of the "extend" block and is shared by all extensions within
488 // the block.
489 // - Just because a location's span is a subset of some other location's span
490 // does not mean that it is a descendent. For example, a "group" defines
491 // both a type and a field in a single declaration. Thus, the locations
492 // corresponding to the type and field and their components will overlap.
493 // - Code which tries to interpret locations should probably be designed to
494 // ignore those that it doesn't understand, as more types of locations could
495 // be recorded in the future.
496 repeated Location location = 1;
497 message Location {
498 // Identifies which part of the FileDescriptorProto was defined at this
499 // location.
500 //
501 // Each element is a field number or an index. They form a path from
502 // the root FileDescriptorProto to the place where the definition. For
503 // example, this path:
504 // [ 4, 3, 2, 7, 1 ]
505 // refers to:
506 // file.message_type(3) // 4, 3
507 // .field(7) // 2, 7
508 // .name() // 1
509 // This is because FileDescriptorProto.message_type has field number 4:
510 // repeated DescriptorProto message_type = 4;
511 // and DescriptorProto.field has field number 2:
512 // repeated FieldDescriptorProto field = 2;
513 // and FieldDescriptorProto.name has field number 1:
514 // optional string name = 1;
515 //
516 // Thus, the above path gives the location of a field name. If we removed
517 // the last element:
518 // [ 4, 3, 2, 7 ]
519 // this path refers to the whole field declaration (from the beginning
520 // of the label to the terminating semicolon).
521 repeated int32 path = 1 [packed=true];
522
523 // Always has exactly three or four elements: start line, start column,
524 // end line (optional, otherwise assumed same as start line), end column.
525 // These are packed into a single field for efficiency. Note that line
526 // and column numbers are zero-based -- typically you will want to add
527 // 1 to each before displaying to a user.
528 repeated int32 span = 2 [packed=true];
529
530 // TODO(kenton): Record comments appearing before and after the
531 // declaration.
532 }
temporal40ee5512008-07-10 02:12:20 +0000533}