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 Fieldprivate final booleanprivate final Internal.EnumVerifierprivate final Fieldprivate final intprivate final Objectprivate final Class<?>private final OneofInfoprivate final Class<?>The actual type stored in the oneof value for this field.private final Fieldprivate final intprivate final booleanprivate final FieldType -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateFieldInfo(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 voidcheckFieldNumber(int fieldNumber) intstatic FieldInfoforExplicitPresenceField(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 FieldInfoConstructs a new descriptor for a field.static FieldInfoforFieldWithEnumVerifier(Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier) static FieldInfoforLegacyRequiredField(Field field, int fieldNumber, FieldType fieldType, Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier) Constructor for a legacy required field.static FieldInfoforMapField(Field field, int fieldNumber, Object mapDefaultEntry, Internal.EnumVerifier enumVerifier) static FieldInfoforOneofMemberField(int fieldNumber, FieldType fieldType, OneofInfo oneof, Class<?> oneofStoredType, boolean enforceUtf8, Internal.EnumVerifier enumVerifier) Constructor for a field that is part of a oneof.static FieldInfoforPackedField(Field field, int fieldNumber, FieldType fieldType, Field cachedSizeField) Constructs a new descriptor for a packed field.static FieldInfoforPackedFieldWithEnumVerifier(Field field, int fieldNumber, FieldType fieldType, Internal.EnumVerifier enumVerifier, Field cachedSizeField) static FieldInfoforRepeatedMessageField(Field field, int fieldNumber, FieldType fieldType, Class<?> messageClass) Constructs a new descriptor for a repeated message field.Gets theEnumVerifierif the field is an enum field.getField()Gets the subjectFieldof this descriptor.intGets 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, ornullif not part of a oneof.Class<?>Gets the actual type stored in the oneof value by this field.Gets the presence bit field.intIfgetPresenceField()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.booleanWhether a UTF-8 should be enforced on string fields.private static booleanisExactlyOneBitSet(int value) booleanWhether 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
FieldInfodescribing 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 subjectFieldof this descriptor. -
getType
Gets the type information for the field. -
getOneof
Gets the oneof for which this field is a member, ornullif 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 theEnumVerifierif the field is an enum field. -
compareTo
- Specified by:
compareToin 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)
-