Package com.google.protobuf
Class FieldInfo
java.lang.Object
com.google.protobuf.FieldInfo
- All Implemented Interfaces:
Comparable<FieldInfo>
@CheckReturnValue
@ExperimentalApi
final class FieldInfo
extends Object
implements Comparable<FieldInfo>
Information for a single field in a protobuf message class.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Field
private final boolean
private final Internal.EnumVerifier
private final Field
private final int
private final Object
private final Class
<?> private final OneofInfo
private final Class
<?> The actual type stored in the oneof value for this field.private final Field
private final int
private final boolean
private final FieldType
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
FieldInfo
(Field field, int fieldNumber, FieldType type, Class<?> messageClass, Field presenceField, int presenceMask, boolean required, boolean enforceUtf8, OneofInfo oneof, Class<?> oneofStoredType, Object mapDefaultEntry, Internal.EnumVerifier enumVerifier, Field cachedSizeField) -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
checkFieldNumber
(int fieldNumber) int
static FieldInfo
forExplicitPresenceField
(Field field, int fieldNumber, FieldType fieldType, Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier) Constructor for a field with explicit presence (e.g.static FieldInfo
Constructs a new descriptor for a field.static FieldInfo
forFieldWithEnumVerifier
(Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier) static FieldInfo
forLegacyRequiredField
(Field field, int fieldNumber, FieldType fieldType, Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier) Constructor for a legacy required field.static FieldInfo
forMapField
(Field field, int fieldNumber, Object mapDefaultEntry, Internal.EnumVerifier enumVerifier) static FieldInfo
forOneofMemberField
(int fieldNumber, FieldType fieldType, OneofInfo oneof, Class<?> oneofStoredType, boolean enforceUtf8, Internal.EnumVerifier enumVerifier) Constructor for a field that is part of a oneof.static FieldInfo
forPackedField
(Field field, int fieldNumber, FieldType fieldType, Field cachedSizeField) Constructs a new descriptor for a packed field.static FieldInfo
forPackedFieldWithEnumVerifier
(Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier, Field cachedSizeField) static FieldInfo
forRepeatedMessageField
(Field field, int fieldNumber, FieldType fieldType, Class<?> messageClass) Constructs a new descriptor for a repeated message field.Gets theEnumVerifier
if the field is an enum field.getField()
Gets the subjectField
of this descriptor.int
Gets the field number for the field.Class
<?> For repeated message fields, returns the message type of the field.Class
<?> For singular or repeated message fields, returns the message type.getOneof()
Gets the oneof for which this field is a member, ornull
if not part of a oneof.Class
<?> Gets the actual type stored in the oneof value by this field.Gets the presence bit field.int
IfgetPresenceField()
is non-null
, returns the mask used to identify the presence bit for this field in the message.getType()
Gets the type information for the field.boolean
Whether a UTF-8 should be enforced on string fields.private static boolean
isExactlyOneBitSet
(int value) boolean
Whether this is a required field.static FieldInfo.Builder
-
Field Details
-
field
-
type
-
messageClass
-
fieldNumber
private final int fieldNumber -
presenceField
-
presenceMask
private final int presenceMask -
required
private final boolean required -
enforceUtf8
private final boolean enforceUtf8 -
oneof
-
cachedSizeField
-
oneofStoredType
-
mapDefaultEntry
-
enumVerifier
-
-
Constructor Details
-
FieldInfo
-
-
Method Details
-
forField
public static FieldInfo forField(Field field, int fieldNumber, FieldType fieldType, boolean enforceUtf8) Constructs a new descriptor for a field. -
forPackedField
public static FieldInfo forPackedField(Field field, int fieldNumber, FieldType fieldType, Field cachedSizeField) Constructs a new descriptor for a packed field. -
forRepeatedMessageField
public static FieldInfo forRepeatedMessageField(Field field, int fieldNumber, FieldType fieldType, Class<?> messageClass) Constructs a new descriptor for a repeated message field. -
forFieldWithEnumVerifier
public static FieldInfo forFieldWithEnumVerifier(Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier) -
forPackedFieldWithEnumVerifier
public static FieldInfo forPackedFieldWithEnumVerifier(Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier, Field cachedSizeField) -
forExplicitPresenceField
public static FieldInfo forExplicitPresenceField(Field field, int fieldNumber, FieldType fieldType, Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier) Constructor for a field with explicit presence (e.g. proto2). -
forOneofMemberField
public static FieldInfo forOneofMemberField(int fieldNumber, FieldType fieldType, OneofInfo oneof, 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) -
forLegacyRequiredField
public static FieldInfo forLegacyRequiredField(Field field, int fieldNumber, FieldType fieldType, Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier) Constructor for a legacy required field. -
forMapField
public static FieldInfo forMapField(Field field, int fieldNumber, Object mapDefaultEntry, Internal.EnumVerifier enumVerifier) -
getFieldNumber
public int getFieldNumber()Gets the field number for the field. -
getField
Gets the subjectField
of this descriptor. -
getType
Gets the type information for the field. -
getOneof
Gets the oneof for which this field is a member, ornull
if not part of a oneof. -
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
Gets theEnumVerifier
if the field is an enum field. -
compareTo
- Specified by:
compareTo
in interfaceComparable<FieldInfo>
-
getListElementType
For repeated message fields, returns the message type of the field. For other fields, returnsnull
. -
getPresenceField
Gets the presence bit field. Only valid for unary fields. For lists, returnsnull
. -
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
-
getMessageFieldClass
For singular or repeated message fields, returns the message type. For other fields, returnsnull
. -
newBuilder
-
isExactlyOneBitSet
private static boolean isExactlyOneBitSet(int value)
-