Class StructureDataType

    • Field Detail

      • structLength

        protected int structLength
      • numComponents

        protected int numComponents
    • Constructor Detail

      • StructureDataType

        public StructureDataType​(java.lang.String name,
                                 int length)
        Construct a new structure with the given name and length. The root category will be used.
        Parameters:
        name - the name of the new structure
        length - the initial size of the structure in bytes. If 0 is specified the structure will report its length as 1 and CompositeDataTypeImpl.isNotYetDefined() will return true.
      • StructureDataType

        public StructureDataType​(java.lang.String name,
                                 int length,
                                 DataTypeManager dtm)
        Construct a new structure with the given name, length and datatype manager which conveys data organization. The root category will be used.
        Parameters:
        name - the name of the new structure
        length - the initial size of the structure in bytes. If 0 is specified the structure will report its length as 1 and CompositeDataTypeImpl.isNotYetDefined() will return true.
        dtm - the data type manager associated with this data type. This can be null. Also, the data type manager may not yet contain this actual data type.
      • StructureDataType

        public StructureDataType​(CategoryPath path,
                                 java.lang.String name,
                                 int length)
        Construct a new structure with the given name and length within the specified categry path.
        Parameters:
        path - the category path indicating where this data type is located.
        name - the name of the new structure
        length - the initial size of the structure in bytes. If 0 is specified the structure will report its length as 1 and CompositeDataTypeImpl.isNotYetDefined() will return true.
      • StructureDataType

        public StructureDataType​(CategoryPath path,
                                 java.lang.String name,
                                 int length,
                                 DataTypeManager dtm)
        Construct a new structure with the given name, length and datatype manager within the specified categry path.
        Parameters:
        path - the category path indicating where this data type is located.
        name - the name of the new structure
        length - the initial size of the structure in bytes. If 0 is specified the structure will report its length as 1 and CompositeDataTypeImpl.isNotYetDefined() will return true.
        dtm - the data type manager associated with this data type. This can be null. Also, the data type manager may not yet contain this actual data type.
      • StructureDataType

        public StructureDataType​(CategoryPath path,
                                 java.lang.String name,
                                 int length,
                                 UniversalID universalID,
                                 SourceArchive sourceArchive,
                                 long lastChangeTime,
                                 long lastChangeTimeInSourceArchive,
                                 DataTypeManager dtm)
        Construct a new structure with the given name and length
        Parameters:
        path - the category path indicating where this data type is located.
        name - the name of the new structure
        length - the initial size of the structure in bytes. If 0 is specified the structure will report its length as 1 and CompositeDataTypeImpl.isNotYetDefined() will return true.
        universalID - the id for the data type
        sourceArchive - the source archive for this data type
        lastChangeTime - the last time this data type was changed
        lastChangeTimeInSourceArchive - the last time this data type was changed in its source archive.
        dtm - the data type manager associated with this data type. This can be null. Also, the data type manager may not yet contain this actual data type.
    • Method Detail

      • 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.
        Specified by:
        getRepresentation in interface DataType
        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.
      • getDefinedComponentAtOrAfterOffset

        public DataTypeComponent getDefinedComponentAtOrAfterOffset​(int offset)
        Description copied from interface: Structure
        Gets the first defined component located at or after the specified offset. Note: The returned component may be a zero-length component.
        Specified by:
        getDefinedComponentAtOrAfterOffset in interface Structure
        Parameters:
        offset - the byte offset into this structure
        Returns:
        the first defined component located at or after the specified offset or null if not found.
      • getComponentContaining

        public DataTypeComponent getComponentContaining​(int offset)
        Description copied from interface: Structure
        Gets the first non-zero-length component that contains the byte at the specified offset. Note that one or more components may share the same offset when a bit-field or zero-length component is present since these may share an offset. A null may be returned under one of the following conditions:
        • offset only corresponds to a zero-length component within a packed structure
        • offset corresponds to a padding byte within a packed structure
        • offset is >= structure length.
        If a bitfield is returned, and the caller supports bitfields, it is recommended that Structure.getComponentsContaining(int) be invoked to gather all bitfields which contain the specified offset.
        Specified by:
        getComponentContaining in interface Structure
        Parameters:
        offset - the byte offset into this structure
        Returns:
        the first non-zero-length component that contains the byte at the specified offset or null if not found.
      • getComponentsContaining

        public java.util.List<DataTypeComponent> getComponentsContaining​(int offset)
        Description copied from interface: Structure
        Get an ordered list of components that contain the byte at the specified offset. Unlike Structure.getComponentAt(int) and Structure.getComponentContaining(int) this method will include zero-length components if they exist at the specified offset. For this reason the specified offset may equal the structure length to obtain and trailing zero-length components. Note that this method will only return more than one component when a bit-fields and/or zero-length components are present since these may share an offset. An empty list may be returned under the following conditions:
        • offset only corresponds to a padding byte within a packed structure
        • offset is equal structure length and no trailing zero-length components exist
        • offset is > structure length
        Specified by:
        getComponentsContaining in interface Structure
        Parameters:
        offset - the byte offset into this structure
        Returns:
        a list of zero or more components containing the specified offset
      • getDataTypeAt

        public DataTypeComponent getDataTypeAt​(int offset)
        Description copied from interface: Structure
        Returns the lowest-level component that contains the specified offset. This is useful for structures that have sub-structures. This method is best used when working with known structures which do not contain bitfields or zero-length components since in those situations multiple components may correspond to the specified offset. A similar ambiguous condition occurs if offset corresponds to a union component.
        Specified by:
        getDataTypeAt in interface Structure
        Parameters:
        offset - the byte offset into this data type.
        Returns:
        a primitive component data type which contains the specified offset.
      • delete

        public void delete​(int ordinal)
        Description copied from interface: Composite
        Deletes the component at the given ordinal position.
        Note: Removal of bitfields from a structure with packing disabled will not shift other components causing vacated bytes to revert to undefined filler.
        Specified by:
        delete in interface Composite
        Parameters:
        ordinal - the ordinal of the component to be deleted.
      • delete

        public void delete​(java.util.Set<java.lang.Integer> ordinals)
        Description copied from interface: Composite
        Deletes the specified set of components at the given ordinal positions.
        Note: Removal of bitfields from a structure with packing disabled will not shift other components causing vacated bytes to revert to undefined filler.
        Specified by:
        delete in interface Composite
        Parameters:
        ordinals - the ordinals of the component to be deleted.
      • shiftOffset

        protected void shiftOffset​(DataTypeComponentImpl dtc,
                                   int deltaOrdinal,
                                   int deltaOffset)
      • getComponent

        public DataTypeComponentImpl getComponent​(int ordinal)
        Description copied from interface: Structure
        Returns the component of this structure with the indicated ordinal.
        Specified by:
        getComponent in interface Composite
        Specified by:
        getComponent in interface Structure
        Parameters:
        ordinal - the ordinal of the component requested.
        Returns:
        the data type component.
      • getNumComponents

        public int getNumComponents()
        Description copied from interface: Composite
        Gets the number of component data types in this composite. If this is Structure with packing disabled, the count will include all undefined filler components which may be present.
        Specified by:
        getNumComponents in interface Composite
        Returns:
        the number of components that make up this composite
      • getNumDefinedComponents

        public int getNumDefinedComponents()
        Description copied from interface: Composite
        Returns the number of explicitly defined components in this composite. For Unions and packed Structures this is equivalent to Composite.getNumComponents() since they do not contain undefined components. This count will always exclude all undefined filler components which may be present within a Structure whose packing is disabled (see Composite.isPackingEnabled()).
        Specified by:
        getNumDefinedComponents in interface Composite
        Returns:
        the number of explicitly defined components in this composite
      • insertAtOffset

        public final DataTypeComponentImpl insertAtOffset​(int offset,
                                                          DataType dataType,
                                                          int length)
        Description copied from interface: Structure
        Inserts a new datatype at the specified offset into this structure. Inserting a component will cause any conflicting components to shift down to the extent necessary to avoid a conflict.
        Specified by:
        insertAtOffset in interface Structure
        Parameters:
        offset - the byte offset into the structure where the new datatype is to be inserted.
        dataType - the datatype to insert. If DataType.DEFAULT is specified for a packed structure an Undefined1DataType will be used in its place.
        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.
      • insertAtOffset

        public DataTypeComponentImpl insertAtOffset​(int offset,
                                                    DataType dataType,
                                                    int length,
                                                    java.lang.String componentName,
                                                    java.lang.String comment)
                                             throws java.lang.IllegalArgumentException
        Description copied from interface: Structure
        Inserts a new datatype at the specified offset into this structure. Inserting a component will cause any conflicting components to shift down to the extent necessary to avoid a conflict.

        This method does not support bit-field insertions which must use the method Structure.insertBitFieldAt(int, int, int, DataType, int, String, String).

        Specified by:
        insertAtOffset in interface Structure
        Parameters:
        offset - the byte offset into the structure where the new datatype is to be inserted.
        dataType - the datatype to insert. If DataType.DEFAULT is specified for a packed structure an Undefined1DataType will be used in its place.
        length - the length to associate with the dataType. For fixed length types a length <= 0 will use the length of the resolved dataType.
        componentName - 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.
      • add

        public DataTypeComponent add​(DataType dataType,
                                     int length,
                                     java.lang.String componentName,
                                     java.lang.String comment)
        Description copied from interface: Composite
        Adds a new datatype to the end of this composite. This is the preferred method to use for adding components to an aligned structure for dynamic dataTypes such as strings whose length must be specified.
        Specified by:
        add in interface Composite
        Parameters:
        dataType - the datatype to add.
        length - the length to associate with the datatype. For fixed length types a length <= 0 will use the length of the resolved dataType.
        componentName - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the componentDataType created.
      • growStructure

        public void growStructure​(int amount)
        Description copied from interface: Structure
        Increases the size of the structure by the specified amount by adding undefined filler at the end of the structure. NOTE: This method only has an affect on non-packed structures.
        Specified by:
        growStructure in interface Structure
        Parameters:
        amount - the amount by which to grow the structure.
      • insert

        public DataTypeComponent insert​(int ordinal,
                                        DataType dataType,
                                        int length,
                                        java.lang.String componentName,
                                        java.lang.String comment)
                                 throws java.lang.IndexOutOfBoundsException,
                                        java.lang.IllegalArgumentException
        Description copied from interface: Composite
        Inserts a new datatype at the specified ordinal position in this composite.
        Note: For an aligned structure the ordinal position will get adjusted automatically to provide the proper alignment.
        Specified by:
        insert in interface Composite
        Parameters:
        ordinal - the ordinal 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.
        componentName - the field name to associate with this component.
        comment - the comment to associate with this component.
        Returns:
        the componentDataType created.
        Throws:
        java.lang.IndexOutOfBoundsException - if component ordinal is out of bounds
        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.
      • addBitField

        public DataTypeComponent addBitField​(DataType baseDataType,
                                             int bitSize,
                                             java.lang.String componentName,
                                             java.lang.String comment)
                                      throws InvalidDataTypeException
        Description copied from interface: Composite
        Adds a new bitfield to the end of this composite. This method is intended to be used with packed structures/unions only where the bitfield will be appropriately packed. The minimum storage storage byte size will be applied. It will not provide useful results for composites with packing disabled.
        Specified by:
        addBitField in interface Composite
        Parameters:
        baseDataType - the bitfield base datatype (certain restrictions apply).
        bitSize - the bitfield size in bits
        componentName - the field name to associate with this component.
        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.
      • insertBitField

        public DataTypeComponent insertBitField​(int ordinal,
                                                int byteWidth,
                                                int bitOffset,
                                                DataType baseDataType,
                                                int bitSize,
                                                java.lang.String componentName,
                                                java.lang.String comment)
                                         throws InvalidDataTypeException,
                                                java.lang.IndexOutOfBoundsException
        Description copied from interface: Structure
        Inserts a new bitfield at the specified ordinal position in this structure. Within packed 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 structures with packing disabled, 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 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.

        Specified by:
        insertBitField in interface Structure
        Parameters:
        ordinal - the ordinal of the component 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.IndexOutOfBoundsException - if ordinal is less than 0 or greater than the current number of components.
      • insertBitFieldAt

        public DataTypeComponentImpl insertBitFieldAt​(int byteOffset,
                                                      int byteWidth,
                                                      int bitOffset,
                                                      DataType baseDataType,
                                                      int bitSize,
                                                      java.lang.String componentName,
                                                      java.lang.String comment)
                                               throws InvalidDataTypeException
        Description copied from interface: Structure
        Inserts a new bitfield at the specified location in this composite. This method is intended to be used with structures with packing disabled where the bitfield will be precisely placed. Within an packed 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.

        When packing disabled, 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 when packing disabled. Only the resulting byte offset within the structure is of significance in determining its ordinal placement.

        Specified by:
        insertBitFieldAt in interface Structure
        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).
        bitSize - the bitfield size in bits. A bitSize of 0 may be specified although its name will be ignored.
        componentName - the field name to associate with this component.
        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.
      • deleteAtOffset

        public void deleteAtOffset​(int offset)
        Description copied from interface: Structure
        Deletes all defined components containing the specified offset in this structure. If the offset corresponds to a bit-field or zero-length component (e.g., 0-element array) multiple components may be deleted. Bit-fields are only cleared and may leave residual undefined components in their place. This method will generally reduce the length of the structure. The Structure.clearAtOffset(int) method should be used for non-packed structures to preserve the structure length and placement of other components.
        Specified by:
        deleteAtOffset in interface Structure
        Parameters:
        offset - the byte offset into the structure where the component(s) are to be deleted. An offset equal to the structure length may be specified to delete any trailing zero-length components.
      • clearAtOffset

        public void clearAtOffset​(int offset)
        Description copied from interface: Structure
        Clears all defined components containing the specified offset in this structure. If the offset corresponds to a bit-field or zero-length component (e.g., 0-element array) multiple components may be cleared. This method will preserve the structure length and placement of other components since freed space will appear as undefined components.

        To avoid clearing zero-length components at a specified offset within a non-packed structure, the Structure.replaceAtOffset(int, DataType, int, String, String) may be used with to clear only the sized component at the offset by specified DataType.DEFAULT as the replacement datatype.

        Specified by:
        clearAtOffset in interface Structure
        Parameters:
        offset - the byte offset into the structure where the component(s) are to be deleted.
      • isEquivalent

        public boolean isEquivalent​(DataType dataType)
        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.

        Specified by:
        isEquivalent in interface DataType
        Parameters:
        dataType - the datatype being tested for equivalence.
        Returns:
        true if the if the given datatype is equivalent to this datatype.
      • dataTypeSizeChanged

        public void dataTypeSizeChanged​(DataType dt)
        Description copied from interface: DataType
        Notification that the given datatype's size has changed.

        DataTypes may need to make internal changes in response.
        TODO: This method is reserved for internal DB use.

        Specified by:
        dataTypeSizeChanged in interface DataType
        Overrides:
        dataTypeSizeChanged in class AbstractDataType
        Parameters:
        dt - the datatype that has changed.
      • copy

        public DataType copy​(DataTypeManager dtm)
        Create copy of structure for target dtm (source archive information is discarded).

        WARNING! copying non-packed structures which contain bitfields can produce invalid results when switching endianess due to the differences in packing order.

        Specified by:
        copy in interface DataType
        Parameters:
        dtm - target data type manager
        Returns:
        cloned structure
      • clone

        public StructureDataType clone​(DataTypeManager dtm)
        Create cloned structure for target dtm preserving source archive information. WARNING! cloning non-packed structures which contain bitfields can produce invalid results when switching endianess due to the differences in packing order.
        Specified by:
        clone in interface DataType
        Specified by:
        clone in interface Structure
        Parameters:
        dtm - target data type manager
        Returns:
        cloned structure
      • clearComponent

        public void clearComponent​(int ordinal)
        Description copied from interface: Structure
        Clears the defined component at the specified component ordinal. Clearing a component within a non-packed structure causes a defined component to be replaced with a number of undefined components. This may not the case when clearing a zero-length component or bit-field which may not result in such undefined components. In the case of a packed structure clearing is always completed without backfill.
        Specified by:
        clearComponent in interface Structure
        Parameters:
        ordinal - the ordinal of the component to clear.
      • replaceWith

        public void replaceWith​(DataType dataType)
        Replaces the internal components of this structure with components of the given structure including packing and alignment settings.
        Specified by:
        replaceWith in interface DataType
        Overrides:
        replaceWith in class DataTypeImpl
        Parameters:
        dataType - the structure to get the component information from.
        Throws:
        java.lang.IllegalArgumentException - if any of the component data types are not allowed to replace a component in this composite data type. 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.
      • dataTypeDeleted

        public void dataTypeDeleted​(DataType dt)
        Description copied from interface: DataType
        Informs this datatype that the given datatype has been deleted.

        TODO: This method is reserved for internal DB use.

        Specified by:
        dataTypeDeleted in interface DataType
        Overrides:
        dataTypeDeleted in class AbstractDataType
        Parameters:
        dt - the datatype that has been deleted.
      • dataTypeReplaced

        public void dataTypeReplaced​(DataType oldDt,
                                     DataType replacementDt)
                              throws java.lang.IllegalArgumentException
        Description copied from interface: DataType
        Informs this datatype that the given oldDT has been replaced with newDT

        TODO: This method is reserved for internal DB use.

        Specified by:
        dataTypeReplaced in interface DataType
        Overrides:
        dataTypeReplaced in class AbstractDataType
        Parameters:
        oldDt - old datatype
        replacementDt - new datatype
        Throws:
        java.lang.IllegalArgumentException
      • getDefinedComponents

        public DataTypeComponent[] getDefinedComponents()
        Description copied from interface: Composite
        Returns an array of Data Type Components that make up this composite excluding undefined filler components which may be present within Structures where packing is disabled. The number of components corresponds to Composite.getNumDefinedComponents(). For Unions and packed Structures this is equivalent to Composite.getComponents() since they do not contain undefined filler components.
        Specified by:
        getDefinedComponents in interface Composite
        Returns:
        array all explicitly defined components
      • getComponents

        public DataTypeComponent[] getComponents()
        Description copied from interface: Composite
        Returns an array of Data Type Components that make up this composite including undefined filler components which may be present within a Structure whch has packing disabled. The number of components corresponds to Composite.getNumComponents().
        Specified by:
        getComponents in interface Composite
        Returns:
        array all components
      • replace

        public final DataTypeComponent replace​(int index,
                                               DataType dataType,
                                               int length)
        Description copied from interface: Structure
        Replaces the component at the specified ordinal with a new component using the specified datatype, length, name and comment. In the case of a packed structure a 1-for-1 replacement will occur. In the case of a non-packed structure certain restrictions apply:
        • A zero-length component may only be replaced with another zero-length component.
        • If ordinal corresponds to a bit-field, all bit-fields which overlap the specified bit-field will be replaced.
        There must be sufficient space to complete the replacement factoring in the space freed by the consumed component(s). If there are no remaining defined components beyond the consumed components the structure will expand its length as needed. For a packed structure, this method behaves the same as a ordinal-based delete followed by an insert.

        Datatypes not permitted include FactoryDataType types, non-sizable Dynamic types, and those which result in a circular direct dependency.

        NOTE: In general, it is not recommended that this method be used with non-packed structures where the replaced component is a bit-field.

        Specified by:
        replace in interface Structure
        Parameters:
        index - the ordinal of the component to be replaced.
        dataType - the datatype to insert. If DataType.DEFAULT is specified for a packed structure an Undefined1DataType will be used in its place. If DataType.DEFAULT is specified for a non-packed structure this is equivelant to Structure.clearComponent(int), ignoring the length, name and comment arguments.
        length - component length for containing the specified dataType. A positive length is required for sizable Dynamic datatypes and should be specified as -1 for fixed-length datatypes to rely on their resolved size.
        Returns:
        the new component.
      • replace

        public DataTypeComponent replace​(int ordinal,
                                         DataType dataType,
                                         int length,
                                         java.lang.String componentName,
                                         java.lang.String comment)
                                  throws java.lang.IndexOutOfBoundsException,
                                         java.lang.IllegalArgumentException
        Description copied from interface: Structure
        Replaces the component at the specified ordinal with a new component using the specified datatype, length, name and comment. In the case of a packed structure a 1-for-1 replacement will occur. In the case of a non-packed structure certain restrictions apply:
        • A zero-length component may only be replaced with another zero-length component.
        • If ordinal corresponds to a bit-field, all bit-fields which overlap the specified bit-field will be replaced.
        There must be sufficient space to complete the replacement factoring in the space freed by the consumed component(s). If there are no remaining defined components beyond the consumed components the structure will expand its length as needed. For a packed structure, this method behaves the same as a ordinal-based delete followed by an insert.

        Datatypes not permitted include FactoryDataType types, non-sizable Dynamic types, and those which result in a circular direct dependency.

        NOTE: In general, it is not recommended that this method be used with non-packed structures where the replaced component is a bit-field.

        Specified by:
        replace in interface Structure
        Parameters:
        ordinal - the ordinal of the component to be replaced.
        dataType - the datatype to insert. If DataType.DEFAULT is specified for a packed structure an Undefined1DataType will be used in its place. If DataType.DEFAULT is specified for a non-packed structure this is equivelant to Structure.clearComponent(int), ignoring the length, name and comment arguments.
        length - component length for containing the specified dataType. A positive length is required for sizable Dynamic datatypes and should be specified as -1 for fixed-length datatypes to rely on their resolved size.
        componentName - the field name to associate with this component or null.
        comment - the comment to associate with this component or null.
        Returns:
        the new component.
        Throws:
        java.lang.IndexOutOfBoundsException - if component ordinal is out of bounds
        java.lang.IllegalArgumentException - may be caused by: 1) invalid offset specified, 2) invalid datatype or associated length specified, or 3) insufficient space for replacement.
      • replaceAtOffset

        public DataTypeComponent replaceAtOffset​(int offset,
                                                 DataType dataType,
                                                 int length,
                                                 java.lang.String name,
                                                 java.lang.String comment)
                                          throws java.lang.IllegalArgumentException
        Description copied from interface: Structure
        Replaces all components containing the specified byte offset with a new component using the specified datatype, length, name and comment. If the offset corresponds to a bit-field more than one component may be consumed by this replacement.

        This method may not be used to replace a zero-length component since there may be any number of zero-length components at the same offset. If the only defined component(s) at the specified offset are zero-length the subsequent undefined will be replaced in the case of a non-packed structure. For a packed structure such a case would be treated as an insert as would an offset which is not contained within a component.

        For a non-packed structure a replacement will attempt to consume sufficient space within moving other defined components. There must be sufficient space to complete the replacement factoring in the space freed by the consumed component(s). When replacing the last defined component the structure size will be expanded as needed to fit the new component. For a packed If there are no remaining defined components beyond the consumed components, or an offset equals to the structure length is specified, the structure will expand its length as needed.

        For a non-packed structure the new component will use the specified offset. In the case of packed structure, the actual offset will be determined during a repack.

        Datatypes not permitted include FactoryDataType types, non-sizable Dynamic types, and those which result in a circular direct dependency.

        Specified by:
        replaceAtOffset in interface Structure
        Parameters:
        offset - the byte offset into the structure where the datatype is to be placed. The specified offset must be less than the length of the structure.
        dataType - the datatype to insert. If DataType.DEFAULT is specified for a packed structure an Undefined1DataType will be used in its place. If DataType.DEFAULT is specified for a non-packed structure this is equivelant to clearing all components, which contain the specified offset, ignoring the length, name and comment arguments.
        length - component length for containing the specified dataType. A positive length is required for sizable Dynamic datatypes and should be specified as -1 for fixed-length datatypes to rely on their resolved size.
        name - the field name to associate with this component or null.
        comment - the comment to associate with this component or null.
        Returns:
        the new component.
        Throws:
        java.lang.IllegalArgumentException - may be caused by: 1) invalid offset specified, 2) invalid datatype or associated length specified, or 3) insufficient space for replacement.
      • getNumUndefinedBytes

        protected int getNumUndefinedBytes​(int index)
        Gets the number of Undefined bytes beginning at the indicated component index. Undefined bytes that have a field name or comment specified are also included.
        Parameters:
        index - the component index to begin checking at.
        Returns:
        the number of contiguous undefined bytes
      • dependsOn

        public boolean dependsOn​(DataType dt)
        Description copied from interface: DataType
        Check if this datatype depends on the existence of the given datatype.

        For example byte[] depends on byte. If byte were deleted, then byte[] would also be deleted.

        Specified by:
        dependsOn in interface DataType
        Overrides:
        dependsOn in class AbstractDataType
        Parameters:
        dt - the datatype to test that this datatype depends on.
        Returns:
        true if the existence of this datatype relies on the existence of the specified datatype dt.
      • deleteAll

        public void deleteAll()
        Description copied from interface: Structure
        Remove all components from this structure, effectively setting the length to zero. Packing and minimum alignment settings are unaffected.
        Specified by:
        deleteAll in interface Structure
      • getDefaultLabelPrefix

        public java.lang.String getDefaultLabelPrefix()
        Description copied from interface: DataType
        Returns the appropriate string to use as the default label prefix in the absence of any data.
        Specified by:
        getDefaultLabelPrefix in interface DataType
        Overrides:
        getDefaultLabelPrefix in class AbstractDataType
        Returns:
        the default label prefix or null if none specified.
      • repack

        public boolean repack​(boolean notify)
        Description copied from class: CompositeDataTypeImpl
        Repack components within this composite based on the current packing, alignment and DataOrganization settings. Non-packed Structures: change detection is limited to component count and length is assumed to already be correct.

        NOTE: If modifications to stored length are made prior to invoking this method, detection of a size change may not be possible.

        NOTE: Currently a change in calculated alignment can not be provided since this value is not stored.

        Specified by:
        repack in class CompositeDataTypeImpl
        Parameters:
        notify - if true notification will be sent to parents if a size change or component placement change is detected.
        Returns:
        true if a layout change was detected.