Module org.refcodes.serial
Package org.refcodes.serial
Class AbstractCrcTransmissionDecorator<DECORATEE extends Transmission>
- java.lang.Object
-
- org.refcodes.numerical.AbstractCrcMixin
-
- org.refcodes.serial.AbstractCrcTransmissionDecorator<DECORATEE>
-
- Type Parameters:
DECORATEE
- The decoratee type describing the according subclass to be enriched with a CRC checksum.
- All Implemented Interfaces:
Serializable
,org.refcodes.mixin.DecorateeAccessor<DECORATEE>
,org.refcodes.mixin.LengthAccessor
,org.refcodes.numerical.CrcAlgorithmAccessor
,org.refcodes.numerical.CrcChecksumAccessor
,org.refcodes.numerical.CrcChecksumConcatenateModeAccessor
,org.refcodes.numerical.CrcChecksumValidationModeAccessor
,org.refcodes.numerical.CrcMixin
,org.refcodes.numerical.EndianessAccessor
,Transmission
,Transmission.TransmissionMixin
- Direct Known Subclasses:
CrcSectionDecorator
,CrcSegmentDecorator
public abstract class AbstractCrcTransmissionDecorator<DECORATEE extends Transmission> extends org.refcodes.numerical.AbstractCrcMixin implements Transmission, Transmission.TransmissionMixin, org.refcodes.mixin.DecorateeAccessor<DECORATEE>, org.refcodes.numerical.CrcMixin, org.refcodes.numerical.CrcChecksumAccessor
AAbstractCrcTransmissionDecorator
wraps aTransmission
instance and enriches theTransmission
with a CRC checksum.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.numerical.CrcAlgorithmAccessor
org.refcodes.numerical.CrcAlgorithmAccessor.CrcAlgorithmBuilder<B extends org.refcodes.numerical.CrcAlgorithmAccessor.CrcAlgorithmBuilder<B>>, org.refcodes.numerical.CrcAlgorithmAccessor.CrcAlgorithmMutator, org.refcodes.numerical.CrcAlgorithmAccessor.CrcAlgorithmProperty
-
Nested classes/interfaces inherited from interface org.refcodes.numerical.CrcChecksumAccessor
org.refcodes.numerical.CrcChecksumAccessor.CrcChecksumBuilder<B extends org.refcodes.numerical.CrcChecksumAccessor.CrcChecksumBuilder<B>>, org.refcodes.numerical.CrcChecksumAccessor.CrcChecksumMutator, org.refcodes.numerical.CrcChecksumAccessor.CrcChecksumProperty
-
Nested classes/interfaces inherited from interface org.refcodes.numerical.CrcChecksumConcatenateModeAccessor
org.refcodes.numerical.CrcChecksumConcatenateModeAccessor.CrcChecksumConcatenateModeBuilder<B extends org.refcodes.numerical.CrcChecksumConcatenateModeAccessor.CrcChecksumConcatenateModeBuilder<B>>, org.refcodes.numerical.CrcChecksumConcatenateModeAccessor.CrcChecksumConcatenateModeMutator, org.refcodes.numerical.CrcChecksumConcatenateModeAccessor.CrcChecksumConcatenateModeProperty
-
Nested classes/interfaces inherited from interface org.refcodes.numerical.CrcChecksumValidationModeAccessor
org.refcodes.numerical.CrcChecksumValidationModeAccessor.CrcChecksumValidationModeBuilder<B extends org.refcodes.numerical.CrcChecksumValidationModeAccessor.CrcChecksumValidationModeBuilder<B>>, org.refcodes.numerical.CrcChecksumValidationModeAccessor.CrcChecksumValidationModeMutator, org.refcodes.numerical.CrcChecksumValidationModeAccessor.CrcChecksumValidationModeProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.DecorateeAccessor
org.refcodes.mixin.DecorateeAccessor.DecorateeBuilder<DECORATEE extends Object,B extends org.refcodes.mixin.DecorateeAccessor.DecorateeBuilder<DECORATEE,B>>, org.refcodes.mixin.DecorateeAccessor.DecorateeMutator<DECORATEE extends Object>, org.refcodes.mixin.DecorateeAccessor.DecorateeProperty<DECORATEE extends Object>
-
Nested classes/interfaces inherited from interface org.refcodes.numerical.EndianessAccessor
org.refcodes.numerical.EndianessAccessor.EndianessBuilder<B extends org.refcodes.numerical.EndianessAccessor.EndianessBuilder<B>>, org.refcodes.numerical.EndianessAccessor.EndianessMutator, org.refcodes.numerical.EndianessAccessor.EndianessProperty
-
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.serial.Transmission
Transmission.TransmissionMixin
-
-
Field Summary
Fields Modifier and Type Field Description protected long
_crcChecksum
protected DECORATEE
_decoratee
static String
CRC_ALGORITHM
static String
CRC_BYTE_WIDTH
static String
CRC_CHECKSUM
static String
CRC_CHECKSUM_BIG_ENDIAN_BYTES
static String
CRC_CHECKSUM_CONCATENATION_MODE
static String
CRC_CHECKSUM_HEX
static String
CRC_CHECKSUM_LITTLE_ENDIAN_BYTES
static String
CRC_ENDIANESS
-
Constructor Summary
Constructors Constructor Description AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode, org.refcodes.numerical.ChecksumValidationMode aCrcChecksumValidationMode)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode, org.refcodes.numerical.ChecksumValidationMode aCrcChecksumValidationMode, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
.AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
.AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.ChecksumValidationMode aCrcChecksumValidationMode)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.ChecksumValidationMode aCrcChecksumValidationMode, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
.AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
.AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance wrapping the givenTransmission
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
long
getCrcChecksum()
DECORATEE
getDecoratee()
int
getLength()
Determines the overall length of thisTransmission
.int
hashCode()
Schema
toSchema()
Retrieves theSchema
representing theTransmission
.Sequence
toSequence()
Provides theSequence
representation of thisTransmission
.org.refcodes.struct.SimpleTypeMap
toSimpleTypeMap()
Returns theSimpleTypeMap
representation of thisTransmission
.String
toString()
void
transmitTo(OutputStream aOutputStream, InputStream aReturnStream)
Transmits theSequence
representing the implementing type's instance to the givenOutputStream
.-
Methods inherited from class org.refcodes.numerical.AbstractCrcMixin
getCrcAlgorithm, getCrcChecksumConcatenateMode, getCrcChecksumValidationMode, getEndianess
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.numerical.CrcChecksumConcatenateModeAccessor
getCrcChecksumConcatenateMode
-
Methods inherited from interface org.refcodes.numerical.CrcChecksumValidationModeAccessor
getCrcChecksumValidationMode
-
Methods inherited from interface org.refcodes.serial.Transmission
transmitTo, transmitTo
-
-
-
-
Field Detail
-
CRC_ENDIANESS
public static final String CRC_ENDIANESS
- See Also:
- Constant Field Values
-
CRC_CHECKSUM
public static final String CRC_CHECKSUM
- See Also:
- Constant Field Values
-
CRC_CHECKSUM_HEX
public static final String CRC_CHECKSUM_HEX
- See Also:
- Constant Field Values
-
CRC_CHECKSUM_LITTLE_ENDIAN_BYTES
public static final String CRC_CHECKSUM_LITTLE_ENDIAN_BYTES
- See Also:
- Constant Field Values
-
CRC_CHECKSUM_BIG_ENDIAN_BYTES
public static final String CRC_CHECKSUM_BIG_ENDIAN_BYTES
- See Also:
- Constant Field Values
-
CRC_ALGORITHM
public static final String CRC_ALGORITHM
- See Also:
- Constant Field Values
-
CRC_BYTE_WIDTH
public static final String CRC_BYTE_WIDTH
- See Also:
- Constant Field Values
-
CRC_CHECKSUM_CONCATENATION_MODE
public static final String CRC_CHECKSUM_CONCATENATION_MODE
- See Also:
- Constant Field Values
-
_decoratee
protected DECORATEE extends Transmission _decoratee
-
_crcChecksum
protected long _crcChecksum
-
-
Constructor Detail
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, TransmissionMetrics aTransmissionMetrics)
Constructs an according instance wrapping the givenTransmission
. The configuration attributes are taken from theTransmissionMetrics
configuration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aTransmissionMetrics
- TheTransmissionMetrics
to be used for configuring this instance.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcAlgorithm
- TheCrcAlgorithm
to be used for CRC checksum calculation.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.ChecksumValidationMode aCrcChecksumValidationMode)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcAlgorithm
- TheCrcAlgorithm
to be used for CRC checksum calculation.aCrcChecksumValidationMode
- The mode of operation when validating provided CRC checksums against calculated ones.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
.- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcAlgorithm
- TheCrcAlgorithm
to be used for CRC checksum calculation.aEndianess
- TheEndianess
to use when calculating the CRC checksum.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.numerical.ChecksumValidationMode aCrcChecksumValidationMode, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
.- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcAlgorithm
- TheCrcAlgorithm
to be used for CRC checksum calculation.aCrcChecksumValidationMode
- The mode of operation when validating provided CRC checksums against calculated ones.aEndianess
- TheEndianess
to use when calculating the CRC checksum.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcChecksumConcatenateMode
- The mode of concatenation to for concatenating the decoratee'sSequence
with the according CRC checksum.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcChecksumConcatenateMode
- The mode of concatenation to for concatenating the decoratee'sSequence
with the according CRC checksum.aEndianess
- TheEndianess
to use when calculating the CRC checksum.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcAlgorithm
- TheCrcAlgorithm
to be used for CRC checksum calculation.aCrcChecksumConcatenateMode
- The mode of concatenation to for concatenating the decoratee'sSequence
with the according CRC checksum.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode, org.refcodes.numerical.ChecksumValidationMode aCrcChecksumValidationMode)
Constructs an according instance wrapping the givenTransmission
(usingTransmissionMetrics.DEFAULT_ENDIANESS
by default).- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcAlgorithm
- TheCrcAlgorithm
to be used for CRC checksum calculation.aCrcChecksumConcatenateMode
- The mode of concatenation to for concatenating the decoratee'sSequence
with the according CRC checksum.aCrcChecksumValidationMode
- The mode of operation when validating provided CRC checksums against calculated ones.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
.- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcAlgorithm
- TheCrcAlgorithm
to be used for CRC checksum calculation.aCrcChecksumConcatenateMode
- The mode of concatenation to for concatenating the decoratee'sSequence
with the according CRC checksum.aEndianess
- TheEndianess
to use when calculating the CRC checksum.
-
AbstractCrcTransmissionDecorator
public AbstractCrcTransmissionDecorator(DECORATEE aDecoratee, org.refcodes.numerical.CrcAlgorithm aCrcAlgorithm, org.refcodes.mixin.ConcatenateMode aCrcChecksumConcatenateMode, org.refcodes.numerical.ChecksumValidationMode aCrcChecksumValidationMode, org.refcodes.numerical.Endianess aEndianess)
Constructs an according instance wrapping the givenTransmission
.- Parameters:
aDecoratee
- TheTransmission
to be wrapped.aCrcAlgorithm
- TheCrcAlgorithm
to be used for CRC checksum calculation.aCrcChecksumConcatenateMode
- The mode of concatenation for concatenating the decoratee'sSequence
with the according CRC checksum.aCrcChecksumValidationMode
- The mode of operation when validating provided CRC checksums against calculated ones.aEndianess
- TheEndianess
to use when calculating the CRC checksum.
-
-
Method Detail
-
toSequence
public Sequence 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
.
-
transmitTo
public void transmitTo(OutputStream aOutputStream, InputStream aReturnStream) throws IOException
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
- Specified by:
transmitTo
in interfaceTransmission.TransmissionMixin
- 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.
-
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).
-
getDecoratee
public DECORATEE getDecoratee()
- Specified by:
getDecoratee
in interfaceorg.refcodes.mixin.DecorateeAccessor<DECORATEE extends Transmission>
-
getCrcChecksum
public long getCrcChecksum()
- Specified by:
getCrcChecksum
in interfaceorg.refcodes.numerical.CrcChecksumAccessor
-
toSchema
public Schema toSchema()
Retrieves theSchema
representing theTransmission
. Retrieving aSchema
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 interfaceTransmission
- Returns:
- The
Schema
representation of the implementing type for debugging and verification (or documentation) purposes.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classorg.refcodes.numerical.AbstractCrcMixin
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classorg.refcodes.numerical.AbstractCrcMixin
-
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.
-
-