Home | History | Annotate | Download | only in protobuf
      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 (a] 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 
     41 package google.protobuf;
     42 option java_package = "com.google.protobuf";
     43 option java_outer_classname = "DescriptorProtos";
     44 
     45 // descriptor.proto must be optimized for speed because reflection-based
     46 // algorithms don't work during bootstrapping.
     47 option optimize_for = SPEED;
     48 
     49 // The protocol compiler can output a FileDescriptorSet containing the .proto
     50 // files it parses.
     51 message FileDescriptorSet {
     52   repeated FileDescriptorProto file = 1;
     53 }
     54 
     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.
     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.
     73 message 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.
     92 message 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.
    160 message 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.
    169 message EnumValueDescriptorProto {
    170   optional string name = 1;
    171   optional int32 number = 2;
    172 
    173   optional EnumValueOptions options = 3;
    174 }
    175 
    176 // Describes a service.
    177 message 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.
    185 message 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 (a] 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 
    224 message 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,
    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 
    257 
    258 
    259 
    260   // Should generic services be generated in each language?  "Generic" services
    261   // are not specific to any particular RPC system.  They are generated by the
    262   // main code generators in each language (without additional plugins).
    263   // Generic services were the only kind of service generation supported by
    264   // early versions of proto2.
    265   //
    266   // Generic services are now considered deprecated in favor of using plugins
    267   // that generate code specific to your particular RPC system.  If you are
    268   // using such a plugin, set these to false.  In the future, we may change
    269   // the default to false, so if you explicitly want generic services, you
    270   // should explicitly set these to true.
    271   optional bool cc_generic_services = 16 [default=true];
    272   optional bool java_generic_services = 17 [default=true];
    273   optional bool py_generic_services = 18 [default=true];
    274 
    275   // The parser stores options it doesn't recognize here. See above.
    276   repeated UninterpretedOption uninterpreted_option = 999;
    277 
    278   // Clients can define custom options in extensions of this message. See above.
    279   extensions 1000 to max;
    280 }
    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 
    303   // Disables the generation of the standard "descriptor()" accessor, which can
    304   // conflict with a field of the same name.  This is meant to make migration
    305   // from proto1 easier; new code should avoid fields named "descriptor".
    306   optional bool no_standard_descriptor_accessor = 2 [default=false];
    307 
    308   // The parser stores options it doesn't recognize here. See above.
    309   repeated UninterpretedOption uninterpreted_option = 999;
    310 
    311   // Clients can define custom options in extensions of this message. See above.
    312   extensions 1000 to max;
    313 }
    314 
    315 message FieldOptions {
    316   // The ctype option instructs the C++ code generator to use a different
    317   // representation of the field than it normally would.  See the specific
    318   // options below.  This option is not yet implemented in the open source
    319   // release -- sorry, we'll try to include it in a future version!
    320   optional CType ctype = 1 [default = STRING];
    321   enum CType {
    322     // Default mode.
    323     STRING = 0;
    324 
    325     CORD = 1;
    326 
    327     STRING_PIECE = 2;
    328   }
    329   // The packed option can be enabled for repeated primitive fields to enable
    330   // a more efficient representation on the wire. Rather than repeatedly
    331   // writing the tag and type for each element, the entire array is encoded as
    332   // a single length-delimited blob.
    333   optional bool packed = 2;
    334 
    335 
    336   // Is this field deprecated?
    337   // Depending on the target platform, this can emit Deprecated annotations
    338   // for accessors, or it will be completely ignored; in the very least, this
    339   // is a formalization for deprecating fields.
    340   optional bool deprecated = 3 [default=false];
    341 
    342   // EXPERIMENTAL.  DO NOT USE.
    343   // For "map" fields, the name of the field in the enclosed type that
    344   // is the key for this map.  For example, suppose we have:
    345   //   message Item {
    346   //     required string name = 1;
    347   //     required string value = 2;
    348   //   }
    349   //   message Config {
    350   //     repeated Item items = 1 [experimental_map_key="name"];
    351   //   }
    352   // In this situation, the map key for Item will be set to "name".
    353   // TODO: Fully-implement this, then remove the "experimental_" prefix.
    354   optional string experimental_map_key = 9;
    355 
    356   // The parser stores options it doesn't recognize here. See above.
    357   repeated UninterpretedOption uninterpreted_option = 999;
    358 
    359   // Clients can define custom options in extensions of this message. See above.
    360   extensions 1000 to max;
    361 }
    362 
    363 message EnumOptions {
    364 
    365   // The parser stores options it doesn't recognize here. See above.
    366   repeated UninterpretedOption uninterpreted_option = 999;
    367 
    368   // Clients can define custom options in extensions of this message. See above.
    369   extensions 1000 to max;
    370 }
    371 
    372 message EnumValueOptions {
    373   // The parser stores options it doesn't recognize here. See above.
    374   repeated UninterpretedOption uninterpreted_option = 999;
    375 
    376   // Clients can define custom options in extensions of this message. See above.
    377   extensions 1000 to max;
    378 }
    379 
    380 message ServiceOptions {
    381 
    382   // Note:  Field numbers 1 through 32 are reserved for Google's internal RPC
    383   //   framework.  We apologize for hoarding these numbers to ourselves, but
    384   //   we were already using them long before we decided to release Protocol
    385   //   Buffers.
    386 
    387   // The parser stores options it doesn't recognize here. See above.
    388   repeated UninterpretedOption uninterpreted_option = 999;
    389 
    390   // Clients can define custom options in extensions of this message. See above.
    391   extensions 1000 to max;
    392 }
    393 
    394 message MethodOptions {
    395 
    396   // Note:  Field numbers 1 through 32 are reserved for Google's internal RPC
    397   //   framework.  We apologize for hoarding these numbers to ourselves, but
    398   //   we were already using them long before we decided to release Protocol
    399   //   Buffers.
    400 
    401   // The parser stores options it doesn't recognize here. See above.
    402   repeated UninterpretedOption uninterpreted_option = 999;
    403 
    404   // Clients can define custom options in extensions of this message. See above.
    405   extensions 1000 to max;
    406 }
    407 
    408 // A message representing a option the parser does not recognize. This only
    409 // appears in options protos created by the compiler::Parser class.
    410 // DescriptorPool resolves these when building Descriptor objects. Therefore,
    411 // options protos in descriptor objects (e.g. returned by Descriptor::options(),
    412 // or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
    413 // in them.
    414 message UninterpretedOption {
    415   // The name of the uninterpreted option.  Each string represents a segment in
    416   // a dot-separated name.  is_extension is true iff a segment represents an
    417   // extension (denoted with parentheses in options specs in .proto files).
    418   // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
    419   // "foo.(bar.baz).qux".
    420   message NamePart {
    421     required string name_part = 1;
    422     required bool is_extension = 2;
    423   }
    424   repeated NamePart name = 2;
    425 
    426   // The value of the uninterpreted option, in whatever type the tokenizer
    427   // identified it as during parsing. Exactly one of these should be set.
    428   optional string identifier_value = 3;
    429   optional uint64 positive_int_value = 4;
    430   optional int64 negative_int_value = 5;
    431   optional double double_value = 6;
    432   optional bytes string_value = 7;
    433 }
    434