Package com.google.protobuf
Class Descriptors.FieldDescriptor
java.lang.Object
com.google.protobuf.Descriptors.GenericDescriptor
com.google.protobuf.Descriptors.FieldDescriptor
- All Implemented Interfaces:
FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
,Comparable<Descriptors.FieldDescriptor>
- Enclosing class:
Descriptors
public static final class Descriptors.FieldDescriptor
extends Descriptors.GenericDescriptor
implements Comparable<Descriptors.FieldDescriptor>, FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
Describes a field of a message type.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Descriptors.OneofDescriptor
private Descriptors.Descriptor
private Object
private Descriptors.EnumDescriptor
private final Descriptors.Descriptor
private final Descriptors.FileDescriptor
private final String
private final int
private final boolean
private String
private Descriptors.Descriptor
private static final Descriptors.NumberGetter
<Descriptors.FieldDescriptor> private static final WireFormat.FieldType[]
private Descriptors.FieldDescriptor.Type
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
FieldDescriptor
(DescriptorProtos.FieldDescriptorProto proto, Descriptors.FileDescriptor file, Descriptors.Descriptor parent, int index, boolean isExtension) -
Method Summary
Modifier and TypeMethodDescriptionint
Compare with anotherFieldDescriptor
.private void
Look up and cross-link all field types, etc.private static String
fieldNameToJsonName
(String name) Get the field's containing oneof.Get the field's containing type.Returns the field's default value.For enum fields, gets the field's type.For extensions defined nested within message types, gets the outer type.getFile()
Get theFileDescriptor
containing this descriptor.Get the field's fully-qualified name.int
getIndex()
Get the index of this descriptor within its parent.Get the field's java type.Get the JSON name of this field.For internal use only.For internal use only.For embedded message and group fields, gets the field's type.getName()
Get the field's unqualified name.int
Get the field's number.Get theFieldOptions
, defined indescriptor.proto
.Get the field's containing oneof, only if non-synthetic.getType()
Get the field's declared type.boolean
Returns true if the field had an explicitly-defined default value.boolean
Returns true if this field was syntactically written with "optional" in the .proto file.boolean
Returns true if this field tracks presence, ie.internalMergeFrom
(MessageLite.Builder to, MessageLite from) For internal use only.boolean
Is this field an extension?boolean
boolean
Is this field declared optional?boolean
Can this field be packed? i.e.boolean
isPacked()
Does this field have the[packed = true]
option or is this field packable in proto3 and not explicitly set to unpacked?boolean
Is this field declared repeated?boolean
Is this field declared required?boolean
For internal use only.private void
toProto()
Convert the descriptor to its protocol message representation.toString()
-
Field Details
-
NUMBER_GETTER
-
table
-
index
private final int index -
proto
-
fullName
-
jsonName
-
file
-
extensionScope
-
isProto3Optional
private final boolean isProto3Optional -
type
-
containingType
-
messageType
-
containingOneof
-
enumType
-
defaultValue
-
-
Constructor Details
-
FieldDescriptor
private FieldDescriptor(DescriptorProtos.FieldDescriptorProto proto, Descriptors.FileDescriptor file, Descriptors.Descriptor parent, int index, boolean isExtension) throws Descriptors.DescriptorValidationException
-
-
Method Details
-
getIndex
public int getIndex()Get the index of this descriptor within its parent.- See Also:
-
toProto
Convert the descriptor to its protocol message representation.- Specified by:
toProto
in classDescriptors.GenericDescriptor
-
getName
Get the field's unqualified name.- Specified by:
getName
in classDescriptors.GenericDescriptor
-
getNumber
public int getNumber()Get the field's number.- Specified by:
getNumber
in interfaceFieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
-
getFullName
Get the field's fully-qualified name.- Specified by:
getFullName
in classDescriptors.GenericDescriptor
- See Also:
-
getJsonName
Get the JSON name of this field. -
getJavaType
Get the field's java type. This is just for convenience. EveryFieldDescriptorProto.Type
maps to exactly one Java type. -
getLiteJavaType
For internal use only.- Specified by:
getLiteJavaType
in interfaceFieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
-
getFile
Get theFileDescriptor
containing this descriptor.- Specified by:
getFile
in classDescriptors.GenericDescriptor
-
getType
Get the field's declared type. -
getLiteType
For internal use only.- Specified by:
getLiteType
in interfaceFieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
-
needsUtf8Check
public boolean needsUtf8Check()For internal use only. -
isMapField
public boolean isMapField() -
isRequired
public boolean isRequired()Is this field declared required? -
isOptional
public boolean isOptional()Is this field declared optional? -
isRepeated
public boolean isRepeated()Is this field declared repeated?- Specified by:
isRepeated
in interfaceFieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
-
isPacked
public boolean isPacked()Does this field have the[packed = true]
option or is this field packable in proto3 and not explicitly set to unpacked?- Specified by:
isPacked
in interfaceFieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
-
isPackable
public boolean isPackable()Can this field be packed? i.e. is it a repeated primitive field? -
hasDefaultValue
public boolean hasDefaultValue()Returns true if the field had an explicitly-defined default value. -
getDefaultValue
Returns the field's default value. Valid for all types except for messages and groups. For all other types, the object returned is of the same class that would returned by Message.getField(this). -
getOptions
Get theFieldOptions
, defined indescriptor.proto
. -
isExtension
public boolean isExtension()Is this field an extension? -
getContainingType
Get the field's containing type. For extensions, this is the type being extended, not the location where the extension was defined. SeegetExtensionScope()
. -
getContainingOneof
Get the field's containing oneof. -
getRealContainingOneof
Get the field's containing oneof, only if non-synthetic. -
hasOptionalKeyword
public boolean hasOptionalKeyword()Returns true if this field was syntactically written with "optional" in the .proto file. Excludes singular proto3 fields that do not have a label. -
hasPresence
public boolean hasPresence()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 hasPresence() == true, the return value of msg.hasField() is semantically meaningful.
-
getExtensionScope
For extensions defined nested within message types, gets the outer type. Not valid for non-extension fields. For example, consider this.proto
file:message Foo { extensions 1000 to max; } extend Foo { optional int32 baz = 1234; } message Bar { extend Foo { optional int32 qux = 4321; } }
Bothbaz
's andqux
's containing type isFoo
. However,baz
's extension scope isnull
whilequx
's extension scope isBar
. -
getMessageType
For embedded message and group fields, gets the field's type. -
getEnumType
For enum fields, gets the field's type.- Specified by:
getEnumType
in interfaceFieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
-
compareTo
Compare with anotherFieldDescriptor
. This orders fields in "canonical" order, which simply means ascending order by field number.other
must be a field of the same type -- i.e.getContainingType()
must return the sameDescriptor
for both fields.- Specified by:
compareTo
in interfaceComparable<Descriptors.FieldDescriptor>
- Returns:
- negative, zero, or positive if
this
is less than, equal to, or greater thanother
, respectively.
-
toString
-
fieldNameToJsonName
-
crossLink
Look up and cross-link all field types, etc. -
setProto
-
internalMergeFrom
For internal use only. This is to satisfy the FieldDescriptorLite interface.- Specified by:
internalMergeFrom
in interfaceFieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
-