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.Resetable,org.refcodes.schema.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:
-
Nested Class Summary
Nested ClassesNested 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.AliasPropertyNested 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.LengthPropertyNested 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.SegmentMixinNested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates 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
Modifier and TypeMethodDescriptionstatic StringSegment.Builderbuilder()Creates builder to buildStringSegment.intfromTransmission(Sequence aSequence, int aOffset) (Re-)initializes this instance with the the givenSequencedata.getAlias()intDetermines the overall length of thisTransmission.voidreceiveFrom(InputStream aInputStream, OutputStream aReturnStream) (Re-)initializes this instance by receiving the accordingSequencefrom the givenInputStream.voidreset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!)voidsetPayload(String aPayload) toSchema()Provides theSequencerepresentation of thisTransmission.org.refcodes.struct.SimpleTypeMapReturns theSimpleTypeMaprepresentation of thisTransmission.toString()voidtransmitTo(OutputStream aOutputStream, InputStream aReturnStream) Transmits theSequencerepresenting the implementing type's instance to the givenOutputStream.withPayload(String aValue) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.refcodes.mixin.PayloadAccessor
getPayloadOrMethods inherited from interface org.refcodes.mixin.PayloadAccessor.PayloadProperty
letPayloadMethods inherited from interface org.refcodes.serial.Segment
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFromMethods inherited from interface org.refcodes.serial.Transmission
transmitTo, transmitTo
-
Constructor Details
-
StringSegment
public StringSegment()Instantiates a new string segment. -
StringSegment
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
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
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
Constructs aStringSegmentwith the givenStringpayload being encoded with theTransmissionMetrics.DEFAULT_ENCODING.- Parameters:
aValue- The payload to be contained by thisStringSegment.
-
StringSegment
Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset. -
StringSegment
- Parameters:
aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.
-
StringSegment
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
- 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
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
Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset. -
StringSegment
- Parameters:
aValue- The payload to be contained by thisStringSegment.aEncoding- TheCharsetto be used for encoding theString.aEndianess- TheEndianessto be used for length values.
-
StringSegment
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
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
Constructs aStringSegmentwith a payload expected to be encoded with the givenCharset. -
StringSegment
- 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
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
- 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
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 Details
-
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
(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
(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
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.
-
reset
public void reset()Resets any dynamic data (e.g. values such as payloads or checksums) and must not(!) reset any configurations or settings required to produce the dynamic data (e.g. theTransmissionMetrics).- Specified by:
resetin interfaceorg.refcodes.mixin.Resetable- Specified by:
resetin interfaceTransmission
-
toSchema
- Specified by:
toSchemain interfaceorg.refcodes.schema.Schemable- Specified by:
toSchemain interfaceTransmission
-
withPayload
- Specified by:
withPayloadin interfaceorg.refcodes.mixin.PayloadAccessor.PayloadBuilder<String,PayloadTransmission<String>>
-
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
- Specified by:
getAliasin interfaceorg.refcodes.mixin.AliasAccessor
-
getPayload
- Specified by:
getPayloadin interfaceorg.refcodes.mixin.PayloadAccessor<String>
-
setPayload
- Specified by:
setPayloadin interfaceorg.refcodes.mixin.PayloadAccessor.PayloadMutator<String>
-
toString
-
builder
Creates builder to buildStringSegment.- Returns:
- created builder
-