Class BitFieldDataType

  • All Implemented Interfaces:
    DataType

    public class BitFieldDataType
    extends AbstractDataType
    BitFieldDataType provides a means of defining a minimally sized bit-field for use within data structures. The length (i.e., storage size) of this bitfield datatype is the minimum number of bytes required to contain the bitfield at its specified offset. The effective bit-size of a bitfield will be limited by the size of the base datatype whose size may be controlled by its associated datatype manager and data organization (e.g., IntegerDataType).

    NOTE: Instantiation of this datatype implementation is intended for internal use only. Creating and manipulating bitfields should be accomplished directly via Structure or Union bitfield methods.

    • Field Detail

      • defaultSettings

        protected Settings defaultSettings
    • Constructor Detail

      • BitFieldDataType

        protected BitFieldDataType​(DataType baseDataType,
                                   int bitSize,
                                   int bitOffset)
                            throws InvalidDataTypeException
        Construct a bit-field type based upon a specified base type. The baseDataType will take precedence if specified. Either baseType or baseDatatype must be specified.
        Parameters:
        baseDataType - base data type (integer/enum type or typedef to same). This bitfield will adopt the same datatype manager as this base type.
        bitSize - size of bit-field expressed as number of bits (0..255). The effective bit size may be reduced based upon the specified base datatype size.
        bitOffset - right shift factor within storage unit when viewed as a big-endian dd scalar value. Based upon minimal storage bitOffset should be in the range 0 to 7.
        Throws:
        InvalidDataTypeException
      • BitFieldDataType

        protected BitFieldDataType​(DataType baseDataType,
                                   int bitSize)
                            throws InvalidDataTypeException
        Construct a bit-field type based upon a supported baseDataType.
        Parameters:
        baseDataType - a supported primitive integer data type or TypeDef to such a type. The baseType must already be cloned to the target datatype manager.
        bitSize - size of bit-field expressed as number of bits
        Throws:
        InvalidDataTypeException - if specified baseDataType is not permitted
    • Method Detail

      • getEffectiveBitSize

        public static int getEffectiveBitSize​(int declaredBitSize,
                                              int baseTypeByteSize)
        Get the effective bit-size based upon the specified base type size. A bit size larger than the base type size will truncated to the base type size.
        Parameters:
        declaredBitSize -
        baseTypeByteSize -
        Returns:
        effective bit-size
      • getMinimumStorageSize

        public static int getMinimumStorageSize​(int bitSize)
        Get the minimum storage size in bytes for a given size in bits. This does not consider the bit offset which may increase the required storage.
        Parameters:
        bitSize - number of bits within bitfield
        Returns:
        minimum storage size in bytes
      • getMinimumStorageSize

        public static int getMinimumStorageSize​(int bitSize,
                                                int bitOffset)
        Get the minimum storage size in bytes for a given size in bits with the specified bitOffset (lsb position within big endian storage)
        Parameters:
        bitSize - number of bits within bitfield
        bitOffset - normalized bitfield offset within storage (lsb)
        Returns:
        minimum storage size in bytes
      • checkBaseDataType

        public static void checkBaseDataType​(DataType baseDataType)
                                      throws InvalidDataTypeException
        Check a bitfield base datatype
        Parameters:
        baseDataType - bitfield base data type (Enum, AbstractIntegerDataType and derived TypeDefs permitted)
        Throws:
        InvalidDataTypeException - if baseDataType is invalid as a bitfield base type.
      • isValidBaseDataType

        public static boolean isValidBaseDataType​(DataType baseDataType)
        Check if a specified baseDataType is valid for use with a bitfield
        Parameters:
        baseDataType - bitfield base data type (Enum, AbstractIntegerDataType and derived TypeDefs permitted)
        Returns:
        true if baseDataType is valid else false
      • addParent

        public void addParent​(DataType dt)
        Description copied from interface: DataType
        Inform this datatype that it has the given parent

        TODO: This method is reserved for internal DB use.

        Specified by:
        addParent in interface DataType
        Overrides:
        addParent in class AbstractDataType
        Parameters:
        dt - parent datatype
      • getBaseTypeSize

        public int getBaseTypeSize()
        Get the size of the base data type based upon the associated data organization.
        Returns:
        base type size
      • getStorageSize

        public int getStorageSize()
        Get the packing storage size in bytes associated with this bit-field which may be larger than the base type associated with the fields original definition. Returned value is the same as getLength().
        Returns:
        packing storage size in bytes
      • getBitSize

        public int getBitSize()
        Get the effective bit size of this bit-field which may not exceed the size of the base datatype.
        Returns:
        bit size
      • getDeclaredBitSize

        public int getDeclaredBitSize()
        Get the declared bit size of this bit-field which may be larger than the effective size which could be truncated.
        Returns:
        bit size as defined by the field construction/declaration.
      • getBitOffset

        public int getBitOffset()
        Get the bit offset of the least-significant bit relative to bit-0 of the base datatype (i.e., least significant bit). This corresponds to the right-shift amount within the base data type when viewed as a big-endian value.
        Returns:
        bit offset
      • getBaseDataType

        public DataType getBaseDataType()
        Get the base datatype associated with this bit-field (e.g., int, long, etc., or TypeDef to supported base type)
        Returns:
        base data type
      • getPrimitiveBaseDataType

        public AbstractIntegerDataType getPrimitiveBaseDataType()
        Get the base datatype associated with this bit-field (e.g., int, long, etc., or TypeDef to supported base type)
        Returns:
        base data type
      • getSettingsDefinitions

        public final SettingsDefinition[] getSettingsDefinitions()
        Gets a list of all the settingsDefinitions used by this datatype.
        Returns:
        a list of the settingsDefinitions used by this datatype.
      • isEquivalent

        public final boolean isEquivalent​(DataType dt)
        Description copied from interface: DataType
        Check if the given datatype is equivalent to this datatype.

        The precise meaning of "equivalent" is datatype dependent.
        NOTE: if invoked by a DB object or manager it should be invoked on the DataTypeDB object passing the other datatype as the argument.

        Parameters:
        dt - the datatype being tested for equivalence.
        Returns:
        true if the if the given datatype is equivalent to this datatype.
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public final boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getDefaultSettings

        public Settings getDefaultSettings()
        Description copied from interface: DataType
        Gets the default settings for this datatype.
        Returns:
        the default settings for this datatype.
      • clone

        public BitFieldDataType clone​(DataTypeManager dtm)
        Clone this bitfield to a new datatype manager. This may change the effective bit size and storage size of the resulting datatype based upon the data organization of the specified dtm.
        Parameters:
        dtm - target datatype manager
        Returns:
        new instance or same instance of dtm is unchanged.
      • getLength

        public int getLength()
        Description copied from interface: DataType
        Get the length (number of 8-bit bytes) of this DataType.

        NOTE: No datatype should ever return 0, even if DataType.isZeroLength(), and only Dynamic datatypes should return -1. If DataType.isZeroLength() is true a length of 1 should be returned. Where a zero-length datatype can be handled (e.g., Composite) the DataType.isZeroLength() method should be used.

        Returns:
        the length of this DataType
      • getDescription

        public java.lang.String getDescription()
        Description copied from interface: DataType
        Get a String briefly describing this DataType.
        Returns:
        a one-liner describing this DataType.
      • getValue

        public java.lang.Object getValue​(MemBuffer buf,
                                         Settings settings,
                                         int length)
        Description copied from interface: DataType
        Get the data in the form of the appropriate Object for this DataType.

        For instance if the datatype is an AddressDT, return an Address object. a Byte, return a Scalar* (maybe this should be a Byte) a Float, return a Float

        Parameters:
        buf - the data buffer.
        settings - the settings to use.
        length - the number of bytes to get the value from.
        Returns:
        the data Object.
      • getValueClass

        public java.lang.Class<?> getValueClass​(Settings settings)
        Description copied from interface: DataType
        Get the Class of the value to be returned by this datatype.
        Parameters:
        settings - the relevant settings to use or null for default.
        Returns:
        Class of the value to be returned by this datatype or null if it can vary or is unspecified. Types which correspond to a string or char array will return the String class.
      • getRepresentation

        public java.lang.String getRepresentation​(MemBuffer buf,
                                                  Settings settings,
                                                  int length)
        Description copied from interface: DataType
        Get bytes from memory in a printable format for this type.
        Parameters:
        buf - the data.
        settings - the settings to use for the representation.
        length - the number of bytes to represent.
        Returns:
        the representation of the data in this format, never null.
      • setDefaultSettings

        public void setDefaultSettings​(Settings settings)
        Description copied from interface: DataType
        Set the default settings for this datatype.

        TODO: This method is reserved for internal DB use.

        Parameters:
        settings - the settings to be used as this dataTypes default settings.
      • getAlignment

        public int getAlignment()
        Description copied from interface: DataType
        Gets the alignment to be used when aligning this datatype within another datatype.
        Returns:
        this datatype's alignment.