#include <google/protobuf/descriptor.h>
namespace google::protobuf
This file contains classes which describe a type of protocol message.
You can use a message's descriptor to learn at runtime what fields it contains and what the types of those fields are. The Message interface also allows you to dynamically access and modify individual fields by passing the FieldDescriptor of the field you are interested in.
Most users will not care about descriptors, because they will write code specific to certain protocol types and will simply use the classes generated by the protocol compiler directly. Advanced users who want to operate on arbitrary types (not known at compile time) may want to read descriptors in order to learn about the contents of a message. A very small number of users will want to construct their own Descriptors, either because they are implementing Message manually or because they are writing something like the protocol compiler.
For an example of how you might use descriptors, see the code example at the top of message.h.
Classes in this file | |
|---|---|
Describes a type of protocol message, or a particular group within a message. | |
A range of field numbers which are designated for third-party extensions. | |
Describes a single field of a message. | |
Describes an enum type defined in a .proto file. | |
Describes an individual enum constant of a particular type. | |
Describes an RPC service. | |
Describes an individual service method. | |
Describes a whole .proto file. | |
Used to construct descriptors. | |
When converting a FileDescriptorProto to a FileDescriptor, various errors might be detected in the input. | |
#include <google/protobuf/descriptor.h>
namespace google::protobuf
Describes a type of protocol message, or a particular group within a message.
To obtain the Descriptor for a given message object, call Message::GetDescriptor(). Generated message classes also have a static method called descriptor() which returns the type's descriptor. Use DescriptorPool to construct your own descriptors.
Members | |
|---|---|
const string & | name() constThe name of the message type, not including its scope. |
const string & | full_name() constThe fully-qualified name of the message type, scope delimited by periods. more... |
int | index() constIndex of this descriptor within the file or containing type's message type array. |
const FileDescriptor * | file() constThe .proto file in which this message type was defined. Never NULL. |
const Descriptor * | containing_type() constIf this Descriptor describes a nested type, this returns the type in which it is nested. more... |
const MessageOptions & | options() constGet options for this message type. more... |
void | CopyTo(DescriptorProto * proto) constWrite the contents of this Descriptor into the given DescriptorProto. more... |
string | DebugString() constWrite the contents of this decriptor in a human-readable form. more... |
Field stuff | |
int | field_count() constThe number of fields in this message type. |
const FieldDescriptor * | field(int index) constGets a field by index, where 0 <= index < field_count(). more... |
const FieldDescriptor * | FindFieldByNumber(int number) constLooks up a field by declared tag number. more... |
const FieldDescriptor * | FindFieldByName(const string & name) constLooks up a field by name. Returns NULL if no such field exists. |
const FieldDescriptor * | FindFieldByLowercaseName(const string & lowercase_name) constLooks up a field by lowercased name (as returned by lowercase_name()). more... |
const FieldDescriptor * | FindFieldByCamelcaseName(const string & camelcase_name) constLooks up a field by camel-case name (as returned by camelcase_name()). more... |
Nested type stuff | |
int | nested_type_count() constThe number of nested types in this message type. |
const Descriptor * | nested_type(int index) constGets a nested type by index, where 0 <= index < nested_type_count(). more... |
const Descriptor * | FindNestedTypeByName(const string & name) constLooks up a nested type by name. more... |
Enum stuff | |
int | enum_type_count() constThe number of enum types in this message type. |
const EnumDescriptor * | enum_type(int index) constGets an enum type by index, where 0 <= index < enum_type_count(). more... |
const EnumDescriptor * | FindEnumTypeByName(const string & name) constLooks up an enum type by name. Returns NULL if no such enum type exists. |
const EnumValueDescriptor * | FindEnumValueByName(const string & name) constLooks up an enum value by name, among all enum types in this message. more... |
Extensions | |
int | extension_range_count() constThe number of extension ranges in this message type. |
const ExtensionRange * | extension_range(int index) constGets an extension range by index, where 0 <= index < extension_range_count(). more... |
bool | IsExtensionNumber(int number) constReturns true if the number is in one of the extension ranges. |
int | extension_count() constThe number of extensions -- extending *other* messages -- that were defined nested within this message type's scope. |
const FieldDescriptor * | extension(int index) constGet an extension by index, where 0 <= index < extension_count(). more... |
const FieldDescriptor * | FindExtensionByName(const string & name) constLooks up a named extension (which extends some *other* message type) defined within this message type's scope. |
const FieldDescriptor * | FindExtensionByLowercaseName(const string & name) constSimilar to FindFieldByLowercaseName(), but finds extensions defined within this message type's scope. |
const FieldDescriptor * | FindExtensionByCamelcaseName(const string & name) constSimilar to FindFieldByCamelcaseName(), but finds extensions defined within this message type's scope. |
const string & Descriptor::full_name() constThe fully-qualified name of the message type, scope delimited by periods.
For example, message type "Foo" which is declared in package "bar" has full name "bar.Foo". If a type "Baz" is nested within Foo, Baz's full_name is "bar.Foo.Baz". To get only the part that comes after the last '.', use name().
const Descriptor *
Descriptor::containing_type() constIf this Descriptor describes a nested type, this returns the type in which it is nested.
Otherwise, returns NULL.
const MessageOptions &
Descriptor::options() constGet options for this message type.
These are specified in the .proto file by placing lines like "option foo = 1234;" in the message definition. Allowed options are defined by MessageOptions in google/protobuf/descriptor.proto, and any available extensions of that message.
void Descriptor::CopyTo(
DescriptorProto * proto) constWrite the contents of this Descriptor into the given DescriptorProto.
The target DescriptorProto must be clear before calling this; if it isn't, the result may be garbage.
string Descriptor::DebugString() constWrite the contents of this decriptor in a human-readable form.
Output will be suitable for re-parsing.
const FieldDescriptor *
Descriptor::field(
int index) constGets a field by index, where 0 <= index < field_count().
These are returned in the order they were defined in the .proto file.
const FieldDescriptor *
Descriptor::FindFieldByNumber(
int number) constLooks up a field by declared tag number.
Returns NULL if no such field exists.
const FieldDescriptor *
Descriptor::FindFieldByLowercaseName(
const string & lowercase_name) constLooks up a field by lowercased name (as returned by lowercase_name()).
This lookup may be ambiguous if multiple field names differ only by case, in which case the field returned is chosen arbitrarily from the matches.
const FieldDescriptor *
Descriptor::FindFieldByCamelcaseName(
const string & camelcase_name) constLooks up a field by camel-case name (as returned by camelcase_name()).
This lookup may be ambiguous if multiple field names differ in a way that leads them to have identical camel-case names, in which case the field returned is chosen arbitrarily from the matches.
const Descriptor *
Descriptor::nested_type(
int index) constGets a nested type by index, where 0 <= index < nested_type_count().
These are returned in the order they were defined in the .proto file.
const Descriptor *
Descriptor::FindNestedTypeByName(
const string & name) constLooks up a nested type by name.
Returns NULL if no such nested type exists.
const EnumDescriptor *
Descriptor::enum_type(
int index) constGets an enum type by index, where 0 <= index < enum_type_count().
These are returned in the order they were defined in the .proto file.
const EnumValueDescriptor *
Descriptor::FindEnumValueByName(
const string & name) constLooks up an enum value by name, among all enum types in this message.
Returns NULL if no such value exists.
const ExtensionRange *
Descriptor::extension_range(
int index) constGets an extension range by index, where 0 <= index < extension_range_count().
These are returned in the order they were defined in the .proto file.
const FieldDescriptor *
Descriptor::extension(
int index) constGet an extension by index, where 0 <= index < extension_count().
These are returned in the order they were defined in the .proto file.
#include <google/protobuf/descriptor.h>
namespace google::protobuf
A range of field numbers which are designated for third-party extensions.
Members | |
|---|---|
int | startinclusive |
int | endexclusive |
#include <google/protobuf/descriptor.h>
namespace google::protobuf
Describes a single field of a message.
To get the descriptor for a given field, first get the Descriptor for the message in which it is defined, then call Descriptor::FindFieldByName(). To get a FieldDescriptor for an extension, do one of the following:
Members | |
|---|---|
enum | TypeIdentifies a field type. more... |
enum | CppTypeSpecifies the C++ data type used to represent the field. more... |
enum | LabelIdentifies whether the field is optional, required, or repeated. more... |
const int | kMaxNumber = (1 << 29) - 1Valid field numbers are positive integers up to kMaxNumber. |
const int | kFirstReservedNumber = 19000First field number reserved for the protocol buffer library implementation. more... |
const int | kLastReservedNumber = 19999Last field number reserved for the protocol buffer library implementation. more... |
int32 | default_value_int32_ |
int64 | default_value_int64_ |
uint32 | default_value_uint32_ |
uint64 | default_value_uint64_ |
float | default_value_float_ |
double | default_value_double_ |
bool | default_value_bool_ |
const EnumValueDescriptor * | default_value_enum_ |
const string * | default_value_string_ |
const string & | name() constName of this field within the message. |
const string & | full_name() constFully-qualified name of the field. |
const FileDescriptor * | file() constFile in which this field was defined. |
bool | is_extension() constIs this an extension field? |
int | number() constDeclared tag number. |
const string & | lowercase_name() const |
const string & | camelcase_name() const |
Type | type() constDeclared type of this field. |
CppType | cpp_type() constC++ type of this field. |
Label | label() constoptional/required/repeated |
bool | is_required() constshorthand for label() == LABEL_REQUIRED |
bool | is_optional() constshorthand for label() == LABEL_OPTIONAL |
bool | is_repeated() constshorthand for label() == LABEL_REPEATED |
int | index() constIndex of this field within the message's field array, or the file or extension scope's extensions array. |
bool | has_default_value() constDoes this field have an explicitly-declared default value? |
int32 | default_value_int32() constGet the field default value if cpp_type() == CPPTYPE_INT32. more... |
int64 | default_value_int64() constGet the field default value if cpp_type() == CPPTYPE_INT64. more... |
uint32 | default_value_uint32() constGet the field default value if cpp_type() == CPPTYPE_UINT32. more... |
uint64 | default_value_uint64() constGet the field default value if cpp_type() == CPPTYPE_UINT64. more... |
float | default_value_float() constGet the field default value if cpp_type() == CPPTYPE_FLOAT. more... |
double | default_value_double() constGet the field default value if cpp_type() == CPPTYPE_DOUBLE. more... |
bool | default_value_bool() constGet the field default value if cpp_type() == CPPTYPE_BOOL. more... |
const EnumValueDescriptor * | default_value_enum() constGet the field default value if cpp_type() == CPPTYPE_ENUM. more... |
const string & | default_value_string() constGet the field default value if cpp_type() == CPPTYPE_STRING. more... |
const Descriptor * | containing_type() constThe Descriptor for the message of which this is a field. more... |
const Descriptor * | extension_scope() constAn extension may be declared within the scope of another message. more... |
const Descriptor * | message_type() constIf type is TYPE_MESSAGE or TYPE_GROUP, returns a descriptor for the message or the group type. more... |
const EnumDescriptor * | enum_type() constIf type is TYPE_ENUM, returns a descriptor for the enum. more... |
const FieldDescriptor * | experimental_map_key() constEXPERIMENTAL; DO NOT USE. more... |
const FieldOptions & | options() constGet the FieldOptions for this field. more... |
void | CopyTo(FieldDescriptorProto * proto) constSee Descriptor::CopyTo(). |
string | DebugString() const |
static CppType | TypeToCppType(Type type)Helper method to get the CppType for a particular Type. |
enum FieldDescriptor::Type {
TYPE_DOUBLE = 1,
TYPE_FLOAT = 2,
TYPE_INT64 = 3,
TYPE_UINT64 = 4,
TYPE_INT32 = 5,
TYPE_FIXED64 = 6,
TYPE_FIXED32 = 7,
TYPE_BOOL = 8,
TYPE_STRING = 9,
TYPE_GROUP = 10,
TYPE_MESSAGE = 11,
TYPE_BYTES = 12,
TYPE_UINT32 = 13,
TYPE_ENUM = 14,
TYPE_SFIXED32 = 15,
TYPE_SFIXED64 = 16,
TYPE_SINT32 = 17,
TYPE_SINT64 = 18,
MAX_TYPE = 18
}Identifies a field type.
0 is reserved for errors. The order is weird for historical reasons. Types 12 and up are new in proto2.
| TYPE_DOUBLE | double, exactly eight bytes on the wire. |
| TYPE_FLOAT | float, exactly four bytes on the wire. |
| TYPE_INT64 | int64, varint on the wire. Negative numbers take 10 bytes. Use TYPE_SINT64 if negative values are likely. |
| TYPE_UINT64 | uint64, varint on the wire. |
| TYPE_INT32 | int32, varint on the wire. Negative numbers take 10 bytes. Use TYPE_SINT32 if negative values are likely. |
| TYPE_FIXED64 | uint64, exactly eight bytes on the wire. |
| TYPE_FIXED32 | uint32, exactly four bytes on the wire. |
| TYPE_BOOL | bool, varint on the wire. |
| TYPE_STRING | UTF-8 text. |
| TYPE_GROUP | Tag-delimited message. Deprecated. |
| TYPE_MESSAGE | Length-delimited message. |
| TYPE_BYTES | Arbitrary byte array. |
| TYPE_UINT32 | uint32, varint on the wire |
| TYPE_ENUM | Enum, varint on the wire. |
| TYPE_SFIXED32 | int32, exactly four bytes on the wire |
| TYPE_SFIXED64 | int64, exactly eight bytes on the wire |
| TYPE_SINT32 | int32, ZigZag-encoded varint on the wire |
| TYPE_SINT64 | int64, ZigZag-encoded varint on the wire |
| MAX_TYPE | Constant useful for defining lookup tables indexed by Type. |
enum FieldDescriptor::CppType {
CPPTYPE_INT32 = 1,
CPPTYPE_INT64 = 2,
CPPTYPE_UINT32 = 3,
CPPTYPE_UINT64 = 4,
CPPTYPE_DOUBLE = 5,
CPPTYPE_FLOAT = 6,
CPPTYPE_BOOL = 7,
CPPTYPE_ENUM = 8,
CPPTYPE_STRING = 9,
CPPTYPE_MESSAGE = 10,
MAX_CPPTYPE = 10
}Specifies the C++ data type used to represent the field.
There is a fixed mapping from Type to CppType where each Type maps to exactly one CppType. 0 is reserved for errors.
| CPPTYPE_INT32 | TYPE_INT32, TYPE_SINT32, TYPE_SFIXED32. |
| CPPTYPE_INT64 | TYPE_INT64, TYPE_SINT64, TYPE_SFIXED64. |
| CPPTYPE_UINT32 | TYPE_UINT32, TYPE_FIXED32. |
| CPPTYPE_UINT64 | TYPE_UINT64, TYPE_FIXED64. |
| CPPTYPE_DOUBLE | TYPE_DOUBLE. |
| CPPTYPE_FLOAT | TYPE_FLOAT. |
| CPPTYPE_BOOL | TYPE_BOOL. |
| CPPTYPE_ENUM | TYPE_ENUM. |
| CPPTYPE_STRING | TYPE_STRING, TYPE_BYTES. |
| CPPTYPE_MESSAGE | TYPE_MESSAGE, TYPE_GROUP. |
| MAX_CPPTYPE | Constant useful for defining lookup tables indexed by CppType. |
enum FieldDescriptor::Label {
LABEL_OPTIONAL = 1,
LABEL_REQUIRED = 2,
LABEL_REPEATED = 3,
MAX_LABEL = 3
}Identifies whether the field is optional, required, or repeated.
0 is reserved for errors.
| LABEL_OPTIONAL | optional |
| LABEL_REQUIRED | required |
| LABEL_REPEATED | repeated |
| MAX_LABEL | Constant useful for defining lookup tables indexed by Label. |
const intFieldDescriptor::kFirstReservedNumber = 19000First field number reserved for the protocol buffer library implementation.
Users may not declare fields that use reserved numbers.
const intFieldDescriptor::kLastReservedNumber = 19999Last field number reserved for the protocol buffer library implementation.
Users may not declare fields that use reserved numbers.
const string & FieldDescriptor::lowercase_name() constSame as name() except converted to lower-case.
This (and especially the FindFieldByLowercaseName() method) can be useful when parsing formats which prefer to use lowercase naming style. (Although, technically field names should be lowercased anyway according to the protobuf style guide, so this only makes a difference when dealing with old .proto files which do not follow the guide.)
const string & FieldDescriptor::camelcase_name() constSame as name() except converted to camel-case.
In this conversion, any time an underscore appears in the name, it is removed and the next letter is capitalized. Furthermore, the first letter of the name is lower-cased. Examples:
FooBar -> fooBar foo_bar -> fooBar fooBar -> fooBar
This (and especially the FindFieldByCamelcaseName() method) can be useful when parsing formats which prefer to use camel-case naming style.
int32 FieldDescriptor::default_value_int32() constGet the field default value if cpp_type() == CPPTYPE_INT32.
If no explicit default was defined, the default is 0.
int64 FieldDescriptor::default_value_int64() constGet the field default value if cpp_type() == CPPTYPE_INT64.
If no explicit default was defined, the default is 0.
uint32 FieldDescriptor::default_value_uint32() constGet the field default value if cpp_type() == CPPTYPE_UINT32.
If no explicit default was defined, the default is 0.
uint64 FieldDescriptor::default_value_uint64() constGet the field default value if cpp_type() == CPPTYPE_UINT64.
If no explicit default was defined, the default is 0.
float FieldDescriptor::default_value_float() constGet the field default value if cpp_type() == CPPTYPE_FLOAT.
If no explicit default was defined, the default is 0.0.
double FieldDescriptor::default_value_double() constGet the field default value if cpp_type() == CPPTYPE_DOUBLE.
If no explicit default was defined, the default is 0.0.
bool FieldDescriptor::default_value_bool() constGet the field default value if cpp_type() == CPPTYPE_BOOL.
If no explicit default was defined, the default is false.
const EnumValueDescriptor *
FieldDescriptor::default_value_enum() constGet the field default value if cpp_type() == CPPTYPE_ENUM.
If no explicit default was defined, the default is the first value defined in the enum type (all enum types are required to have at least one value). This never returns NULL.
const string & FieldDescriptor::default_value_string() constGet the field default value if cpp_type() == CPPTYPE_STRING.
If no explicit default was defined, the default is the empty string.
const Descriptor *
FieldDescriptor::containing_type() constThe Descriptor for the message of which this is a field.
For extensions, this is the extended type. Never NULL.
const Descriptor *
FieldDescriptor::extension_scope() constAn extension may be declared within the scope of another message.
If this field is an extension (is_extension() is true), then extension_scope() returns that message, or NULL if the extension was declared at global scope. If this is not an extension, extension_scope() is undefined (may assert-fail).
const Descriptor *
FieldDescriptor::message_type() constIf type is TYPE_MESSAGE or TYPE_GROUP, returns a descriptor for the message or the group type.
Otherwise, undefined.
const EnumDescriptor *
FieldDescriptor::enum_type() constIf type is TYPE_ENUM, returns a descriptor for the enum.
Otherwise, undefined.
const FieldDescriptor *
FieldDescriptor::experimental_map_key() constEXPERIMENTAL; DO NOT USE.
If this field is a map field, experimental_map_key() is the field that is the key for this map. experimental_map_key()->containing_type() is the same as message_type().
const FieldOptions &
FieldDescriptor::options() constGet the FieldOptions for this field.
This includes things listed in square brackets after the field definition. E.g., the field:
optional string text = 1 [ctype=CORD];
has the "ctype" option set. Allowed options are defined by FieldOptions in google/protobuf/descriptor.proto, and any available extensions of that message.
#include <google/protobuf/descriptor.h>
namespace google::protobuf
Describes an enum type defined in a .proto file.
To get the EnumDescriptor for a generated enum type, call TypeName_descriptor(). Use DescriptorPool to construct your own descriptors.
Members | |
|---|---|
const string & | name() constThe name of this enum type in the containing scope. |
const string & | full_name() constThe fully-qualified name of the enum type, scope delimited by periods. |
int | index() constIndex of this enum within the file or containing message's enum array. |
const FileDescriptor * | file() constThe .proto file in which this enum type was defined. Never NULL. |
int | value_count() constThe number of values for this EnumDescriptor. more... |
const EnumValueDescriptor * | value(int index) constGets a value by index, where 0 <= index < value_count(). more... |
const EnumValueDescriptor * | FindValueByName(const string & name) constLooks up a value by name. Returns NULL if no such value exists. |
const EnumValueDescriptor * | FindValueByNumber(int number) constLooks up a value by number. more... |
const Descriptor * | containing_type() constIf this enum type is nested in a message type, this is that message type. more... |
const EnumOptions & | options() constGet options for this enum type. more... |
void | CopyTo(EnumDescriptorProto * proto) constSee Descriptor::CopyTo(). |
string | DebugString() const |
int EnumDescriptor::value_count() constThe number of values for this EnumDescriptor.
Guaranteed to be greater than zero.
const EnumValueDescriptor *
EnumDescriptor::value(
int index) constGets a value by index, where 0 <= index < value_count().
These are returned in the order they were defined in the .proto file.
const EnumValueDescriptor *
EnumDescriptor::FindValueByNumber(
int number) constLooks up a value by number.
Returns NULL if no such value exists. If multiple values have this number, the first one defined is returned.
const Descriptor *
EnumDescriptor::containing_type() constIf this enum type is nested in a message type, this is that message type.
Otherwise, NULL.
const EnumOptions &
EnumDescriptor::options() constGet options for this enum type.
These are specified in the .proto file by placing lines like "option foo = 1234;" in the enum definition. Allowed options are defined by EnumOptions in google/protobuf/descriptor.proto, and any available extensions of that message.
#include <google/protobuf/descriptor.h>
namespace google::protobuf
Describes an individual enum constant of a particular type.
To get the EnumValueDescriptor for a given enum value, first get the EnumDescriptor for its type, then use EnumDescriptor::FindValueByName() or EnumDescriptor::FindValueByNumber(). Use DescriptorPool to construct your own descriptors.
Members | |
|---|---|
const string & | name() constName of this enum constant. |
int | index() constIndex within the enums's Descriptor. |
int | number() constNumeric value of this enum constant. |
const string & | full_name() constThe full_name of an enum value is a sibling symbol of the enum type. more... |
const EnumDescriptor * | type() constThe type of this value. Never NULL. |
const EnumValueOptions & | options() constGet options for this enum value. more... |
void | CopyTo(EnumValueDescriptorProto * proto) constSee Descriptor::CopyTo(). |
string | DebugString() const |
const string & EnumValueDescriptor::full_name() constThe full_name of an enum value is a sibling symbol of the enum type.
e.g. the full name of FieldDescriptorProto::TYPE_INT32 is actually "google.protobuf.FieldDescriptorProto.TYPE_INT32", NOT "google.protobuf.FieldDescriptorProto.Type.TYPE_INT32". This is to conform with C++ scoping rules for enums.
const EnumValueOptions &
EnumValueDescriptor::options() constGet options for this enum value.
These are specified in the .proto file by adding text like "[foo = 1234]" after an enum value definition. Allowed options are defined by EnumValueOptions in google/protobuf/descriptor.proto, and any available extensions of that message.
#include <google/protobuf/descriptor.h>
namespace google::protobuf
Describes an RPC service.
To get the ServiceDescriptor for a service, call Service::GetDescriptor(). Generated service classes also have a static method called descriptor() which returns the type's ServiceDescriptor. Use DescriptorPool to construct your own descriptors.
Members | |
|---|---|
const string & | name() constThe name of the service, not including its containing scope. |
const string & | full_name() constThe fully-qualified name of the service, scope delimited by periods. |
int | index() constIndex of this service within the file's services array. |
const FileDescriptor * | file() constThe .proto file in which this service was defined. Never NULL. |
const ServiceOptions & | options() constGet options for this service type. more... |
int | method_count() constThe number of methods this service defines. |
const MethodDescriptor * | method(int index) const |
const MethodDescriptor * | FindMethodByName(const string & name) constLook up a MethodDescriptor by name. |
void | CopyTo(ServiceDescriptorProto * proto) constSee Descriptor::CopyTo(). |
string | DebugString() const |
const ServiceOptions &
ServiceDescriptor::options() constGet options for this service type.
These are specified in the .proto file by placing lines like "option foo = 1234;" in the service definition. Allowed options are defined by ServiceOptions in google/protobuf/descriptor.proto, and any available extensions of that message.
const MethodDescriptor *
ServiceDescriptor::method(
int index) constGets a MethodDescriptor by index, where 0 <= index < method_count().
These are returned in the order they were defined in the .proto file.
#include <google/protobuf/descriptor.h>
namespace google::protobuf
Describes an individual service method.
To obtain a MethodDescriptor given a service, first get its ServiceDescriptor, then call ServiceDescriptor::FindMethodByName(). Use DescriptorPool to construct your own descriptors.
Members | |
|---|---|
const string & | name() constName of this method, not including containing scope. |
const string & | full_name() constThe fully-qualified name of the method, scope delimited by periods. |
int | index() constIndex within the service's Descriptor. |
const ServiceDescriptor * | service() constGets the service to which this method belongs. Never NULL. |
const Descriptor * | input_type() constGets the type of protocol message which this method accepts as input. |
const Descriptor * | output_type() constGets the type of protocol message which this message produces as output. |
const MethodOptions & | options() constGet options for this method. more... |
void | CopyTo(MethodDescriptorProto * proto) constSee Descriptor::CopyTo(). |
string | DebugString() const |
const MethodOptions &
MethodDescriptor::options() constGet options for this method.
These are specified in the .proto file by placing lines like "option foo = 1234;" in curly-braces after a method declaration. Allowed options are defined by MethodOptions in google/protobuf/descriptor.proto, and any available extensions of that message.
#include <google/protobuf/descriptor.h>
namespace google::protobuf
Describes a whole .proto file.
To get the FileDescriptor for a compiled-in file, get the descriptor for something defined in that file and call descriptor->file(). Use DescriptorPool to construct your own descriptors.
Members | |
|---|---|
const string & | name() constThe filename, relative to the source tree. more... |
const string & | package() constThe package, e.g. "google.protobuf.compiler". |
const DescriptorPool * | pool() const |
int | dependency_count() constThe number of files imported by this one. |
const FileDescriptor * | dependency(int index) constGets an imported file by index, where 0 <= index < dependency_count(). more... |
int | message_type_count() constNumber of top-level message types defined in this file. more... |
const Descriptor * | message_type(int index) constGets a top-level message type, where 0 <= index < message_type_count(). more... |
int | enum_type_count() constNumber of top-level enum types defined in this file. more... |
const EnumDescriptor * | enum_type(int index) constGets a top-level enum type, where 0 <= index < enum_type_count(). more... |
int | service_count() constNumber of services defined in this file. |
const ServiceDescriptor * | service(int index) constGets a service, where 0 <= index < service_count(). more... |
int | extension_count() constNumber of extensions defined at file scope. more... |
const FieldDescriptor * | extension(int index) constGets an extension's descriptor, where 0 <= index < extension_count(). more... |
const FileOptions & | options() constGet options for this file. more... |
const Descriptor * | FindMessageTypeByName(const string & name) constFind a top-level message type by name. Returns NULL if not found. |
const EnumDescriptor * | FindEnumTypeByName(const string & name) constFind a top-level enum type by name. Returns NULL if not found. |
const EnumValueDescriptor * | FindEnumValueByName(const string & name) constFind an enum value defined in any top-level enum by name. more... |
const ServiceDescriptor * | FindServiceByName(const string & name) constFind a service definition by name. Returns NULL if not found. |
const FieldDescriptor * | FindExtensionByName(const string & name) constFind a top-level extension definition by name. Returns NULL if not found. |
const FieldDescriptor * | FindExtensionByLowercaseName(const string & name) constSimilar to FindExtensionByName(), but searches by lowercased-name. more... |
const FieldDescriptor * | FindExtensionByCamelcaseName(const string & name) constSimilar to FindExtensionByName(), but searches by camelcased-name. more... |
void | CopyTo(FileDescriptorProto * proto) constSee Descriptor::CopyTo(). |
string | DebugString() const |
const string & FileDescriptor::name() constThe filename, relative to the source tree.
e.g. "google/protobuf/descriptor.proto"
const DescriptorPool *
FileDescriptor::pool() constThe DescriptorPool in which this FileDescriptor and all its contents were allocated.
Never NULL.
const FileDescriptor *
FileDescriptor::dependency(
int index) constGets an imported file by index, where 0 <= index < dependency_count().
These are returned in the order they were defined in the .proto file.
int FileDescriptor::message_type_count() constNumber of top-level message types defined in this file.
(This does not include nested types.)
const Descriptor *
FileDescriptor::message_type(
int index) constGets a top-level message type, where 0 <= index < message_type_count().
These are returned in the order they were defined in the .proto file.
int FileDescriptor::enum_type_count() constNumber of top-level enum types defined in this file.
(This does not include nested types.)
const EnumDescriptor *
FileDescriptor::enum_type(
int index) constGets a top-level enum type, where 0 <= index < enum_type_count().
These are returned in the order they were defined in the .proto file.
const ServiceDescriptor *
FileDescriptor::service(
int index) constGets a service, where 0 <= index < service_count().
These are returned in the order they were defined in the .proto file.
int FileDescriptor::extension_count() constNumber of extensions defined at file scope.
(This does not include extensions nested within message types.)
const FieldDescriptor *
FileDescriptor::extension(
int index) constGets an extension's descriptor, where 0 <= index < extension_count().
These are returned in the order they were defined in the .proto file.
const FileOptions &
FileDescriptor::options() constGet options for this file.
These are specified in the .proto file by placing lines like "option foo = 1234;" at the top level, outside of any other definitions. Allowed options are defined by FileOptions in google/protobuf/descriptor.proto, and any available extensions of that message.
const EnumValueDescriptor *
FileDescriptor::FindEnumValueByName(
const string & name) constFind an enum value defined in any top-level enum by name.
Returns NULL if not found.
const FieldDescriptor *
FileDescriptor::FindExtensionByLowercaseName(
const string & name) constSimilar to FindExtensionByName(), but searches by lowercased-name.
const FieldDescriptor *
FileDescriptor::FindExtensionByCamelcaseName(
const string & name) constSimilar to FindExtensionByName(), but searches by camelcased-name.
#include <google/protobuf/descriptor.h>
namespace google::protobuf
Used to construct descriptors.
Normally you won't want to build your own descriptors. Message classes constructed by the protocol compiler will provide them for you. However, if you are implementing Message on your own, or if you are writing a program which can operate on totally arbitrary types and needs to load them from some sort of database, you might need to.
Since Descriptors are composed of a whole lot of cross-linked bits of data that would be a pain to put together manually, the DescriptorPool class is provided to make the process easier. It can take a FileDescriptorProto (defined in descriptor.proto), validate it, and convert it to a set of nicely cross-linked Descriptors.
DescriptorPool also helps with memory management. Descriptors are composed of many objects containing static data and pointers to each other. In all likelihood, when it comes time to delete this data, you'll want to delete it all at once. In fact, it is not uncommon to have a whole pool of descriptors all cross-linked with each other which you wish to delete all at once. This class represents such a pool, and handles the memory management for you.
You can also search for descriptors within a DescriptorPool by name, and extensions by number.
Members | |
|---|---|
| DescriptorPool()Create a normal, empty DescriptorPool. |
explicit | DescriptorPool(DescriptorDatabase * fallback_database, ErrorCollector * error_collector = NULL) |
| ~DescriptorPool() |
const FileDescriptor * | FindFileByName(const string & name) constFind a FileDescriptor in the pool by file name. more... |
const FileDescriptor * | FindFileContainingSymbol(const string & symbol_name) constFind the FileDescriptor in the pool which defines the given symbol. more... |
static const DescriptorPool * | generated_pool()Get a pointer to the generated pool. more... |
Looking up descriptorsThese find descriptors by fully-qualified name. These will find both top-level descriptors and nested descriptors. They return NULL if not found. | |
const Descriptor * | FindMessageTypeByName(const string & name) const |
const FieldDescriptor * | FindFieldByName(const string & name) const |
const FieldDescriptor * | FindExtensionByName(const string & name) const |
const EnumDescriptor * | FindEnumTypeByName(const string & name) const |
const EnumValueDescriptor * | FindEnumValueByName(const string & name) const |
const ServiceDescriptor * | FindServiceByName(const string & name) const |
const MethodDescriptor * | FindMethodByName(const string & name) const |
const FieldDescriptor * | FindExtensionByNumber(const Descriptor * extendee, int number) constFinds an extension of the given type by number. more... |
void | FindAllExtensions(const Descriptor * extendee, vector< const FieldDescriptor * > * out) constFinds extensions of extendee. more... |
Building descriptors | |
const FileDescriptor * | BuildFile(const FileDescriptorProto & proto)Convert the FileDescriptorProto to real descriptors and place them in this DescriptorPool. more... |
const FileDescriptor * | BuildFileCollectingErrors(const FileDescriptorProto & proto, ErrorCollector * error_collector)Same as BuildFile() except errors are sent to the given ErrorCollector. |
void | AllowUnknownDependencies()By default, it is an error if a FileDescriptorProto contains references to types or other files that are not found in the DescriptorPool (or its backing DescriptorDatabase, if any). more... |
Internal stuffThese methods MUST NOT be called from outside the proto2 library. These methods may contain hidden pitfalls and may be removed in a future library version. | |
explicit | DescriptorPool(const DescriptorPool * underlay)DEPRECATED: Use of underlays can lead to many subtle gotchas. more... |
void | InternalDontEnforceDependencies()For internal use only: Changes the behavior of BuildFile() such that it allows the file to make reference to message types declared in other files which it did not officially declare as dependencies. |
void | internal_set_underlay(const DescriptorPool * underlay)For internal use only. |
bool | InternalIsFileLoaded(const string & filename) constFor internal (unit test) use only: Returns true if a FileDescriptor has been constructed for the given file, false otherwise. more... |
static void | InternalAddGeneratedFile(const void * encoded_file_descriptor, int size)Called by generated classes at init time to add their descriptors to generated_pool. more... |
static DescriptorPool * | internal_generated_pool()For internal use only: Gets a non-const pointer to the generated pool. more... |
const FileDescriptor *
DescriptorPool::FindFileByName(
const string & name) constFind a FileDescriptor in the pool by file name.
Returns NULL if not found.
const FileDescriptor *
DescriptorPool::FindFileContainingSymbol(
const string & symbol_name) constFind the FileDescriptor in the pool which defines the given symbol.
If any of the Find*ByName() methods below would succeed, then this is equivalent to calling that method and calling the result's file() method. Otherwise this returns NULL.
static const DescriptorPool *
DescriptorPool::generated_pool()Get a pointer to the generated pool.
Generated protocol message classes which are compiled into the binary will allocate their descriptors in this pool. Do not add your own descriptors to this pool.
const FieldDescriptor *
DescriptorPool::FindExtensionByNumber(
const Descriptor * extendee,
int number) constFinds an extension of the given type by number.
The extendee must be a member of this DescriptorPool or one of its underlays.
void DescriptorPool::FindAllExtensions(
const Descriptor * extendee,
vector< const FieldDescriptor * > * out) constFinds extensions of extendee.
The extensions will be appended to out in an undefined order. Only extensions defined directly in this DescriptorPool or one of its underlays are guaranteed to be found: extensions defined in the fallback database might not be found depending on the database implementation.
const FileDescriptor *
DescriptorPool::BuildFile(
const FileDescriptorProto & proto)Convert the FileDescriptorProto to real descriptors and place them in this DescriptorPool.
All dependencies of the file must already be in the pool. Returns the resulting FileDescriptor, or NULL if there were problems with the input (e.g. the message was invalid, or dependencies were missing). Details about the errors are written to GOOGLE_LOG(ERROR).
void DescriptorPool::AllowUnknownDependencies()By default, it is an error if a FileDescriptorProto contains references to types or other files that are not found in the DescriptorPool (or its backing DescriptorDatabase, if any).
If you call AllowUnknownDependencies(), however, then unknown types and files will be replaced by placeholder descriptors. This can allow you to perform some useful operations with a .proto file even if you do not have access to other .proto files on which it depends. However, some heuristics must be used to fill in the gaps in information, and these can lead to descriptors which are inaccurate. For example, the DescriptorPool may be forced to guess whether an unknown type is a message or an enum, as well as what package it resides in. Furthermore, placeholder types will not be discoverable via FindMessageTypeByName() and similar methods, which could confuse some descriptor-based algorithms. Generally, the results of this option should only be relied upon for debugging purposes.
explicit DescriptorPool::DescriptorPool(
const DescriptorPool * underlay)DEPRECATED: Use of underlays can lead to many subtle gotchas.
Instead, try to formulate what you want to do in terms of DescriptorDatabases. This constructor will be removed soon.
Create a DescriptorPool which is overlaid on top of some other pool. If you search for a descriptor in the overlay and it is not found, the underlay will be searched as a backup. If the underlay has its own underlay, that will be searched next, and so on. This also means that files built in the overlay will be cross-linked with the underlay's descriptors if necessary. The underlay remains property of the caller; it must remain valid for the lifetime of the newly-constructed pool.
Example: Say you want to parse a .proto file at runtime in order to use its type with a DynamicMessage. Say this .proto file has dependencies, but you know that all the dependencies will be things that are already compiled into the binary. For ease of use, you'd like to load the types right out of generated_pool() rather than have to parse redundant copies of all these .protos and runtime. But, you don't want to add the parsed types directly into generated_pool(): this is not allowed, and would be bad design anyway. So, instead, you could use generated_pool() as an underlay for a new DescriptorPool in which you add only the new file.
bool DescriptorPool::InternalIsFileLoaded(
const string & filename) constFor internal (unit test) use only: Returns true if a FileDescriptor has been constructed for the given file, false otherwise.
Useful for testing lazy descriptor initialization behavior.
static void DescriptorPool::InternalAddGeneratedFile(
const void * encoded_file_descriptor,
int size)Called by generated classes at init time to add their descriptors to generated_pool.
Do NOT call this in your own code! filename must be a permanent string (e.g. a string literal).
static DescriptorPool * DescriptorPool::internal_generated_pool()For internal use only: Gets a non-const pointer to the generated pool.
This is called at static-initialization time only, so thread-safety is not a concern. If both an underlay and a fallback database are present, the fallback database takes precedence.
#include <google/protobuf/descriptor.h>
namespace google::protobuf
When converting a FileDescriptorProto to a FileDescriptor, various errors might be detected in the input.
The caller may handle these programmatically by implementing an ErrorCollector.
Members | |
|---|---|
enum | ErrorLocationThese constants specify what exact part of the construct is broken. more... |
| ErrorCollector() |
virtual | ~ErrorCollector() |
virtual void | AddError(const string & filename, const string & element_name, const Message * descriptor, ErrorLocation location, const string & message) = 0Reports an error in the FileDescriptorProto. |
enum ErrorCollector::ErrorLocation {
NAME,
NUMBER,
TYPE,
EXTENDEE,
DEFAULT_VALUE,
INPUT_TYPE,
OUTPUT_TYPE,
OPTION_NAME,
OPTION_VALUE,
OTHER
}These constants specify what exact part of the construct is broken.
This is useful e.g. for mapping the error back to an exact location in a .proto file.
| NAME | the symbol name, or the package name for files |
| NUMBER | field or extension range number |
| TYPE | field type |
| EXTENDEE | field extendee |
| DEFAULT_VALUE | field default value |
| INPUT_TYPE | method input type |
| OUTPUT_TYPE | method output type |
| OPTION_NAME | name in assignment |
| OPTION_VALUE | value in option assignment |
| OTHER | some other problem |