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:
-
Nested Class Summary
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
ConstructorDescriptionInstantiates 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_ENDIANESS
endian 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 providedEndianess
representation of the decoratee's length.StringSegment
(String aValue) Constructs aStringSegment
with the givenString
payload being encoded with theTransmissionMetrics.DEFAULT_ENCODING
.StringSegment
(String aValue, int aLengthWidth) Constructs aStringSegment
with the givenString
payload* being encoded with theTransmissionMetrics.DEFAULT_ENCODING
.StringSegment
(String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess) Constructs aStringSegment
with the givenString
payload being encoded with theTransmissionMetrics.DEFAULT_ENCODING
.StringSegment
(String aAlias, String aValue) Constructs aStringSegment
with the givenString
payload being encoded with theTransmissionMetrics.DEFAULT_ENCODING
.StringSegment
(String aAlias, String aValue, int aLengthWidth) Constructs aStringSegment
with the givenString
payload being encoded with theTransmissionMetrics.DEFAULT_ENCODING
.StringSegment
(String aAlias, String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess) Constructs aStringSegment
with the givenString
payload 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 aStringSegment
with the givenString
payload 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 aStringSegment
with the givenString
payload being encoded with theTransmissionMetrics.DEFAULT_ENCODING
.StringSegment
(String aValue, TransmissionMetrics aTransmissionMetrics) Constructs an according instance from the given configuration.StringSegment
(Charset aEncoding) Constructs aStringSegment
with a payload expected to be encoded with the givenCharset
.StringSegment
(Charset aEncoding, int aLengthWidth) Constructs aStringSegment
with a payload expected to be encoded with the givenCharset
.StringSegment
(Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess) Constructs aStringSegment
with a payload expected to be encoded with the givenCharset
.StringSegment
(Charset aEncoding, org.refcodes.numerical.Endianess aEndianess) Constructs aStringSegment
with 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_WIDTH
bytes used to specify the decoratee's length and the providedEndianess
representation of the decoratee's length.StringSegment
(TransmissionMetrics aTransmissionMetrics) Constructs an according instance from the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringSegment.Builder
builder()
Creates builder to buildStringSegment
.int
fromTransmission
(Sequence aSequence, int aOffset) (Re-)initializes this instance with the the givenSequence
data.getAlias()
int
Determines the overall length of thisTransmission
.void
receiveFrom
(InputStream aInputStream, OutputStream aReturnStream) (Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
.void
setPayload
(String aPayload) toSchema()
Retrieves theSerialSchema
representing theTransmission
.Provides theSequence
representation of thisTransmission
.org.refcodes.struct.SimpleTypeMap
Returns theSimpleTypeMap
representation of thisTransmission
.toString()
void
transmitTo
(OutputStream aOutputStream, InputStream aReturnStream) Transmits theSequence
representing 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, wait
Methods inherited from interface org.refcodes.mixin.PayloadAccessor
getPayloadOr
Methods inherited from interface org.refcodes.mixin.PayloadAccessor.PayloadProperty
letPayload
Methods inherited from interface org.refcodes.serial.Segment
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFrom
Methods 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 theTransmissionMetrics
configuration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
StringSegment
Constructs an according instance from the given configuration. The configuration attributes are taken from theTransmissionMetrics
configuration 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
- TheTransmissionMetrics
to be used for configuring this instance.
-
StringSegment
Constructs an according instance from the given configuration. The configuration attributes are taken from theTransmissionMetrics
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 theStringSegment
.aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
StringSegment
Constructs aStringSegment
with the givenString
payload being encoded with theTransmissionMetrics.DEFAULT_ENCODING
.- Parameters:
aValue
- The payload to be contained by thisStringSegment
.
-
StringSegment
Constructs aStringSegment
with a payload expected to be encoded with the givenCharset
. -
StringSegment
- Parameters:
aValue
- The payload to be contained by thisStringSegment
.aEncoding
- TheCharset
to be used for encoding theString
.
-
StringSegment
Constructs aStringSegment
with the givenString
payload 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
- TheCharset
to be used for encoding theString
.
-
StringSegment
public StringSegment(org.refcodes.numerical.Endianess aEndianess) Constructs an empty allocation value with a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTH
bytes used to specify the decoratee's length and the providedEndianess
representation of the decoratee's length.- Parameters:
aEndianess
- TheEndianess
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 aTransmissionMetrics.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 providedEndianess
representation of the decoratee's length.- Parameters:
aLengthWidth
- The width (in bytes) to be used for length values.aEndianess
- TheEndianess
to be used for length values.
-
StringSegment
Constructs aStringSegment
with the givenString
payload being encoded with theTransmissionMetrics.DEFAULT_ENCODING
.- Parameters:
aValue
- The payload to be contained by thisStringSegment
.aEndianess
- TheEndianess
to be used for length values.
-
StringSegment
Constructs aStringSegment
with a payload expected to be encoded with the givenCharset
. -
StringSegment
- Parameters:
aValue
- The payload to be contained by thisStringSegment
.aEncoding
- TheCharset
to be used for encoding theString
.aEndianess
- TheEndianess
to be used for length values.
-
StringSegment
Constructs aStringSegment
with the givenString
payload 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
- TheEndianess
to 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
- TheCharset
to be used for encoding theString
.aEndianess
- TheEndianess
to be used for length values.
-
StringSegment
Constructs aStringSegment
with the givenString
payload* 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 aStringSegment
with a payload expected to be encoded with the givenCharset
. -
StringSegment
- Parameters:
aValue
- The payload to be contained by thisStringSegment
.aEncoding
- TheCharset
to be used for encoding theString
.aLengthWidth
- The width (in bytes) to be used for length values.
-
StringSegment
Constructs aStringSegment
with the givenString
payload 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
- TheCharset
to be used for encoding theString
.aLengthWidth
- The width (in bytes) to be used for length values.
-
StringSegment
Constructs aStringSegment
with the givenString
payload 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
- TheEndianess
to be used for length values.
-
StringSegment
public StringSegment(Charset aEncoding, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess) Constructs aStringSegment
with 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
- TheCharset
to be used for encoding theString
.aLengthWidth
- The width (in bytes) to be used for length values.aEndianess
- TheEndianess
to be used for length values.
-
StringSegment
public StringSegment(String aAlias, String aValue, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess) Constructs aStringSegment
with the givenString
payload 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
- TheEndianess
to 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
- TheCharset
to be used for encoding theString
.aLengthWidth
- The width (in bytes) to be used for length values.aEndianess
- TheEndianess
to be used for length values.
-
-
Method Details
-
toSequence
Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well. Caution, the Transmission (or its nestedTransmission
instances) may be backed by the returnedSequence
.- Specified by:
toSequence
in interfaceTransmission
- Returns:
- The according instance's
Sequence
.
-
fromTransmission
(Re-)initializes this instance with the the givenSequence
data.- Specified by:
fromTransmission
in interfaceSegment
- Parameters:
aSequence
- TheSequence
data 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
Sequence
processed by this method. - Throws:
TransmissionException
- thrown in case a givenSequence
cannot be processed.
-
receiveFrom
public void receiveFrom(InputStream aInputStream, OutputStream aReturnStream) throws IOException, TransmissionException (Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
. Implementations providing error correction methods use the provided feedbackOutputStream
to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.- Specified by:
receiveFrom
in interfaceSegment
- Parameters:
aInputStream
- TheInputStream
from which to read the instance's (re-)initializationSequence
from.aReturnStream
- AnOutputStream
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 theInputStream
caused problems.TransmissionException
- thrown in case a given transmission cannot be processed.
-
getLength
public int getLength()Determines the overall length of thisTransmission
. In case of nestedTransmission
instances, all length values from all sub-segments are accumulated to the result as well.- Specified by:
getLength
in interfaceorg.refcodes.mixin.LengthAccessor
- Specified by:
getLength
in interfaceTransmission
- Returns:
- The (overall) length of the
Transmission
(including any sub-segments).
-
transmitTo
Transmits theSequence
representing the implementing type's instance to the givenOutputStream
. Implementations providing error correction methods use the provided feedbackInputStream
to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the transmitted data.- Specified by:
transmitTo
in interfaceTransmission
- Parameters:
aOutputStream
- TheOutputStream
where to write this instance'sSequence
to.aReturnStream
- AnInputStream
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 theOutputStream
caused problems.
-
toSchema
Retrieves theSerialSchema
representing theTransmission
. Retrieving aSerialSchema
is useful when analyzing and debugging data structures such as aAllocSectionDecoratorSegment
instance to help document, learn and verify on the structure (as well as the content) of that veryAllocSectionDecoratorSegment
.- Specified by:
toSchema
in interfaceorg.refcodes.mixin.Schemable
- Specified by:
toSchema
in interfaceTransmission
- Returns:
- The
SerialSchema
representation of the implementing type for debugging and verification (or documentation) purposes.
-
withPayload
- Specified by:
withPayload
in interfaceorg.refcodes.mixin.PayloadAccessor.PayloadBuilder<String,
PayloadTransmission<String>>
-
getEncoding
- Specified by:
getEncoding
in interfaceorg.refcodes.mixin.EncodingAccessor<Charset>
-
toSimpleTypeMap
public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()Returns theSimpleTypeMap
representation of thisTransmission
. In case this Transmission hasTransmission
children, then the children are queried as well and contained in the resultingSimpleTypeMap
. The aliases of the accordingTransmission
instances represent the resulting path to aTransmission
's final simple type.- Specified by:
toSimpleTypeMap
in interfaceTransmission
- Returns:
- The
SimpleTypeMap
representing thisTransmission
and (if any) its children, with the according aliases forming the paths to theTransmission
's values.
-
getAlias
- Specified by:
getAlias
in interfaceorg.refcodes.mixin.AliasAccessor
-
getPayload
- Specified by:
getPayload
in interfaceorg.refcodes.mixin.PayloadAccessor<String>
-
setPayload
- Specified by:
setPayload
in interfaceorg.refcodes.mixin.PayloadAccessor.PayloadMutator<String>
-
toString
-
builder
Creates builder to buildStringSegment
.- Returns:
- created builder
-