public static final class Descriptors.FieldDescriptor extends Descriptors.GenericDescriptor implements Comparable<Descriptors.FieldDescriptor>, FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
Describes a field of a message type.
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 | |
---|---|
Name | Description |
other |
Descriptors.FieldDescriptor |
Returns | |
---|---|
Type | Description |
int |
negative, zero, or positive if |
getContainingOneof()
public Descriptors.OneofDescriptor getContainingOneof()
Get the field's containing oneof.
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
Object |
getEnumType()
public Descriptors.EnumDescriptor getEnumType()
For enum fields, gets the field's type.
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
Descriptors.Descriptor |
getFile()
public Descriptors.FileDescriptor getFile()
Get the FileDescriptor
containing this descriptor.
Returns | |
---|---|
Type | Description |
Descriptors.FileDescriptor |
getFullName()
public String getFullName()
Get the field's fully-qualified name. See Also: Descriptors.Descriptor#getFullName()
Returns | |
---|---|
Type | Description |
String |
getIndex()
public int getIndex()
Get the index of this descriptor within its parent. See Also: Descriptors.Descriptor#getIndex()
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
Descriptors.FieldDescriptor.JavaType |
getJsonName()
public String getJsonName()
Get the JSON name of this field.
Returns | |
---|---|
Type | Description |
String |
getLiteJavaType()
public WireFormat.JavaType getLiteJavaType()
For internal use only.
Returns | |
---|---|
Type | Description |
WireFormat.JavaType |
getLiteType()
public WireFormat.FieldType getLiteType()
For internal use only.
Returns | |
---|---|
Type | Description |
WireFormat.FieldType |
getMessageType()
public Descriptors.Descriptor getMessageType()
For embedded message and group fields, gets the field's type.
Returns | |
---|---|
Type | Description |
Descriptors.Descriptor |
getName()
public String getName()
Get the field's unqualified name.
Returns | |
---|---|
Type | Description |
String |
getNumber()
public int getNumber()
Get the field's number.
Returns | |
---|---|
Type | Description |
int |
getOptions()
public DescriptorProtos.FieldOptions getOptions()
Get the FieldOptions
, defined in descriptor.proto
.
Returns | |
---|---|
Type | Description |
DescriptorProtos.FieldOptions |
getRealContainingOneof()
public Descriptors.OneofDescriptor getRealContainingOneof()
Get the field's containing oneof, only if non-synthetic.
Returns | |
---|---|
Type | Description |
Descriptors.OneofDescriptor |
getType()
public Descriptors.FieldDescriptor.Type getType()
Get the field's declared type.
Returns | |
---|---|
Type | Description |
Descriptors.FieldDescriptor.Type |
hasDefaultValue()
public boolean hasDefaultValue()
Returns true if the field had an explicitly-defined default value.
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
to |
MessageLite.Builder |
from |
MessageLite |
Returns | |
---|---|
Type | Description |
MessageLite.Builder |
isExtension()
public boolean isExtension()
Is this field an extension?
Returns | |
---|---|
Type | Description |
boolean |
isMapField()
public boolean isMapField()
Returns | |
---|---|
Type | Description |
boolean |
isOptional()
public boolean isOptional()
Is this field declared optional?
Returns | |
---|---|
Type | Description |
boolean |
isPackable()
public boolean isPackable()
Can this field be packed? i.e. is it a repeated primitive field?
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
boolean |
isRepeated()
public boolean isRepeated()
Is this field declared repeated?
Returns | |
---|---|
Type | Description |
boolean |
isRequired()
public boolean isRequired()
Is this field declared required?
Returns | |
---|---|
Type | Description |
boolean |
needsUtf8Check()
public boolean needsUtf8Check()
For internal use only.
Returns | |
---|---|
Type | Description |
boolean |
toProto()
public DescriptorProtos.FieldDescriptorProto toProto()
Convert the descriptor to its protocol message representation.
Returns | |
---|---|
Type | Description |
DescriptorProtos.FieldDescriptorProto |
toString()
public String toString()
Returns | |
---|---|
Type | Description |
String |