Class FieldInfo

java.lang.Object
com.google.protobuf.FieldInfo
All Implemented Interfaces:
Comparable<FieldInfo>

@ExperimentalApi final class FieldInfo extends Object implements Comparable<FieldInfo>
Information for a single field in a protobuf message class.
  • Field Details

    • field

      private final Field field
    • type

      private final FieldType type
    • messageClass

      private final Class<?> messageClass
    • fieldNumber

      private final int fieldNumber
    • presenceField

      private final 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 Field cachedSizeField
    • oneofStoredType

      private final Class<?> oneofStoredType
      The actual type stored in the oneof value for this field. Since the oneof value is an Object, primitives will store their boxed type. Only valid in conjunction with oneof (both must be either null or non-null.
    • mapDefaultEntry

      private final Object mapDefaultEntry
    • enumVerifier

      private final Internal.EnumVerifier enumVerifier
  • Constructor Details

  • 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)
    • forProto2OptionalField

      public static FieldInfo forProto2OptionalField(Field field, int fieldNumber, FieldType fieldType, 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, 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 an Object, primitives will store their boxed type. Must be non-null.
      enforceUtf8 - Only used for string fields. If true, 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(Field field, int fieldNumber, FieldType fieldType, Field presenceField, int presenceMask, boolean enforceUtf8, Internal.EnumVerifier enumVerifier)
      Constructor for a proto2 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

      public Field getField()
      Gets the subject Field 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, or null if not part of a oneof.
    • getOneofStoredType

      public Class<?> getOneofStoredType()
      Gets the actual type stored in the oneof value by this field. Since the oneof value is an Object, primitives will store their boxed type. For non-oneof fields, this will always be null.
    • getEnumVerifier

      public Internal.EnumVerifier getEnumVerifier()
      Gets the EnumVerifier if the field is an enum field.
    • compareTo

      public int compareTo(FieldInfo o)
      Specified by:
      compareTo in interface Comparable<FieldInfo>
    • getListElementType

      public Class<?> getListElementType()
      For repeated message fields, returns the message type of the field. For other fields, returns null.
    • getPresenceField

      public Field getPresenceField()
      Gets the presence bit field. Only valid for unary fields. For lists, returns null.
    • getMapDefaultEntry

      public Object getMapDefaultEntry()
    • getPresenceMask

      public int getPresenceMask()
      If getPresenceField() 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 Field getCachedSizeField()
    • getMessageFieldClass

      public Class<?> getMessageFieldClass()
      For singular or repeated message fields, returns the message type. For other fields, returns null.
    • newBuilder

      public static FieldInfo.Builder newBuilder()
    • isExactlyOneBitSet

      private static boolean isExactlyOneBitSet(int value)