class FieldDescriptor
Defined at line 758 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
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:
- Get the Descriptor or FileDescriptor for its containing scope, then
call Descriptor::FindExtensionByName() or
FileDescriptor::FindExtensionByName().
- Given a DescriptorPool, call DescriptorPool::FindExtensionByNumber() or
DescriptorPool::FindExtensionByPrintableName().
Use DescriptorPool to construct your own descriptors.
Public Members
static const int kMaxNumber
static const int kFirstReservedNumber
static const int kLastReservedNumber
Public Methods
internal::DescriptorStringView name ()
Name of this field within the message.
Defined at line 2571 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
internal::DescriptorStringView full_name ()
Fully-qualified name of the field.
Defined at line 2571 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
internal::DescriptorStringView json_name ()
JSON name of this field.
Defined at line 2707 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const FileDescriptor * file ()
Defined at line 2572 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool is_extension ()
Defined at line 2574 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
int number ()
Defined at line 2573 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
internal::DescriptorStringView lowercase_name ()
Same 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.)
Defined at line 2699 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
internal::DescriptorStringView camelcase_name ()
Same 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.
Defined at line 2703 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
Type type ()
Defined at line 2734 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const char * type_name ()
Defined at line 2829 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
CppType cpp_type ()
Defined at line 2833 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const char * cpp_type_name ()
Defined at line 2837 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
Label label ()
Defined at line 2730 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
CppStringType cpp_string_type ()
bool is_required ()
bool is_optional ()
Defined at line 2738 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool is_repeated ()
Defined at line 2742 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool is_packable ()
Defined at line 2747 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool is_map ()
Defined at line 2751 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool is_packed ()
Whether or not this field is packable and packed. In proto2, packable
fields must have `packed = true` specified. In proto3, all packable fields
are packed by default unless `packed = false` is specified.
bool has_presence ()
Returns true if this field tracks presence, ie. does the field
distinguish between "unset" and "present with default value."
This includes required, optional, and oneof fields. It excludes maps,
repeated fields, and singular proto3 fields without "optional".
For fields where has_presence() == true, the return value of
Reflection::HasField() is semantically meaningful.
bool requires_utf8_validation ()
Returns true if this TYPE_STRING-typed field requires UTF-8 validation on
parse.
bool legacy_enum_field_treated_as_closed ()
Determines if the given enum field is treated as closed based on legacy
non-conformant behavior.
Conformant behavior determines closedness based on the enum and
can be queried using EnumDescriptor::is_closed().
Some runtimes currently have a quirk where non-closed enums are
treated as closed when used as the type of fields defined in a
`syntax = proto2;` file. This quirk is not present in all runtimes; as of
writing, we know that:
- C++, Java, and C++-based Python share this quirk.
- UPB and UPB-based Python do not.
- PHP and Ruby treat all enums as open regardless of declaration.
Care should be taken when using this function to respect the target
runtime's enum handling quirks.
int index ()
Index of this field within the message's field array, or the file or
extension scope's extensions array.
Defined at line 2767 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool has_default_value ()
Does this field have an explicitly-declared default value?
Defined at line 2577 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool has_json_name ()
Whether the user has specified the json_name field option in the .proto
file.
Defined at line 2578 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
int32_t default_value_int32_t ()
Get the field default value if cpp_type() == CPPTYPE_INT32. If no
explicit default was defined, the default is 0.
Defined at line 2579 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
int64_t default_value_int64_t ()
Get the field default value if cpp_type() == CPPTYPE_INT64. If no
explicit default was defined, the default is 0.
Defined at line 2580 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
uint32_t default_value_uint32_t ()
Get the field default value if cpp_type() == CPPTYPE_UINT32. If no
explicit default was defined, the default is 0.
Defined at line 2581 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
uint64_t default_value_uint64_t ()
Get the field default value if cpp_type() == CPPTYPE_UINT64. If no
explicit default was defined, the default is 0.
Defined at line 2582 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
float default_value_float ()
Get the field default value if cpp_type() == CPPTYPE_FLOAT. If no
explicit default was defined, the default is 0.0.
Defined at line 2583 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
double default_value_double ()
Get the field default value if cpp_type() == CPPTYPE_DOUBLE. If no
explicit default was defined, the default is 0.0.
Defined at line 2584 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool default_value_bool ()
Get the field default value if cpp_type() == CPPTYPE_BOOL. If no
explicit default was defined, the default is false.
Defined at line 2585 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const EnumValueDescriptor * default_value_enum ()
Get 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 nullptr.
internal::DescriptorStringView default_value_string ()
Get the field default value if cpp_type() == CPPTYPE_STRING. If no
explicit default was defined, the default is the empty string.
Defined at line 2586 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const Descriptor * containing_type ()
The Descriptor for the message of which this is a field. For extensions,
this is the extended type. Never nullptr.
Defined at line 2575 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const OneofDescriptor * containing_oneof ()
If the field is a member of a oneof, this is the one, otherwise this is
nullptr.
Defined at line 2711 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const OneofDescriptor * real_containing_oneof ()
If the field is a member of a non-synthetic oneof, returns the descriptor
for the oneof, otherwise returns nullptr.
Defined at line 2755 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
int index_in_oneof ()
If the field is a member of a oneof, returns the index in that oneof.
Defined at line 2720 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const Descriptor * extension_scope ()
An 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 nullptr if the extension was declared at global
scope. If this is not an extension, extension_scope() is undefined (may
assert-fail).
Defined at line 2725 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const Descriptor * message_type ()
If type is TYPE_MESSAGE or TYPE_GROUP, returns a descriptor for the
message or the group type. Otherwise, returns null.
const EnumDescriptor * enum_type ()
If type is TYPE_ENUM, returns a descriptor for the enum. Otherwise,
returns null.
const FieldOptions & options ()
Get 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
descriptor.proto, and any available extensions of that message.
Defined at line 2576 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
void CopyTo (FieldDescriptorProto * proto)
See Descriptor::CopyTo().
std::string DebugString ()
See Descriptor::DebugString().
std::string DebugStringWithOptions (const DebugStringOptions & options)
See Descriptor::DebugStringWithOptions().
void FieldDescriptor (const FieldDescriptor & )
Defined at line 764 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
CppType TypeToCppType (Type type)
Helper method to get the CppType for a particular Type.
Defined at line 2841 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const char * TypeName (Type type)
Helper method to get the name of a Type.
Defined at line 2845 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
const char * CppTypeName (CppType cpp_type)
Helper method to get the name of a CppType.
Defined at line 2849 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
bool IsTypePackable (Type field_type)
Return true iff [packed = true] is valid for fields of this type.
Defined at line 2853 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
internal::DescriptorStringView PrintableNameForExtension ()
Returns full_name() except if the field is a MessageSet extension,
in which case it returns the full_name() of the containing message type
for backwards compatibility with proto1.
A MessageSet extension is defined as an optional message extension
whose containing type has the message_set_wire_format option set.
This should be true of extensions of google.protobuf.bridge.MessageSet;
by convention, such extensions are named "message_set_extension".
The opposite operation (looking up an extension's FieldDescriptor given
its printable name) can be accomplished with
message->file()->pool()->FindExtensionByPrintableName(message, name)
where the extension extends "message".
bool GetSourceLocation (SourceLocation * out_location)
Updates |*out_location| to the source location of the complete
extent of this field declaration. Returns false and leaves
|*out_location| unchanged iff location information was not available.
FieldDescriptor & operator= (const FieldDescriptor & )
Defined at line 765 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
int32_t default_value_int32 ()
Defined at line 941 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
int64_t default_value_int64 ()
Defined at line 945 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
uint32_t default_value_uint32 ()
Defined at line 949 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
uint64_t default_value_uint64 ()
Defined at line 953 of file ../../third_party/protobuf/src/google/protobuf/descriptor.h
Friends
class OneofDescriptor
class Descriptor
class FileDescriptor
class DescriptorBuilder
class InternalFeatureHelper
const std::string & FieldDescriptor (const FieldDescriptor * field)
class FieldDescriptorLegacy
class Reflection
class Formatter
class Printer
class Symbol
template <typename Sink>
void FieldDescriptor (Sink & sinkconst FieldDescriptor & d)