Class FieldInfo

  • All Implemented Interfaces:
    java.lang.Comparable<FieldInfo>

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

      • field

        private final java.lang.reflect.Field field
      • 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
      • 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 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 java.lang.Object mapDefaultEntry
    • 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.
      • 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 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​(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 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 java.lang.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 java.lang.Comparable<FieldInfo>
      • getListElementType

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

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

        public java.lang.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 java.lang.reflect.Field getCachedSizeField()
      • getMessageFieldClass

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

        private static boolean isExactlyOneBitSet​(int value)