Class StringSegment

java.lang.Object
org.refcodes.serial.StringSegment
All Implemented Interfaces:
Serializable, org.refcodes.mixin.AliasAccessor, org.refcodes.mixin.EncodingAccessor<Charset>, org.refcodes.mixin.LengthAccessor, org.refcodes.mixin.PayloadAccessor<String>, org.refcodes.mixin.PayloadAccessor.PayloadBuilder<String,PayloadTransmission<String>>, org.refcodes.mixin.PayloadAccessor.PayloadMutator<String>, org.refcodes.mixin.PayloadAccessor.PayloadProperty<String>, org.refcodes.mixin.Schemable, PayloadSegment<String>, PayloadTransmission<String>, Segment, Transmission

public class StringSegment extends Object implements PayloadSegment<String>, org.refcodes.mixin.EncodingAccessor<Charset>
The StringSegment is an implementation of a Section carrying a String as payload. By default, if not otherwise specified, the TransmissionMetrics.DEFAULT_ENCODING encoding is used for encoding and decoding String instances.
See Also:
  • Constructor Details

    • StringSegment

      public StringSegment()
      Instantiates a new string segment.
    • StringSegment

      public StringSegment(TransmissionMetrics aTransmissionMetrics)
      Constructs an according instance from the given configuration. 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.
    • StringSegment

      public StringSegment(String aValue, TransmissionMetrics aTransmissionMetrics)
      Constructs an according instance from the given configuration. 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:
      aValue - The payload to be contained by the StringSegment.
      aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
    • StringSegment

      public StringSegment(String aAlias, String aValue, TransmissionMetrics aTransmissionMetrics)
      Constructs an according instance from the given configuration. 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 instance.
      aValue - The payload to be contained by the StringSegment.
      aTransmissionMetrics - The TransmissionMetrics to be used for configuring this instance.
    • StringSegment

      public StringSegment(String aValue)
      Constructs a StringSegment with the given String payload being encoded with the TransmissionMetrics.DEFAULT_ENCODING.
      Parameters:
      aValue - The payload to be contained by this StringSegment.
    • StringSegment

      public StringSegment(Charset aEncoding)
      Constructs a StringSegment with a payload expected to be encoded with the given Charset.
      Parameters:
      aEncoding - The Charset to be used for encoding and decoding String instances.
    • StringSegment

      public StringSegment(String aValue, Charset aEncoding)
      Constructs a StringSegment with the given String payload being encoded with the given Charset.
      Parameters:
      aValue - The payload to be contained by this StringSegment.
      aEncoding - The Charset to be used for encoding the String.
    • StringSegment

      public StringSegment(String aAlias, String aValue)
      Constructs a StringSegment with the given String payload being encoded with the TransmissionMetrics.DEFAULT_ENCODING.
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aValue - The payload to be contained by this StringSegment.
    • StringSegment

      public StringSegment(String aAlias, String aValue, Charset aEncoding)
      Constructs a StringSegment with the given String payload being encoded with the given Charset.
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aValue - The payload to be contained by this StringSegment.
      aEncoding - The Charset to be used for encoding the String.
    • StringSegment

      public StringSegment(org.refcodes.numerical.Endianess aEndianess)
      Constructs an empty allocation value with a width of TransmissionMetrics.DEFAULT_LENGTH_WIDTH bytes used to specify the decoratee's length and the provided Endianess representation of the decoratee's length.
      Parameters:
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(int aLengthWidth)
      Constructs an empty allocation value with the given number of bytes used to specify the decoratee's length and a TransmissionMetrics.DEFAULT_ENDIANESS endian representation of the decoratee's length.
      Parameters:
      aLengthWidth - The width (in bytes) to be used for length values.
    • StringSegment

      public StringSegment(int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
      Constructs an empty allocation value with the given number of bytes used to specify the decoratee's length and the provided Endianess representation of the decoratee's length.
      Parameters:
      aLengthWidth - The width (in bytes) to be used for length values.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(String aValue, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with the given String payload being encoded with the TransmissionMetrics.DEFAULT_ENCODING.
      Parameters:
      aValue - The payload to be contained by this StringSegment.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with a payload expected to be encoded with the given Charset.
      Parameters:
      aEncoding - The Charset to be used for encoding and decoding String instances.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(String aValue, Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with the given String payload being encoded with the given Charset.
      Parameters:
      aValue - The payload to be contained by this StringSegment.
      aEncoding - The Charset to be used for encoding the String.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(String aAlias, String aValue, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with the given String payload being encoded with the TransmissionMetrics.DEFAULT_ENCODING.
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aValue - The payload to be contained by this StringSegment.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(String aAlias, String aValue, Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with the given String payload being encoded with the given Charset.
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aValue - The payload to be contained by this StringSegment.
      aEncoding - The Charset to be used for encoding the String.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(String aValue, int aLengthWidth)
      Constructs a StringSegment with the given Stringpayload* being encoded with the TransmissionMetrics.DEFAULT_ENCODING.**
      Parameters:
      aValue - The payload to be contained by this StringSegment.
      aLengthWidth - The width (in bytes) to be used for length values.
    • StringSegment

      public StringSegment(Charset aEncoding, int aLengthWidth)
      Constructs a StringSegment with a payload expected to be encoded with the given Charset.
      Parameters:
      aEncoding - The Charset to be used for encoding and decoding String instances.
      aLengthWidth - The width (in bytes) to be used for length values.
    • StringSegment

      public StringSegment(String aValue, Charset aEncoding, int aLengthWidth)
      Constructs a StringSegment with the given String payload being encoded with the given Charset.
      Parameters:
      aValue - The payload to be contained by this StringSegment.
      aEncoding - The Charset to be used for encoding the String.
      aLengthWidth - The width (in bytes) to be used for length values.
    • StringSegment

      public StringSegment(String aAlias, String aValue, int aLengthWidth)
      Constructs a StringSegment with the given String payload being encoded with the TransmissionMetrics.DEFAULT_ENCODING.
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aValue - The payload to be contained by this StringSegment.
      aLengthWidth - The width (in bytes) to be used for length values.
    • StringSegment

      public StringSegment(String aAlias, String aValue, Charset aEncoding, int aLengthWidth)
      Constructs a StringSegment with the given String payload being encoded with the given Charset.
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aValue - The payload to be contained by this StringSegment.
      aEncoding - The Charset to be used for encoding the String.
      aLengthWidth - The width (in bytes) to be used for length values.
    • StringSegment

      public StringSegment(String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with the given String payload being encoded with the TransmissionMetrics.DEFAULT_ENCODING.
      Parameters:
      aValue - The payload to be contained by this StringSegment.
      aLengthWidth - The width (in bytes) to be used for length values.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with a payload expected to be encoded with the given Charset.
      Parameters:
      aEncoding - The Charset to be used for encoding and decoding String instances.
      aLengthWidth - The width (in bytes) to be used for length values.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(String aValue, Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with the given String payload being encoded with the given Charset.
      Parameters:
      aValue - The payload to be contained by this StringSegment.
      aEncoding - The Charset to be used for encoding the String.
      aLengthWidth - The width (in bytes) to be used for length values.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(String aAlias, String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with the given String payload being encoded with the TransmissionMetrics.DEFAULT_ENCODING.
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aValue - The payload to be contained by this StringSegment.
      aLengthWidth - The width (in bytes) to be used for length values.
      aEndianess - The Endianess to be used for length values.
    • StringSegment

      public StringSegment(String aAlias, String aValue, Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
      Constructs a StringSegment with the given String payload being encoded with the given Charset.
      Parameters:
      aAlias - The alias which identifies the content of this segment.
      aValue - The payload to be contained by this StringSegment.
      aEncoding - The Charset to be used for encoding the String.
      aLengthWidth - The width (in bytes) to be used for length values.
      aEndianess - The Endianess to be used for length values.
  • Method Details

    • toSequence

      public Sequence toSequence()
      Provides the Sequence representation of this Transmission. In case of nested Transmission instances, all Sequence representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nested Transmission instances) may be backed by the returned Sequence.
      Specified by:
      toSequence in interface Transmission
      Returns:
      The according instance's Sequence.
    • 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.
    • 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.
    • toSchema

      public SerialSchema toSchema()
      Retrieves the SerialSchema representing the Transmission. Retrieving a SerialSchema is useful when analyzing and debugging data structures such as a AllocSectionDecoratorSegment instance to help document, learn and verify on the structure (as well as the content) of that very AllocSectionDecoratorSegment.
      Specified by:
      toSchema in interface org.refcodes.mixin.Schemable
      Specified by:
      toSchema in interface Transmission
      Returns:
      The SerialSchema representation of the implementing type for debugging and verification (or documentation) purposes.
    • withPayload

      public StringSegment withPayload(String aValue)
      Specified by:
      withPayload in interface org.refcodes.mixin.PayloadAccessor.PayloadBuilder<String,PayloadTransmission<String>>
    • getEncoding

      public Charset getEncoding()
      Specified by:
      getEncoding in interface org.refcodes.mixin.EncodingAccessor<Charset>
    • 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.
    • getAlias

      public String getAlias()
      Specified by:
      getAlias in interface org.refcodes.mixin.AliasAccessor
    • getPayload

      public String getPayload()
      Specified by:
      getPayload in interface org.refcodes.mixin.PayloadAccessor<String>
    • setPayload

      public void setPayload(String aPayload)
      Specified by:
      setPayload in interface org.refcodes.mixin.PayloadAccessor.PayloadMutator<String>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static StringSegment.Builder builder()
      Creates builder to build StringSegment.
      Returns:
      created builder