Class Descriptors.FieldDescriptor

public static final class Descriptors.FieldDescriptor extends Descriptors.GenericDescriptor implements Comparable<Descriptors.FieldDescriptor>, FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>

Describes a field of a message type.

Inheritance

Object > Descriptors.GenericDescriptor > Descriptors.FieldDescriptor

Implements

Comparable<Descriptors.FieldDescriptor>, com.google.protobuf.FieldSet.FieldDescriptorLite<com.google.protobuf.Descriptors.FieldDescriptor>

Methods

compareTo(Descriptors.FieldDescriptor other)

public int compareTo(Descriptors.FieldDescriptor other)

Compare with another FieldDescriptor. 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 same Descriptor for both fields.

Parameter
NameDescription
otherDescriptors.FieldDescriptor
Returns
TypeDescription
int

negative, zero, or positive if this is less than, equal to, or greater than other, respectively.

getContainingOneof()

public Descriptors.OneofDescriptor getContainingOneof()

Get the field's containing oneof.

Returns
TypeDescription
Descriptors.OneofDescriptor

getContainingType()

public Descriptors.Descriptor getContainingType()

Get the field's containing type. For extensions, this is the type being extended, not the location where the extension was defined. See #getExtensionScope().

Returns
TypeDescription
Descriptors.Descriptor

getDefaultValue()

public Object 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).

Returns
TypeDescription
Object

getEnumType()

public Descriptors.EnumDescriptor getEnumType()

For enum fields, gets the field's type.

Returns
TypeDescription
Descriptors.EnumDescriptor

getExtensionScope()

public Descriptors.Descriptor 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; } }

Both baz's and qux's containing type is Foo. However, baz's extension scope is null while qux's extension scope is Bar.

Returns
TypeDescription
Descriptors.Descriptor

getFile()

public Descriptors.FileDescriptor getFile()

Get the FileDescriptor containing this descriptor.

Returns
TypeDescription
Descriptors.FileDescriptor
Overrides

getFullName()

public String getFullName()

Get the field's fully-qualified name. See Also: Descriptors.Descriptor#getFullName()

Returns
TypeDescription
String
Overrides

getIndex()

public int getIndex()

Get the index of this descriptor within its parent. See Also: Descriptors.Descriptor#getIndex()

Returns
TypeDescription
int

getJavaType()

public Descriptors.FieldDescriptor.JavaType getJavaType()

Get the field's java type. This is just for convenience. Every FieldDescriptorProto.Type maps to exactly one Java type.

Returns
TypeDescription
Descriptors.FieldDescriptor.JavaType

getJsonName()

public String getJsonName()

Get the JSON name of this field.

Returns
TypeDescription
String

getLiteJavaType()

public WireFormat.JavaType getLiteJavaType()

For internal use only.

Returns
TypeDescription
WireFormat.JavaType

getLiteType()

public WireFormat.FieldType getLiteType()

For internal use only.

Returns
TypeDescription
WireFormat.FieldType

getMessageType()

public Descriptors.Descriptor getMessageType()

For embedded message and group fields, gets the field's type.

Returns
TypeDescription
Descriptors.Descriptor

getName()

public String getName()

Get the field's unqualified name.

Returns
TypeDescription
String
Overrides

getNumber()

public int getNumber()

Get the field's number.

Returns
TypeDescription
int

getOptions()

public DescriptorProtos.FieldOptions getOptions()

Get the FieldOptions, defined in descriptor.proto.

Returns
TypeDescription
DescriptorProtos.FieldOptions

getRealContainingOneof()

public Descriptors.OneofDescriptor getRealContainingOneof()

Get the field's containing oneof, only if non-synthetic.

Returns
TypeDescription
Descriptors.OneofDescriptor

getType()

public Descriptors.FieldDescriptor.Type getType()

Get the field's declared type.

Returns
TypeDescription
Descriptors.FieldDescriptor.Type

hasDefaultValue()

public boolean hasDefaultValue()

Returns true if the field had an explicitly-defined default value.

Returns
TypeDescription
boolean

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.

Returns
TypeDescription
boolean

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.

Returns
TypeDescription
boolean

internalMergeFrom(MessageLite.Builder to, MessageLite from)

public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from)

For internal use only. This is to satisfy the FieldDescriptorLite interface.

Parameters
NameDescription
toMessageLite.Builder
fromMessageLite
Returns
TypeDescription
MessageLite.Builder

isExtension()

public boolean isExtension()

Is this field an extension?

Returns
TypeDescription
boolean

isMapField()

public boolean isMapField()
Returns
TypeDescription
boolean

isOptional()

public boolean isOptional()

Is this field declared optional?

Returns
TypeDescription
boolean

isPackable()

public boolean isPackable()

Can this field be packed? i.e. is it a repeated primitive field?

Returns
TypeDescription
boolean

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?

Returns
TypeDescription
boolean

isRepeated()

public boolean isRepeated()

Is this field declared repeated?

Returns
TypeDescription
boolean

isRequired()

public boolean isRequired()

Is this field declared required?

Returns
TypeDescription
boolean

needsUtf8Check()

public boolean needsUtf8Check()

For internal use only.

Returns
TypeDescription
boolean

toProto()

public DescriptorProtos.FieldDescriptorProto toProto()

Convert the descriptor to its protocol message representation.

Returns
TypeDescription
DescriptorProtos.FieldDescriptorProto
Overrides

toString()

public String toString()
Returns
TypeDescription
String
Overrides