Package com.google.protobuf
Class Descriptors.Descriptor
java.lang.Object
com.google.protobuf.Descriptors.GenericDescriptor
com.google.protobuf.Descriptors.Descriptor
- Enclosing class:
Descriptors
Describes a message type.
-
Method Summary
Modifier and TypeMethodDescriptionfindEnumTypeByName
(String name) Finds a nested enum type by name.findFieldByName
(String name) Finds a field by name.findFieldByNumber
(int number) Finds a field by field number.findNestedTypeByName
(String name) Finds a nested message type by name.If this is a nested type, get the outer descriptor, otherwise null.Get a list of enum types nested within this one.Get a list of this message type's extensions.Get a list of this message type's fields.getFile()
Get theDescriptors.FileDescriptor
containing this descriptor.Get the type's fully-qualified name, within the proto language's namespace.int
getIndex()
Get the index of this descriptor within its parent.getName()
Get the type's unqualified name.Get a list of message types nested within this one.Get a list of this message type's oneofs.Get theMessageOptions
, defined indescriptor.proto
.Get a list of this message type's real oneofs.boolean
Indicates whether the message can be extended.boolean
isExtensionNumber
(int number) Determines if the given field number is an extension.boolean
isReservedName
(String name) Determines if the given field name is reserved.boolean
isReservedNumber
(int number) Determines if the given field number is reserved.toProto()
Convert the descriptor to its protocol message representation.
-
Method Details
-
getIndex
public int getIndex()Get the index of this descriptor within its parent. In other words, given aDescriptors.FileDescriptor
file
, the following is true:for all i in [0, file.getMessageTypeCount()): file.getMessageType(i).getIndex() == i
Similarly, for aDescriptors.Descriptor
messageType
:for all i in [0, messageType.getNestedTypeCount()): messageType.getNestedType(i).getIndex() == i
-
toProto
Convert the descriptor to its protocol message representation.- Specified by:
toProto
in classDescriptors.GenericDescriptor
-
getName
Get the type's unqualified name.- Specified by:
getName
in classDescriptors.GenericDescriptor
-
getFullName
Get the type's fully-qualified name, within the proto language's namespace. This differs from the Java name. For example, given this.proto
:package foo.bar; option java_package = "com.example.protos" message Baz {}
Baz
's full name is "foo.bar.Baz".- Specified by:
getFullName
in classDescriptors.GenericDescriptor
-
getFile
Get theDescriptors.FileDescriptor
containing this descriptor.- Specified by:
getFile
in classDescriptors.GenericDescriptor
-
getContainingType
If this is a nested type, get the outer descriptor, otherwise null. -
getOptions
Get theMessageOptions
, defined indescriptor.proto
. -
getFields
Get a list of this message type's fields. -
getOneofs
Get a list of this message type's oneofs. -
getRealOneofs
Get a list of this message type's real oneofs. -
getExtensions
Get a list of this message type's extensions. -
getNestedTypes
Get a list of message types nested within this one. -
getEnumTypes
Get a list of enum types nested within this one. -
isExtensionNumber
public boolean isExtensionNumber(int number) Determines if the given field number is an extension. -
isReservedNumber
public boolean isReservedNumber(int number) Determines if the given field number is reserved. -
isReservedName
Determines if the given field name is reserved. -
isExtendable
public boolean isExtendable()Indicates whether the message can be extended. That is, whether it has any "extensions x to y" ranges declared on it. -
findFieldByName
Finds a field by name.- Parameters:
name
- The unqualified name of the field (e.g. "foo"). For protocol buffer messages that follow Google's guidance on naming this will be a snake case string, such assong_name
.- Returns:
- The field's descriptor, or
null
if not found.
-
findFieldByNumber
Finds a field by field number.- Parameters:
number
- The field number within this message type.- Returns:
- The field's descriptor, or
null
if not found.
-
findNestedTypeByName
Finds a nested message type by name.- Parameters:
name
- The unqualified name of the nested type such as "Foo"- Returns:
- The types's descriptor, or
null
if not found.
-
findEnumTypeByName
Finds a nested enum type by name.- Parameters:
name
- The unqualified name of the nested type such as "Foo"- Returns:
- The types's descriptor, or
null
if not found.
-