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 classFieldInfo.BuilderA builder forFieldInfoinstances.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.FieldcachedSizeFieldprivate booleanenforceUtf8private Internal.EnumVerifierenumVerifierprivate java.lang.reflect.Fieldfieldprivate intfieldNumberprivate java.lang.ObjectmapDefaultEntryprivate java.lang.Class<?>messageClassprivate OneofInfooneofprivate java.lang.Class<?>oneofStoredTypeThe actual type stored in the oneof value for this field.private java.lang.reflect.FieldpresenceFieldprivate intpresenceMaskprivate booleanrequiredprivate FieldTypetype
-
Constructor Summary
Constructors Modifier Constructor Description privateFieldInfo(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 voidcheckFieldNumber(int fieldNumber)intcompareTo(FieldInfo o)static FieldInfoforExplicitPresenceField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)Constructor for a field with explicit presence (e.g.static FieldInfoforField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, boolean enforceUtf8)Constructs a new descriptor for a field.static FieldInfoforFieldWithEnumVerifier(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier)static FieldInfoforLegacyRequiredField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)Constructor for a legacy required field.static FieldInfoforMapField(java.lang.reflect.Field field, int fieldNumber, java.lang.Object mapDefaultEntry, Internal.EnumVerifier enumVerifier)static FieldInfoforOneofMemberField(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 FieldInfoforPackedField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field cachedSizeField)Constructs a new descriptor for a packed field.static FieldInfoforPackedFieldWithEnumVerifier(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier, java.lang.reflect.Field cachedSizeField)static FieldInfoforRepeatedMessageField(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.FieldgetCachedSizeField()Internal.EnumVerifiergetEnumVerifier()Gets theEnumVerifierif the field is an enum field.java.lang.reflect.FieldgetField()Gets the subjectFieldof this descriptor.intgetFieldNumber()Gets the field number for the field.java.lang.Class<?>getListElementType()For repeated message fields, returns the message type of the field.java.lang.ObjectgetMapDefaultEntry()java.lang.Class<?>getMessageFieldClass()For singular or repeated message fields, returns the message type.OneofInfogetOneof()Gets the oneof for which this field is a member, ornullif not part of a oneof.java.lang.Class<?>getOneofStoredType()Gets the actual type stored in the oneof value by this field.java.lang.reflect.FieldgetPresenceField()Gets the presence bit field.intgetPresenceMask()IfgetPresenceField()is non-null, returns the mask used to identify the presence bit for this field in the message.FieldTypegetType()Gets the type information for the field.booleanisEnforceUtf8()Whether a UTF-8 should be enforced on string fields.private static booleanisExactlyOneBitSet(int value)booleanisRequired()Whether this is a required field.static FieldInfo.BuildernewBuilder()
-
-
-
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)
-
forExplicitPresenceField
public static FieldInfo forExplicitPresenceField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.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, 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
FieldInfodescribing this field.
-
checkFieldNumber
private static void checkFieldNumber(int fieldNumber)
-
forLegacyRequiredField
public static FieldInfo forLegacyRequiredField(java.lang.reflect.Field field, int fieldNumber, FieldType fieldType, java.lang.reflect.Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)
Constructor for a legacy 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 subjectFieldof 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, ornullif 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 theEnumVerifierif the field is an enum field.
-
compareTo
public int compareTo(FieldInfo o)
- Specified by:
compareToin 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)
-
-