Interface Structure

  • All Superinterfaces:
    Composite, DataType
    All Known Implementing Classes:
    StructureDataType

    public interface Structure
    extends Composite
    The structure interface.

    NOTE: Structures containing only a flexible array will report a length of 1 which will result in improper code unit sizing since we are unable to support a defined data of length 0.

    NOTE: The use of zero-length bitfields within unaligned structures is discouraged since they have no real affect and are easily misplaced. Their use should be reserved for aligned/packed structures.

    • Method Detail

      • getComponent

        DataTypeComponent getComponent​(int ordinal)
        Returns the component of this structure with the indicated ordinal. If the specified ordinal equals getNumComponents() the defined flexible array component will be returned, otherwise an out of bounds exception will be thrown. Use of getFlexibleArrayComponent() is preferred for obtaining this special trailing component.
        Specified by:
        getComponent in interface Composite
        Parameters:
        ordinal - the component's ordinal (zero based).
        Returns:
        the data type component.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if the ordinal is out of bounds
      • getComponentAt

        DataTypeComponent getComponentAt​(int offset)
        Gets the immediate child component that contains the byte at the given offset. If the specified offset corresponds to a bit-field,the first bit-field component containing the offset will be returned.
        Parameters:
        offset - the byte offset into this data type
        Returns:
        the immediate child component.
      • getDataTypeAt

        DataTypeComponent getDataTypeAt​(int offset)
        Returns the primitive Data Type that is at this offset. This is useful for prototypes that have components that are made up of other components If the specified offset corresponds to a bit-field,the BitFieldDataType of the first bit-field component containing the offset will be returned.
        Parameters:
        offset - the byte offset into this data type.
        Returns:
        the primitive data type at the offset.
      • insertBitField

        DataTypeComponent insertBitField​(int ordinal,
                                         int byteWidth,
                                         int bitOffset,
                                         DataType baseDataType,
                                         int bitSize,
                                         java.lang.String componentName,
                                         java.lang.String comment)
                                  throws InvalidDataTypeException,
                                         java.lang.ArrayIndexOutOfBoundsException
        Inserts a new bitfield at the specified ordinal position in this structure. Within aligned structures the specified byteWidth and bitOffset will be ignored since packing will occur at the specified ordinal position. The resulting component length and bitfield details will reflect the use of minimal storage sizing.

        For unaligned structures, a component shift will only occur if the bitfield placement conflicts with another component. If no conflict occurs, the bitfield will be placed at the specified location consuming any DEFAULT components as needed. When a conflict does occur a shift will be performed at the ordinal position based upon the specified byteWidth. When located onto existing bitfields they will be packed together provided they do not conflict, otherwise the conflict rule above applies.

        Supported aligned packing starts with bit-0 (lsb) of the first byte for little-endian, and with bit-7 (msb) of the first byte for big-endian. This is the default behavior for most compilers. Insertion behavior may not work as expected if packing rules differ from this.

        Parameters:
        ordinal - the ordinal where the new datatype is to be inserted.
        byteWidth - the storage allocation unit width which contains the bitfield. Must be large enough to contain the "effective bit size" and corresponding bitOffset. The actual component size used will be recomputed during insertion.
        bitOffset - corresponds to the bitfield left-shift amount with the storage unit when viewed as big-endian. The final offset may be reduced based upon the minimal storage size determined during insertion.
        baseDataType - the bitfield base datatype (certain restrictions apply).
        bitSize - the declared bitfield size in bits. The effective bit size may be adjusted based upon the specified baseDataType.
        componentName - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the bitfield component created whose associated data type will be BitFieldDataType.
        Throws:
        InvalidDataTypeException - if the specified baseDataType is not a valid base type for bitfields.
        java.lang.ArrayIndexOutOfBoundsException - if ordinal is less than 0 or greater than the current number of components.
      • insertBitFieldAt

        DataTypeComponent insertBitFieldAt​(int byteOffset,
                                           int byteWidth,
                                           int bitOffset,
                                           DataType baseDataType,
                                           int bitSize,
                                           java.lang.String componentName,
                                           java.lang.String comment)
                                    throws InvalidDataTypeException
        Inserts a new bitfield at the specified location in this composite. This method is intended to be used with unaligned structures where the bitfield will be precisely placed. Within an aligned structure the specified byteOffset, byteWidth and bitOffset will be used to identify the appropriate ordinal but may not be preserved. The component length will be computed based upon the specified parameters and will be reduced from byteWidth to its minimal size for the new component.

        For unaligned mode, a component shift will only occur if the bitfield placement conflicts with another component. If no conflict occurs, the bitfield will be placed at the specified location consuming any DEFAULT components as needed. When a conflict does occur a shift will be performed at the point of conflict based upon the specified byteWidth. When located onto existing bitfields they will be packed together provided they do not conflict, otherwise the conflict rule above applies.

        Supported packing for little-endian fills lsb first, whereas big-endian fills msb first. Insertion behavior may not work as expected if packing rules differ from this.

        Zero length bitfields may be inserted although they have no real affect for unaligned structures. Only the resulting byte offset within the structure is of significance in determining its' ordinal placement.

        Parameters:
        byteOffset - the first byte offset within this structure which corresponds to the first byte of the specified storage unit identified by its byteWidth.
        byteWidth - the storage unit width which contains the bitfield. Must be large enough to contain the specified bitSize and corresponding bitOffset. The actual component size used will be recomputed during insertion.
        bitOffset - corresponds to the bitfield left-shift amount with the storage unit when viewed as big-endian. The final offset may be reduced based upon the minimal storage size determined during insertion.
        baseDataType - the bitfield base datatype (certain restrictions apply).
        componentName - the field name to associate with this component.
        bitSize - the bitfield size in bits. A bitSize of 0 may be specified although its name will be ignored.
        comment - the comment to associate with this component.
        Returns:
        the componentDataType created whose associated data type will be BitFieldDataType.
        Throws:
        InvalidDataTypeException - if the specified data type is not a valid base type for bitfields.
      • insertAtOffset

        DataTypeComponent insertAtOffset​(int offset,
                                         DataType dataType,
                                         int length)
        Inserts a new datatype at the specified offset into this structure. Inserting a component will causing any conflicting component to shift down to the extent necessary to avoid a conflict.
        Parameters:
        offset - the byte offset into the structure where the new datatype is to be inserted.
        dataType - the datatype to insert.
        length - the length to associate with the dataType. For fixed length types a length <= 0 will use the length of the resolved dataType.
        Returns:
        the componentDataType created.
        Throws:
        java.lang.IllegalArgumentException - if the specified data type is not allowed to be inserted into this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to insert dt1 to dt2 since this would cause a cyclic dependency.
      • insertAtOffset

        DataTypeComponent insertAtOffset​(int offset,
                                         DataType dataType,
                                         int length,
                                         java.lang.String name,
                                         java.lang.String comment)
        Inserts a new datatype at the specified offset into this structure. Inserting a component will causing any conflicting component to shift down to the extent necessary to avoid a conflict.
        Parameters:
        offset - the byte offset into the structure where the new datatype is to be inserted.
        dataType - the datatype to insert.
        length - the length to associate with the dataType. For fixed length types a length <= 0 will use the length of the resolved dataType.
        name - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the componentDataType created.
        Throws:
        java.lang.IllegalArgumentException - if the specified data type is not allowed to be inserted into this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to insert dt1 to dt2 since this would cause a cyclic dependency.
      • deleteAtOffset

        void deleteAtOffset​(int offset)
        Deletes the component containing the specified offset in this structure. If the offset corresponds to a bit-field, all bit-fields whose base type group contains the offset will be removed.
        Parameters:
        offset - the byte offset into the structure where the datatype is to be deleted.
      • deleteAll

        void deleteAll()
        Remove all components from this structure, effectively setting the length to zero.
      • clearComponent

        void clearComponent​(int index)
        Clears the defined component at the given component index. Clearing a component causes a defined component to be replaced with a number of undefined dataTypes to offset the removal of the defined dataType.
        Parameters:
        index - the index of the component to clear.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if component ordinal is out of bounds
      • replace

        DataTypeComponent replace​(int index,
                                  DataType dataType,
                                  int length)
        Replaces the component at the given component index with a new component of the indicated data type.
        Parameters:
        index - the index where the datatype is to be replaced.
        dataType - the datatype to insert.
        length - the length of the dataType to insert. For fixed length types a length <= 0 will use the length of the resolved dataType.
        Returns:
        the new componentDataType at the index.
        Throws:
        java.lang.IllegalArgumentException - if the specified data type is not allowed to replace a component in this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to replace a dt2 component with dt1 since this would cause a cyclic dependency. In addition, any attempt to replace an existing bit-field component or specify a BitFieldDatatype will produce this error.
        java.lang.ArrayIndexOutOfBoundsException - if component index is out of bounds
      • replace

        DataTypeComponent replace​(int index,
                                  DataType dataType,
                                  int length,
                                  java.lang.String name,
                                  java.lang.String comment)
        Replaces the component at the given component index with a new component of the indicated data type.
        Parameters:
        index - the index where the datatype is to be replaced.
        dataType - the datatype to insert.
        length - the length to associate with the dataType. For fixed length types a length <= 0 will use the length of the resolved dataType.
        name - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the new componentDataType at the index.
        Throws:
        java.lang.IllegalArgumentException - if the specified data type is not allowed to replace a component in this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to replace a dt2 component with dt1 since this would cause a cyclic dependency. In addition, any attempt to replace an existing bit-field component or specify a BitFieldDatatype will produce this error.
        java.lang.ArrayIndexOutOfBoundsException - if component index is out of bounds
      • replaceAtOffset

        DataTypeComponent replaceAtOffset​(int offset,
                                          DataType dataType,
                                          int length,
                                          java.lang.String name,
                                          java.lang.String comment)
        Replaces the component at the specified byte offset with a new component of the indicated data type. If the offset corresponds to a bit-field, all bit-fields at that offset will be removed and replaced by the specified component. Keep in mind bit-field or any component removal must clear sufficient space for an unaligned structure to complete the replacement.
        Parameters:
        offset - the byte offset into the structure where the datatype is to be replaced.
        dataType - the datatype to insert.
        length - the length to associate with the dataType. For fixed length types a length <= 0 will use the length of the resolved dataType.
        name - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the new componentDataType at the index.
        Throws:
        java.lang.IllegalArgumentException - if the specified data type is not allowed to replace a component in this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to replace a dt2 component with dt1 since this would cause a cyclic dependency. In addition, any attempt to replace an existing bit-field component or specify a BitFieldDatatype will produce this error.
      • getComponents

        DataTypeComponent[] getComponents()
        Returns a list of all components that make up this data type excluding any trailing flexible array component if present.
        Specified by:
        getComponents in interface Composite
        Returns:
        an array containing the components
      • getDefinedComponents

        DataTypeComponent[] getDefinedComponents()
        Returns the list of components that are defined. (As opposed to "filler" undefined bytes.). Any trailing flexible array component will be omitted.
      • hasFlexibleArrayComponent

        boolean hasFlexibleArrayComponent()
        Determine if a trailing flexible array component has been defined.
        Returns:
        true if trailing flexible array component has been defined.
      • getFlexibleArrayComponent

        DataTypeComponent getFlexibleArrayComponent()
        Get the optional trailing flexible array component associated with this structure.
        Returns:
        optional trailing flexible array component associated with this structure or null if not present.
      • setFlexibleArrayComponent

        DataTypeComponent setFlexibleArrayComponent​(DataType flexType,
                                                    java.lang.String name,
                                                    java.lang.String comment)
        Set the optional trailing flexible array component associated with this structure.
        Parameters:
        flexType - the flexible array dataType (example: for 'char[0]' the type 'char' should be specified)
        name - component field name or null for default name
        comment - component comment
        Returns:
        updated flexible array component
      • clearFlexibleArrayComponent

        void clearFlexibleArrayComponent()
        Remove the optional trailing flexible array component associated with this structure.
      • getNumComponents

        int getNumComponents()
        Gets the number of component data types in this data type excluding any trailing flexible array component if present.
        Specified by:
        getNumComponents in interface Composite
        Returns:
        the number of components that make up this data prototype
      • getNumDefinedComponents

        int getNumDefinedComponents()
        Returns the number of non-undefined components in this composite. For example, say a structure has an int (4 bytes) at offset 0 and another int at offset 8. This structure would have 6 total components (one for each undefined between the two ints), but only 2 defined components. Any trailing flexible array component will not be included in this count.
        Returns:
        the number of non-undefined components in this composite
      • growStructure

        void growStructure​(int amount)
        Increases the size of the structure by the given amount by adding undefined datatypes at the end of the structure.
        Parameters:
        amount - the amount by which to grow the structure.
        Throws:
        java.lang.IllegalArgumentException - if amount < 1