Package com.google.protobuf
Class FieldInfo
- java.lang.Object
-
- com.google.protobuf.FieldInfo
-
- All Implemented Interfaces:
java.lang.Comparable<FieldInfo>
@CheckReturnValue @ExperimentalApi final class FieldInfo extends java.lang.Object implements java.lang.Comparable<FieldInfo>
Information for a single field in a protobuf message class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FieldInfo.Builder
A builder forFieldInfo
instances.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.Field
cachedSizeField
private boolean
enforceUtf8
private Internal.EnumVerifier
enumVerifier
private java.lang.reflect.Field
field
private int
fieldNumber
private java.lang.Object
mapDefaultEntry
private java.lang.Class<?>
messageClass
private OneofInfo
oneof
private java.lang.Class<?>
oneofStoredType
The actual type stored in the oneof value for this field.private java.lang.reflect.Field
presenceField
private int
presenceMask
private boolean
required
private FieldType
type
-
Constructor Summary
Constructors Modifier Constructor Description private
FieldInfo(java.lang.reflect.Field field, int fieldNumber, FieldType type, java.lang.Class<?> messageClass, java.lang.reflect.Field presenceField, int presenceMask, boolean required, boolean enforceUtf8, OneofInfo oneof, java.lang.Class<?> oneofStoredType, java.lang.Object mapDefaultEntry, Internal.EnumVerifier enumVerifier, java.lang.reflect.Field cachedSizeField)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkFieldNumber(int fieldNumber)
int
compareTo(FieldInfo o)
static FieldInfo
forField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, boolean enforceUtf8)
Constructs a new descriptor for a field.static FieldInfo
forFieldWithEnumVerifier(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier)
static FieldInfo
forMapField(java.lang.reflect.Field field, int fieldNumber, java.lang.Object mapDefaultEntry, Internal.EnumVerifier enumVerifier)
static FieldInfo
forOneofMemberField(int fieldNumber, FieldType fieldType, OneofInfo oneof, java.lang.Class<?> oneofStoredType, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)
Constructor for a field that is part of a oneof.static FieldInfo
forPackedField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field cachedSizeField)
Constructs a new descriptor for a packed field.static FieldInfo
forPackedFieldWithEnumVerifier(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier, java.lang.reflect.Field cachedSizeField)
static FieldInfo
forProto2OptionalField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)
Constructor for a proto2 optional field.static FieldInfo
forProto2RequiredField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)
Constructor for a proto2 required field.static FieldInfo
forRepeatedMessageField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.Class<?> messageClass)
Constructs a new descriptor for a repeated message field.java.lang.reflect.Field
getCachedSizeField()
Internal.EnumVerifier
getEnumVerifier()
Gets theEnumVerifier
if the field is an enum field.java.lang.reflect.Field
getField()
Gets the subjectField
of this descriptor.int
getFieldNumber()
Gets the field number for the field.java.lang.Class<?>
getListElementType()
For repeated message fields, returns the message type of the field.java.lang.Object
getMapDefaultEntry()
java.lang.Class<?>
getMessageFieldClass()
For singular or repeated message fields, returns the message type.OneofInfo
getOneof()
Gets the oneof for which this field is a member, ornull
if not part of a oneof.java.lang.Class<?>
getOneofStoredType()
Gets the actual type stored in the oneof value by this field.java.lang.reflect.Field
getPresenceField()
Gets the presence bit field.int
getPresenceMask()
IfgetPresenceField()
is non-null
, returns the mask used to identify the presence bit for this field in the message.FieldType
getType()
Gets the type information for the field.boolean
isEnforceUtf8()
Whether a UTF-8 should be enforced on string fields.private static boolean
isExactlyOneBitSet(int value)
boolean
isRequired()
Whether this is a required field.static FieldInfo.Builder
newBuilder()
-
-
-
Field Detail
-
field
private final java.lang.reflect.Field field
-
type
private final FieldType type
-
messageClass
private final java.lang.Class<?> messageClass
-
fieldNumber
private final int fieldNumber
-
presenceField
private final java.lang.reflect.Field presenceField
-
presenceMask
private final int presenceMask
-
required
private final boolean required
-
enforceUtf8
private final boolean enforceUtf8
-
oneof
private final OneofInfo oneof
-
cachedSizeField
private final java.lang.reflect.Field cachedSizeField
-
oneofStoredType
private final java.lang.Class<?> oneofStoredType
The actual type stored in the oneof value for this field. Since the oneof value is anObject
, primitives will store their boxed type. Only valid in conjunction withoneof
(both must be either null or non-null.
-
mapDefaultEntry
private final java.lang.Object mapDefaultEntry
-
enumVerifier
private final Internal.EnumVerifier enumVerifier
-
-
Constructor Detail
-
FieldInfo
private FieldInfo(java.lang.reflect.Field field, int fieldNumber, FieldType type, java.lang.Class<?> messageClass, java.lang.reflect.Field presenceField, int presenceMask, boolean required, boolean enforceUtf8, OneofInfo oneof, java.lang.Class<?> oneofStoredType, java.lang.Object mapDefaultEntry, Internal.EnumVerifier enumVerifier, java.lang.reflect.Field cachedSizeField)
-
-
Method Detail
-
forField
public static FieldInfo forField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, boolean enforceUtf8)
Constructs a new descriptor for a field.
-
forPackedField
public static FieldInfo forPackedField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field cachedSizeField)
Constructs a new descriptor for a packed field.
-
forRepeatedMessageField
public static FieldInfo forRepeatedMessageField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.Class<?> messageClass)
Constructs a new descriptor for a repeated message field.
-
forFieldWithEnumVerifier
public static FieldInfo forFieldWithEnumVerifier(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier)
-
forPackedFieldWithEnumVerifier
public static FieldInfo forPackedFieldWithEnumVerifier(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier, java.lang.reflect.Field cachedSizeField)
-
forProto2OptionalField
public static FieldInfo forProto2OptionalField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)
Constructor for a proto2 optional field.
-
forOneofMemberField
public static FieldInfo forOneofMemberField(int fieldNumber, FieldType fieldType, OneofInfo oneof, java.lang.Class<?> oneofStoredType, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)
Constructor for a field that is part of a oneof.- Parameters:
fieldNumber
- the unique field number for this field within the message.fieldType
- the type of the field (must be non-null).oneof
- the oneof for which this field is associated (must be non-null).oneofStoredType
- the actual type stored in the oneof value for this field. Since the oneof value is anObject
, primitives will store their boxed type. Must be non-null.enforceUtf8
- Only used for string fields. Iftrue
, will enforce UTF-8 on a string field.- Returns:
- the
FieldInfo
describing this field.
-
checkFieldNumber
private static void checkFieldNumber(int fieldNumber)
-
forProto2RequiredField
public static FieldInfo forProto2RequiredField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)
Constructor for a proto2 required field.
-
forMapField
public static FieldInfo forMapField(java.lang.reflect.Field field, int fieldNumber, java.lang.Object mapDefaultEntry, Internal.EnumVerifier enumVerifier)
-
getFieldNumber
public int getFieldNumber()
Gets the field number for the field.
-
getField
public java.lang.reflect.Field getField()
Gets the subjectField
of this descriptor.
-
getType
public FieldType getType()
Gets the type information for the field.
-
getOneof
public OneofInfo getOneof()
Gets the oneof for which this field is a member, ornull
if not part of a oneof.
-
getOneofStoredType
public java.lang.Class<?> getOneofStoredType()
Gets the actual type stored in the oneof value by this field. Since the oneof value is anObject
, primitives will store their boxed type. For non-oneof fields, this will always benull
.
-
getEnumVerifier
public Internal.EnumVerifier getEnumVerifier()
Gets theEnumVerifier
if the field is an enum field.
-
compareTo
public int compareTo(FieldInfo o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<FieldInfo>
-
getListElementType
public java.lang.Class<?> getListElementType()
For repeated message fields, returns the message type of the field. For other fields, returnsnull
.
-
getPresenceField
public java.lang.reflect.Field getPresenceField()
Gets the presence bit field. Only valid for unary fields. For lists, returnsnull
.
-
getMapDefaultEntry
public java.lang.Object getMapDefaultEntry()
-
getPresenceMask
public int getPresenceMask()
IfgetPresenceField()
is non-null
, returns the mask used to identify the presence bit for this field in the message.
-
isRequired
public boolean isRequired()
Whether this is a required field.
-
isEnforceUtf8
public boolean isEnforceUtf8()
Whether a UTF-8 should be enforced on string fields. Only applies to strings and string lists.
-
getCachedSizeField
public java.lang.reflect.Field getCachedSizeField()
-
getMessageFieldClass
public java.lang.Class<?> getMessageFieldClass()
For singular or repeated message fields, returns the message type. For other fields, returnsnull
.
-
newBuilder
public static FieldInfo.Builder newBuilder()
-
isExactlyOneBitSet
private static boolean isExactlyOneBitSet(int value)
-
-