main
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
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
49// The protocol compiler can output a FileDescriptorSet containing the .proto
50// files it parses.
51message FileDescriptorSet {
52 repeated FileDescriptorProto file = 1;
53}
54
55// 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;
70}
71
72// Describes a message type.
73message DescriptorProto {
74 optional string name = 1;
75
76 repeated FieldDescriptorProto field = 2;
77 repeated FieldDescriptorProto extension = 6;
78
79 repeated DescriptorProto nested_type = 3;
80 repeated EnumDescriptorProto enum_type = 4;
81
82 message ExtensionRange {
83 optional int32 start = 1;
84 optional int32 end = 2;
85 }
86 repeated ExtensionRange extension_range = 5;
87
88 optional MessageOptions options = 7;
89}
90
91// Describes a field within a message.
92message FieldDescriptorProto {
93 enum Type {
94 // 0 is reserved for errors.
95 // Order is weird for historical reasons.
96 TYPE_DOUBLE = 1;
97 TYPE_FLOAT = 2;
98 TYPE_INT64 = 3; // Not ZigZag encoded. Negative numbers
99 // take 10 bytes. Use TYPE_SINT64 if negative
100 // values are likely.
101 TYPE_UINT64 = 4;
102 TYPE_INT32 = 5; // Not ZigZag encoded. Negative numbers
103 // take 10 bytes. Use TYPE_SINT32 if negative
104 // values are likely.
105 TYPE_FIXED64 = 6;
106 TYPE_FIXED32 = 7;
107 TYPE_BOOL = 8;
108 TYPE_STRING = 9;
109 TYPE_GROUP = 10; // Tag-delimited aggregate.
110 TYPE_MESSAGE = 11; // Length-delimited aggregate.
111
112 // New in version 2.
113 TYPE_BYTES = 12;
114 TYPE_UINT32 = 13;
115 TYPE_ENUM = 14;
116 TYPE_SFIXED32 = 15;
117 TYPE_SFIXED64 = 16;
118 TYPE_SINT32 = 17; // Uses ZigZag encoding.
119 TYPE_SINT64 = 18; // Uses ZigZag encoding.
120 };
121
122 enum Label {
123 // 0 is reserved for errors
124 LABEL_OPTIONAL = 1;
125 LABEL_REQUIRED = 2;
126 LABEL_REPEATED = 3;
127 // TODO(sanjay): Should we add LABEL_MAP?
128 };
129
130 optional string name = 1;
131 optional int32 number = 3;
132 optional Label label = 4;
133
134 // If type_name is set, this need not be set. If both this and type_name
135 // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
136 optional Type type = 5;
137
138 // For message and enum types, this is the name of the type. If the name
139 // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
140 // rules are used to find the type (i.e. first the nested types within this
141 // message are searched, then within the parent, on up to the root
142 // namespace).
143 optional string type_name = 6;
144
145 // For extensions, this is the name of the type being extended. It is
146 // resolved in the same manner as type_name.
147 optional string extendee = 2;
148
149 // For numeric types, contains the original text representation of the value.
150 // For booleans, "true" or "false".
151 // For strings, contains the default text contents (not escaped in any way).
152 // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
153 // TODO(kenton): Base-64 encode?
154 optional string default_value = 7;
155
156 optional FieldOptions options = 8;
157}
158
159// Describes an enum type.
160message EnumDescriptorProto {
161 optional string name = 1;
162
163 repeated EnumValueDescriptorProto value = 2;
164
165 optional EnumOptions options = 3;
166}
167
168// Describes a value within an enum.
169message EnumValueDescriptorProto {
170 optional string name = 1;
171 optional int32 number = 2;
172
173 optional EnumValueOptions options = 3;
174}
175
176// Describes a service.
177message ServiceDescriptorProto {
178 optional string name = 1;
179 repeated MethodDescriptorProto method = 2;
180
181 optional ServiceOptions options = 3;
182}
183
184// Describes a method of a service.
185message MethodDescriptorProto {
186 optional string name = 1;
187
188 // Input and output type names. These are resolved in the same way as
189 // FieldDescriptorProto.type_name, but must refer to a message type.
190 optional string input_type = 2;
191 optional string output_type = 3;
192
193 optional MethodOptions options = 4;
194}
195
196// ===================================================================
197// Options
198
199// Each of the definitions above may have "options" attached. These are
200// just annotations which may cause code to be generated slightly differently
201// or may contain hints for code that manipulates protocol messages.
202//
203// Clients may define custom options as extensions of the *Options messages.
204// These extensions may not yet be known at parsing time, so the parser cannot
205// store the values in them. Instead it stores them in a field in the *Options
206// message called uninterpreted_option. This field must have the same name
207// across all *Options messages. We then use this field to populate the
208// extensions when we build a descriptor, at which point all protos have been
209// parsed and so all extensions are known.
210//
211// Extension numbers for custom options may be chosen as follows:
212// * For options which will only be used within a single application or
213// organization, or for experimental options, use field numbers 50000
214// through 99999. It is up to you to ensure that you do not use the
215// same number for multiple options.
216// * For options which will be published and used publicly by multiple
217// independent entities, e-mail kenton@google.com to reserve extension
218// numbers. Simply tell me how many you need and I'll send you back a
219// set of numbers to use -- there's no need to explain how you intend to
220// use them. If this turns out to be popular, a web service will be set up
221// to automatically assign option numbers.
222
223
224message FileOptions {
225
226 // Sets the Java package where classes generated from this .proto will be
227 // placed. By default, the proto package is used, but this is often
228 // inappropriate because proto packages do not normally start with backwards
229 // domain names.
230 optional string java_package = 1;
231
232
233 // If set, all the classes from the .proto file are wrapped in a single
234 // outer class with the given name. This applies to both Proto1
235 // (equivalent to the old "--one_java_file" option) and Proto2 (where
236 // a .proto always translates to a single class, but you may want to
237 // explicitly choose the class name).
238 optional string java_outer_classname = 8;
239
240 // If set true, then the Java code generator will generate a separate .java
241 // file for each top-level message, enum, and service defined in the .proto
242 // file. Thus, these types will *not* be nested inside the outer class
243 // named by java_outer_classname. However, the outer class will still be
244 // generated to contain the file's getDescriptor() method as well as any
245 // top-level extensions defined in the file.
246 optional bool java_multiple_files = 10 [default=false];
247
248 // Generated classes can be optimized for speed or code size.
249 enum OptimizeMode {
250 SPEED = 1; // Generate complete code for parsing, serialization, etc.
251 CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
252 }
253 optional OptimizeMode optimize_for = 9 [default=SPEED];
254
255
256
257 // The parser stores options it doesn't recognize here. See above.
258 repeated UninterpretedOption uninterpreted_option = 999;
259
260 // Clients can define custom options in extensions of this message. See above.
261 extensions 1000 to max;
262}
263
264message MessageOptions {
265 // Set true to use the old proto1 MessageSet wire format for extensions.
266 // This is provided for backwards-compatibility with the MessageSet wire
267 // format. You should not use this for any other reason: It's less
268 // efficient, has fewer features, and is more complicated.
269 //
270 // The message must be defined exactly as follows:
271 // message Foo {
272 // option message_set_wire_format = true;
273 // extensions 4 to max;
274 // }
275 // Note that the message cannot have any defined fields; MessageSets only
276 // have extensions.
277 //
278 // All extensions of your type must be singular messages; e.g. they cannot
279 // be int32s, enums, or repeated messages.
280 //
281 // Because this is an option, the above two restrictions are not enforced by
282 // the protocol compiler.
283 optional bool message_set_wire_format = 1 [default=false];
284
285 // The parser stores options it doesn't recognize here. See above.
286 repeated UninterpretedOption uninterpreted_option = 999;
287
288 // Clients can define custom options in extensions of this message. See above.
289 extensions 1000 to max;
290}
291
292message FieldOptions {
293 // The ctype option instructs the C++ code generator to use a different
294 // representation of the field than it normally would. See the specific
295 // options below. This option is not yet implemented in the open source
296 // release -- sorry, we'll try to include it in a future version!
297 optional CType ctype = 1;
298 enum CType {
299 CORD = 1;
300
301 STRING_PIECE = 2;
302 }
303 // The packed option can be enabled for repeated primitive fields to enable
304 // a more efficient representation on the wire. Rather than repeatedly
305 // writing the tag and type for each element, the entire array is encoded as
306 // a single length-delimited blob.
307 optional bool packed = 2;
308
309 // Is this field deprecated?
310 // Depending on the target platform, this can emit Deprecated annotations
311 // for accessors, or it will be completely ignored; in the very least, this
312 // is a formalization for deprecating fields.
313 optional bool deprecated = 3 [default=false];
314
315 // EXPERIMENTAL. DO NOT USE.
316 // For "map" fields, the name of the field in the enclosed type that
317 // is the key for this map. For example, suppose we have:
318 // message Item {
319 // required string name = 1;
320 // required string value = 2;
321 // }
322 // message Config {
323 // repeated Item items = 1 [experimental_map_key="name"];
324 // }
325 // In this situation, the map key for Item will be set to "name".
326 // TODO: Fully-implement this, then remove the "experimental_" prefix.
327 optional string experimental_map_key = 9;
328
329 // The parser stores options it doesn't recognize here. See above.
330 repeated UninterpretedOption uninterpreted_option = 999;
331
332 // Clients can define custom options in extensions of this message. See above.
333 extensions 1000 to max;
334}
335
336message EnumOptions {
337
338 // The parser stores options it doesn't recognize here. See above.
339 repeated UninterpretedOption uninterpreted_option = 999;
340
341 // Clients can define custom options in extensions of this message. See above.
342 extensions 1000 to max;
343}
344
345message EnumValueOptions {
346 // The parser stores options it doesn't recognize here. See above.
347 repeated UninterpretedOption uninterpreted_option = 999;
348
349 // Clients can define custom options in extensions of this message. See above.
350 extensions 1000 to max;
351}
352
353message ServiceOptions {
354
355 // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
356 // framework. We apologize for hoarding these numbers to ourselves, but
357 // we were already using them long before we decided to release Protocol
358 // Buffers.
359
360 // The parser stores options it doesn't recognize here. See above.
361 repeated UninterpretedOption uninterpreted_option = 999;
362
363 // Clients can define custom options in extensions of this message. See above.
364 extensions 1000 to max;
365}
366
367message MethodOptions {
368
369 // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
370 // framework. We apologize for hoarding these numbers to ourselves, but
371 // we were already using them long before we decided to release Protocol
372 // Buffers.
373
374 // The parser stores options it doesn't recognize here. See above.
375 repeated UninterpretedOption uninterpreted_option = 999;
376
377 // Clients can define custom options in extensions of this message. See above.
378 extensions 1000 to max;
379}
380
381// A message representing a option the parser does not recognize. This only
382// appears in options protos created by the compiler::Parser class.
383// DescriptorPool resolves these when building Descriptor objects. Therefore,
384// options protos in descriptor objects (e.g. returned by Descriptor::options(),
385// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
386// in them.
387message UninterpretedOption {
388 // The name of the uninterpreted option. Each string represents a segment in
389 // a dot-separated name. is_extension is true iff a segment represents an
390 // extension (denoted with parentheses in options specs in .proto files).
391 // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
392 // "foo.(bar.baz).qux".
393 message NamePart {
394 required string name_part = 1;
395 required bool is_extension = 2;
396 }
397 repeated NamePart name = 2;
398
399 // The value of the uninterpreted option, in whatever type the tokenizer
400 // identified it as during parsing. Exactly one of these should be set.
401 optional string identifier_value = 3;
402 optional uint64 positive_int_value = 4;
403 optional int64 negative_int_value = 5;
404 optional double double_value = 6;
405 optional bytes string_value = 7;
406}