- 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>,PayloadSegment<String>,PayloadTransmission<String>,Segment,Transmission
public class StringSegment extends Object implements PayloadSegment<String>, org.refcodes.mixin.EncodingAccessor<Charset>
TheStringSegmentis an implementation of aSectioncarrying aStringas payload. By default, if not otherwise specified, theTransmissionMetrics.DEFAULT_ENCODINGencoding is used for encoding and decodingStringinstances.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStringSegment.BuilderBuilder to buildStringSegment.-
Nested classes/interfaces inherited from interface org.refcodes.mixin.AliasAccessor
org.refcodes.mixin.AliasAccessor.AliasBuilder<B extends org.refcodes.mixin.AliasAccessor.AliasBuilder<B>>, org.refcodes.mixin.AliasAccessor.AliasMutator, org.refcodes.mixin.AliasAccessor.AliasProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.EncodingAccessor
org.refcodes.mixin.EncodingAccessor.EncodingBuilder<E extends Object,B extends org.refcodes.mixin.EncodingAccessor.EncodingBuilder<E,B>>, org.refcodes.mixin.EncodingAccessor.EncodingMutator<E extends Object>, org.refcodes.mixin.EncodingAccessor.EncodingProperty<E extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.LengthAccessor
org.refcodes.mixin.LengthAccessor.LengthBuilder<B extends org.refcodes.mixin.LengthAccessor.LengthBuilder<B>>, org.refcodes.mixin.LengthAccessor.LengthMutator, org.refcodes.mixin.LengthAccessor.LengthProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.PayloadAccessor
org.refcodes.mixin.PayloadAccessor.PayloadBuilder<P extends Object,B extends org.refcodes.mixin.PayloadAccessor.PayloadBuilder<P,B>>, org.refcodes.mixin.PayloadAccessor.PayloadMutator<P extends Object>, org.refcodes.mixin.PayloadAccessor.PayloadProperty<P extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Segment
Segment.SegmentMixin
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Constructor Summary
Constructors Constructor Description StringSegment()Instantiates a new string segment.StringSegment(int aLengthWidth)Constructs an empty allocation value with the given number of bytes used to specify the decoratee's length and aTransmissionMetrics.DEFAULT_ENDIANESSendian representation of the decoratee's length.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 providedEndianessrepresentation of the decoratee's length.StringSegment(String aValue)Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.StringSegment(String aValue, int aLengthWidth)Constructs aStringSegmentwith the givenStringpayload* being encoded with theTransmissionMetrics.DEFAULT_ENCODING.StringSegment(String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.StringSegment(String aAlias, String aValue)Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.StringSegment(String aAlias, String aValue, int aLengthWidth)Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.StringSegment(String aAlias, String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.StringSegment(String aAlias, String aValue, Charset aEncoding)StringSegment(String aAlias, String aValue, Charset aEncoding, int aLengthWidth)StringSegment(String aAlias, String aValue, Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)StringSegment(String aAlias, String aValue, Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)StringSegment(String aAlias, String aValue, org.refcodes.numerical.Endianess aEndianess)Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.StringSegment(String aAlias, String aValue, TransmissionMetrics aTransmissionMetrics)Constructs an according instance from the given configuration.StringSegment(String aValue, Charset aEncoding)StringSegment(String aValue, Charset aEncoding, int aLengthWidth)StringSegment(String aValue, Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)StringSegment(String aValue, Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)StringSegment(String aValue, org.refcodes.numerical.Endianess aEndianess)Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.StringSegment(String aValue, TransmissionMetrics aTransmissionMetrics)Constructs an according instance from the given configuration.StringSegment(Charset aEncoding)Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset.StringSegment(Charset aEncoding, int aLengthWidth)Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset.StringSegment(Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset.StringSegment(Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset.StringSegment(org.refcodes.numerical.Endianess aEndianess)Constructs an empty allocation value with a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTHbytes used to specify the decoratee's length and the providedEndianessrepresentation of the decoratee's length.StringSegment(TransmissionMetrics aTransmissionMetrics)Constructs an according instance from the given configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringSegment.Builderbuilder()Creates builder to buildStringSegment.intfromTransmission(Sequence aSequence, int aOffset)(Re-)initializes this instance with the the givenSequencedata.StringgetAlias()CharsetgetEncoding()intgetLength()Determines the overall length of thisTransmission.StringgetPayload()voidreceiveFrom(InputStream aInputStream, OutputStream aReturnStream)(Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream.voidsetPayload(String aPayload)SchematoSchema()Retrieves theSchemarepresenting theTransmission.SequencetoSequence()Provides theSequencerepresentation of thisTransmission.org.refcodes.struct.SimpleTypeMaptoSimpleTypeMap()Returns theSimpleTypeMaprepresentation of thisTransmission.StringtoString()voidtransmitTo(OutputStream aOutputStream, InputStream aReturnStream)Transmits theSequencerepresenting the implementing type's instance to the givenOutputStream.StringSegmentwithPayload(String aValue)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.serial.Segment
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFrom
-
Methods inherited from interface org.refcodes.serial.Transmission
transmitTo, transmitTo
-
-
-
-
Constructor Detail
-
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 theTransmissionMetricsconfiguration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aTransmissionMetrics- TheTransmissionMetricsto 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 theTransmissionMetricsconfiguration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aValue- The payload to be contained by theStringSegment.aTransmissionMetrics- TheTransmissionMetricsto 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 theTransmissionMetricsconfiguration 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 theStringSegment.aTransmissionMetrics- TheTransmissionMetricsto be used for configuring this instance.
-
StringSegment
public StringSegment(String aValue)
Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.- Parameters:
aValue- The payload to be contained by thisStringSegment.
-
StringSegment
public StringSegment(Charset aEncoding)
Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset.
-
StringSegment
public StringSegment(String aValue, Charset aEncoding)
- Parameters:
aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.
-
StringSegment
public StringSegment(String aAlias, String aValue)
Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.- Parameters:
aAlias- The alias which identifies the content of this segment.aValue- The payload to be contained by thisStringSegment.
-
StringSegment
public StringSegment(String aAlias, String aValue, Charset aEncoding)
- Parameters:
aAlias- The alias which identifies the content of this segment.aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.
-
StringSegment
public StringSegment(org.refcodes.numerical.Endianess aEndianess)
Constructs an empty allocation value with a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTHbytes used to specify the decoratee's length and the providedEndianessrepresentation of the decoratee's length.- Parameters:
aEndianess- TheEndianessto 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 aTransmissionMetrics.DEFAULT_ENDIANESSendian 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 providedEndianessrepresentation of the decoratee's length.- Parameters:
aLengthWidth- The width (in bytes) to be used for length values.aEndianess- TheEndianessto be used for length values.
-
StringSegment
public StringSegment(String aValue, org.refcodes.numerical.Endianess aEndianess)
Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.- Parameters:
aValue- The payload to be contained by thisStringSegment.aEndianess- TheEndianessto be used for length values.
-
StringSegment
public StringSegment(Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)
Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset.
-
StringSegment
public StringSegment(String aValue, Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)
- Parameters:
aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.aEndianess- TheEndianessto be used for length values.
-
StringSegment
public StringSegment(String aAlias, String aValue, org.refcodes.numerical.Endianess aEndianess)
Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.- Parameters:
aAlias- The alias which identifies the content of this segment.aValue- The payload to be contained by thisStringSegment.aEndianess- TheEndianessto be used for length values.
-
StringSegment
public StringSegment(String aAlias, String aValue, Charset aEncoding, org.refcodes.numerical.Endianess aEndianess)
- Parameters:
aAlias- The alias which identifies the content of this segment.aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.aEndianess- TheEndianessto be used for length values.
-
StringSegment
public StringSegment(String aValue, int aLengthWidth)
Constructs aStringSegmentwith the givenStringpayload* being encoded with theTransmissionMetrics.DEFAULT_ENCODING.**- Parameters:
aValue- The payload to be contained by thisStringSegment.aLengthWidth- The width (in bytes) to be used for length values.
-
StringSegment
public StringSegment(Charset aEncoding, int aLengthWidth)
Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset.
-
StringSegment
public StringSegment(String aValue, Charset aEncoding, int aLengthWidth)
- Parameters:
aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.aLengthWidth- The width (in bytes) to be used for length values.
-
StringSegment
public StringSegment(String aAlias, String aValue, int aLengthWidth)
Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.- Parameters:
aAlias- The alias which identifies the content of this segment.aValue- The payload to be contained by thisStringSegment.aLengthWidth- The width (in bytes) to be used for length values.
-
StringSegment
public StringSegment(String aAlias, String aValue, Charset aEncoding, int aLengthWidth)
- Parameters:
aAlias- The alias which identifies the content of this segment.aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.aLengthWidth- The width (in bytes) to be used for length values.
-
StringSegment
public StringSegment(String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.- Parameters:
aValue- The payload to be contained by thisStringSegment.aLengthWidth- The width (in bytes) to be used for length values.aEndianess- TheEndianessto be used for length values.
-
StringSegment
public StringSegment(Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset.
-
StringSegment
public StringSegment(String aValue, Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
- Parameters:
aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.aLengthWidth- The width (in bytes) to be used for length values.aEndianess- TheEndianessto be used for length values.
-
StringSegment
public StringSegment(String aAlias, String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.- Parameters:
aAlias- The alias which identifies the content of this segment.aValue- The payload to be contained by thisStringSegment.aLengthWidth- The width (in bytes) to be used for length values.aEndianess- TheEndianessto be used for length values.
-
StringSegment
public StringSegment(String aAlias, String aValue, Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess)
- Parameters:
aAlias- The alias which identifies the content of this segment.aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.aLengthWidth- The width (in bytes) to be used for length values.aEndianess- TheEndianessto be used for length values.
-
-
Method Detail
-
toSequence
public Sequence toSequence()
Provides theSequencerepresentation of thisTransmission. In case of nestedTransmissioninstances, allSequencerepresentations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmissioninstances) may be backed by the returnedSequence.- Specified by:
toSequencein interfaceTransmission- Returns:
- The according instance's
Sequence.
-
fromTransmission
public int fromTransmission(Sequence aSequence, int aOffset) throws TransmissionException
(Re-)initializes this instance with the the givenSequencedata.- Specified by:
fromTransmissionin interfaceSegment- Parameters:
aSequence- TheSequencedata from which to (re-)initialize this instance.aOffset- The offset where to start processing the providedSequence.- Returns:
- The index after the last offset into the given
Sequenceprocessed by this method. - Throws:
TransmissionException- thrown in case a givenSequencecannot be processed.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, OutputStream aReturnStream) throws IOException, TransmissionException
(Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream. Implementations providing error correction methods use the provided feedbackOutputStreamto do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.- Specified by:
receiveFromin interfaceSegment- Parameters:
aInputStream- TheInputStreamfrom which to read the instance's (re-)initializationSequencefrom.aReturnStream- AnOutputStreambeing 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 theInputStreamcaused problems.TransmissionException- thrown in case a given transmission cannot be processed.
-
getLength
public int getLength()
Determines the overall length of thisTransmission. In case of nestedTransmissioninstances, all length values from all sub-segments are accumulated to the result as well.- Specified by:
getLengthin interfaceorg.refcodes.mixin.LengthAccessor- Specified by:
getLengthin interfaceTransmission- Returns:
- The (overall) length of the
Transmission(including any sub-segments).
-
transmitTo
public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
Transmits theSequencerepresenting the implementing type's instance to the givenOutputStream. Implementations providing error correction methods use the provided feedbackInputStreamto do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.- Specified by:
transmitToin interfaceTransmission- Parameters:
aOutputStream- TheOutputStreamwhere to write this instance'sSequenceto.aReturnStream- AnInputStreambeing 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 theOutputStreamcaused problems.
-
toSchema
public Schema toSchema()
Retrieves theSchemarepresenting theTransmission. Retrieving aSchemais useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegmentinstance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment.- Specified by:
toSchemain interfaceTransmission- Returns:
- The
Schemarepresentation of the implementing type for debugging and verification (or documentation) purposes.
-
withPayload
public StringSegment withPayload(String aValue)
- Specified by:
withPayloadin interfaceorg.refcodes.mixin.PayloadAccessor.PayloadBuilder<String,PayloadTransmission<String>>
-
getEncoding
public Charset getEncoding()
- Specified by:
getEncodingin interfaceorg.refcodes.mixin.EncodingAccessor<Charset>
-
toSimpleTypeMap
public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
Returns theSimpleTypeMaprepresentation of thisTransmission. In case this Transmission hasTransmissionchildren, then the children are queried as well and contained in the resultingSimpleTypeMap. The aliases of the accordingTransmissioninstances represent the resulting path to aTransmission's final simple type.- Specified by:
toSimpleTypeMapin interfaceTransmission- Returns:
- The
SimpleTypeMaprepresenting thisTransmissionand (if any) its children, with the according aliases forming the paths to theTransmission's values.
-
getAlias
public String getAlias()
- Specified by:
getAliasin interfaceorg.refcodes.mixin.AliasAccessor
-
getPayload
public String getPayload()
- Specified by:
getPayloadin interfaceorg.refcodes.mixin.PayloadAccessor<String>
-
setPayload
public void setPayload(String aPayload)
- Specified by:
setPayloadin interfaceorg.refcodes.mixin.PayloadAccessor.PayloadMutator<String>
-
builder
public static StringSegment.Builder builder()
Creates builder to buildStringSegment.- Returns:
- created builder
-
-