Class DynamicTypeSegment

    • Constructor Detail

      • DynamicTypeSegment

        public DynamicTypeSegment​(int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess)
        Constructs the DynamicTypeSegment with the given properties as well as with the TransmissionMetrics.DEFAULT_ENCODING.
        Parameters:
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
      • DynamicTypeSegment

        public DynamicTypeSegment​(int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess,
                                  Charset aCharset)
        Constructs the DynamicTypeSegment with the given properties.
        Parameters:
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
        aCharset - The Charset to be used for encoding and decoding String instances.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess)
        Constructs the DynamicTypeSegment with the given properties as well as with the TransmissionMetrics.DEFAULT_ENCODING.
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess,
                                  Charset aCharset)
        Constructs the DynamicTypeSegment with the given properties.
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
        aCharset - The Charset to be used for encoding and decoding String instances.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  T aValue,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess)
        Constructs the DynamicTypeSegment with the given properties as well as with the TransmissionMetrics.DEFAULT_ENCODING. It is pre-initialized with the given value as of fromType(Object).
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aValue - The data structure's value.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  T aValue,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess,
                                  Charset aCharset)
        Constructs the DynamicTypeSegment with the given properties. It is pre-initialized with the given value as of fromType(Object).
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aValue - The data structure's value.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
        aCharset - The Charset to be used for encoding and decoding String instances.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  T aValue,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess,
                                  Charset aCharset,
                                  String... aAttributes)
        Constructs the DynamicTypeSegment with the given properties. It is pre-initialized with the given value as of fromType(Object, String...).
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aValue - The data structure's value.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
        aCharset - The Charset to be used for encoding and decoding String instances.
        aAttributes - The attributes or null if all attributes are to be processed in alphabetical order.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  T aValue,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess,
                                  String... aAttributes)
        Constructs the DynamicTypeSegment with the given properties as well as with the TransmissionMetrics.DEFAULT_ENCODING. It is pre-initialized with the given value as of fromType(Object, String...).
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aValue - The data structure's value.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
        aAttributes - The attributes or null if all attributes are to be processed in alphabetical order.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  T aValue,
                                  TransmissionMetrics aTransmissionMetrics)
        Constructs the DynamicTypeSegment with the given properties. It is pre-initialized with the given value as of fromType(Object). The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aValue - The data structure's value.
        aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  T aValue,
                                  TransmissionMetrics aTransmissionMetrics,
                                  String... aAttributes)
        Constructs the DynamicTypeSegment with the given properties. It is pre-initialized with the given value as of fromType(Object, String...). The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aValue - The data structure's value.
        aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
        aAttributes - The attributes or null if all attributes are to be processed in alphabetical order.
      • DynamicTypeSegment

        public DynamicTypeSegment​(String aAlias,
                                  TransmissionMetrics aTransmissionMetrics)
        Constructs the DynamicTypeSegment with the given properties. The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
        Parameters:
        aAlias - The alias which identifies the content of this segment.
        aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
      • DynamicTypeSegment

        public DynamicTypeSegment​(T aValue,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess)
        Constructs the DynamicTypeSegment with the given properties as well as with the TransmissionMetrics.DEFAULT_ENCODING. It is pre-initialized with the given value as of fromType(Object).
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aValue - The data structure's value.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
      • DynamicTypeSegment

        public DynamicTypeSegment​(T aValue,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess,
                                  Charset aCharset)
        Constructs the DynamicTypeSegment with the given properties. It is pre-initialized with the given value as of fromType(Object).
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aValue - The data structure's value.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
        aCharset - The Charset to be used for encoding and decoding String instances.
      • DynamicTypeSegment

        public DynamicTypeSegment​(T aValue,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess,
                                  Charset aCharset,
                                  String... aAttributes)
        Constructs the DynamicTypeSegment with the given properties. It is pre-initialized with the given value as of fromType(Object, String...).
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aValue - The data structure's value.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
        aCharset - The Charset to be used for encoding and decoding String instances.
        aAttributes - The attributes or null if all attributes are to be processed in alphabetical order.
      • DynamicTypeSegment

        public DynamicTypeSegment​(T aValue,
                                  int aLengthWidth,
                                  org.refcodes.numerical.Endianess aEndianess,
                                  String... aAttributes)
        Constructs the DynamicTypeSegment with the given properties as well as with the TransmissionMetrics.DEFAULT_ENCODING. It is pre-initialized with the given value as of fromType(Object, String...).
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aValue - The data structure's value.
        aLengthWidth - The width (in bytes) to be used for length values.
        aEndianess - The Endianess to be used for (length) values.
        aAttributes - The attributes or null if all attributes are to be processed in alphabetical order.
      • DynamicTypeSegment

        public DynamicTypeSegment​(T aValue,
                                  TransmissionMetrics aTransmissionMetrics)
        Constructs the DynamicTypeSegment with the given properties. It is pre-initialized with the given value as of fromType(Object). The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aValue - The data structure's value.
        aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
      • DynamicTypeSegment

        public DynamicTypeSegment​(T aValue,
                                  TransmissionMetrics aTransmissionMetrics,
                                  String... aAttributes)
        Constructs the DynamicTypeSegment with the given properties. It is pre-initialized with the given value as of fromType(Object, String...). The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aValue - The data structure's value.
        aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
        aAttributes - The attributes or null if all attributes are to be processed in alphabetical order.
      • DynamicTypeSegment

        public DynamicTypeSegment​(TransmissionMetrics aTransmissionMetrics)
        Constructs the DynamicTypeSegment with the given properties. The configuration attributes are taken from the TransmissionMetrics configuration object, though only those attributes are supported which are also supported by the other constructors!
        Parameters:
        aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
    • Method Detail

      • getLength

        public int getLength()
        Determines the overall length of this Transmission. In case of nested Transmission instances, all length values from all sub-segments are accumulated to the result as well.
        Specified by:
        getLength in interface org.refcodes.mixin.LengthAccessor
        Specified by:
        getLength in interface Transmission
        Returns:
        The (overall) length of the Transmission (including any sub-segments).
      • transmitTo

        public void transmitTo​(OutputStream aOutputStream,
                               InputStream aReturnStream)
                        throws IOException
        Transmits the Sequence representing the implementing type's instance to the given OutputStream. Implementations providing error correction methods use the provided feedback InputStream to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.
        Specified by:
        transmitTo in interface Transmission
        Parameters:
        aOutputStream - The OutputStream where to write this instance's Sequence to.
        aReturnStream - An InputStream being the return channel to handle "stop-and-wait ARQ" or the like in case of a bidirectional connection. Can be null in case we have a unidirectional connection.
        Throws:
        IOException - thrown in case writing data to the OutputStream caused problems.
      • toSimpleTypeMap

        public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
        Returns the SimpleTypeMap representation of this Transmission. In case this Transmission has Transmission children, then the children are queried as well and contained in the resulting SimpleTypeMap. The aliases of the according Transmission instances represent the resulting path to a Transmission's final simple type.
        Specified by:
        toSimpleTypeMap in interface Transmission
        Returns:
        The SimpleTypeMap representing this Transmission and (if any) its children, with the according aliases forming the paths to the Transmission's values.
      • toType

        public <T> T toType​(Class<T> aType,
                            String... aAttributes)
                     throws IllegalArgumentException
        Constructs an instance for the given type T. . The attributes of the given data structure are processed using the predefined set of attributes in their according order
        Specified by:
        toType in interface DynamicTypeTransmission
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aType - The data structure's type.
        aAttributes - The attributes or null if all attributes are to be processed in alphabetical order.
        Returns:
        The according type constructed from the DynamicTypeSection's Sequence.
        Throws:
        IllegalArgumentException - thrown in case the DynamicTypeSection's Sequence does not match the provided type.
      • fromType

        public <T> void fromType​(T aValue)
        Constructs the DynamicTypeSection's Sequence from the given type's instance . The attributes of the given data structure are processed all and in alphabetical order. For specifying a predefined set of attributes and their order, please invoke DynamicTypeTransmission.fromType(Object, String[]) instead!
        Specified by:
        fromType in interface DynamicTypeTransmission
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aValue - The data structure's value.
      • fromType

        public <T> void fromType​(T aValue,
                                 String... aAttributes)
        Constructs an instance for the given type T. . The attributes of the given data structure are processed using the predefined set of attributes in their according order.
        Specified by:
        fromType in interface DynamicTypeTransmission
        Type Parameters:
        T - The type of the data structure representing the body.
        Parameters:
        aValue - The data structure's value.
        aAttributes - The attributes or null if all attributes are to be processed in alphabetical order.
      • getEncoding

        public Charset getEncoding()
        Specified by:
        getEncoding in interface org.refcodes.mixin.EncodingAccessor<Charset>
      • getEndianess

        public org.refcodes.numerical.Endianess getEndianess()
        Specified by:
        getEndianess in interface org.refcodes.numerical.EndianessAccessor
      • getLengthWidth

        public int getLengthWidth()
        Retrieves the length width (in bytes) from the length width (in bytes) property.
        Specified by:
        getLengthWidth in interface LengthWidthAccessor
        Returns:
        The length width (in bytes) stored by the length width (in bytes) property.
      • fromTransmission

        public int fromTransmission​(Sequence aSequence,
                                    int aOffset)
                             throws TransmissionException
        (Re-)initializes this instance with the the given Sequence data.
        Specified by:
        fromTransmission in interface Segment
        Parameters:
        aSequence - The Sequence data from which to (re-)initialize this instance.
        aOffset - The offset where to start processing the provided Sequence.
        Returns:
        The index after the last offset into the given Sequence processed by this method.
        Throws:
        TransmissionException - thrown in case a given Sequence cannot be processed.
      • receiveFrom

        public void receiveFrom​(InputStream aInputStream,
                                OutputStream aReturnStream)
                         throws IOException,
                                TransmissionException
        (Re-)initializes this instance by receiving the according Sequence from the given InputStream. Implementations providing error correction methods use the provided feedback OutputStream to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.
        Specified by:
        receiveFrom in interface Segment
        Parameters:
        aInputStream - The InputStream from which to read the instance's (re-)initialization Sequence from.
        aReturnStream - An OutputStream being the return channel to handle "stop-and-wait ARQ" or the like in case of a bidirectional connection. Can be null in case we have a unidirectional connection.
        Throws:
        IOException - thrown in case reading data from the InputStream caused problems.
        TransmissionException - thrown in case a given transmission cannot be processed.