- java.lang.Object
-
- org.refcodes.serial.AcknowledgeSegment
-
- All Implemented Interfaces:
Serializable
,org.refcodes.mixin.LengthAccessor
,org.refcodes.mixin.MagicBytesAccessor
,MagicBytesAccessor
,Segment
,SequenceNumberAccessor
,Transmission
,Transmission.TransmissionMixin
public class AcknowledgeSegment extends Object implements Segment, Transmission.TransmissionMixin, SequenceNumberAccessor, MagicBytesAccessor
TheAcknowledgeSegment
representsSegment
transporting a cargo and providing a sequence number, CRC checksums as well as length declarations.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
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.MagicBytesAccessor
MagicBytesAccessor.MagicBytesBuilder<B extends MagicBytesAccessor.MagicBytesBuilder<B>>, MagicBytesAccessor.MagicBytesMutator, MagicBytesAccessor.MagicBytesProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Segment
Segment.SegmentMixin
-
Nested classes/interfaces inherited from interface org.refcodes.serial.SequenceNumberAccessor
SequenceNumberAccessor.SequenceNumberBuilder<B extends SequenceNumberAccessor.SequenceNumberBuilder<B>>, SequenceNumberAccessor.SequenceNumberMutator, SequenceNumberAccessor.SequenceNumberProperty
-
Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin
-
-
Field Summary
Fields Modifier and Type Field Description protected Segment
_delegatee
-
Constructor Summary
Constructors Constructor Description AcknowledgeSegment()
Instantiates a newAcknowledgeSegment
.AcknowledgeSegment(int aSequenceNumber)
Instantiates a newAcknowledgeSegment
for the given sequence number.AcknowledgeSegment(int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newAcknowledgeSegment
for the given sequence number.AcknowledgeSegment(TransmissionMetrics aTransmissionMetrics)
Instantiates a newAcknowledgeSegment
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
int
fromTransmission(Sequence aSequence, int aOffset)
(Re-)initializes this instance with the the givenSequence
data.int
getLength()
Determines the overall length of thisTransmission
.byte[]
getMagicBytes()
int
getSequenceNumber()
Retrieves the sequence number from the sequence number property.int
hashCode()
void
receiveFrom(InputStream aInputStream, OutputStream aReturnStream)
(Re-)initializes this instance by receiving the accordingSequence
from the givenInputStream
.Schema
toSchema()
Retrieves theSchema
representing theTransmission
.org.refcodes.struct.SimpleTypeMap
toSimpleTypeMap()
Returns theSimpleTypeMap
representation of thisTransmission
.String
toString()
Sequence
toTransmission()
Provides theSequence
representation of thisTransmission
.void
transmitTo(OutputStream aOutputStream, InputStream aReturnStream)
Transmits theSequence
representing the implementing type's instance to the givenOutputStream
.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, 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
-
-
-
-
Field Detail
-
_delegatee
protected Segment _delegatee
-
-
Constructor Detail
-
AcknowledgeSegment
public AcknowledgeSegment(int aSequenceNumber)
Instantiates a newAcknowledgeSegment
for the given sequence number.- Parameters:
aSequenceNumber
- The sequence number to be assigned to theAcknowledgeSegment
.
-
AcknowledgeSegment
public AcknowledgeSegment(int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newAcknowledgeSegment
for the given sequence number.- Parameters:
aSequenceNumber
- The sequence number to be assigned to theAcknowledgeSegment
.aTransmissionMetrics
- TheTransmissionMetrics
to use.
-
AcknowledgeSegment
public AcknowledgeSegment()
Instantiates a newAcknowledgeSegment
.
-
AcknowledgeSegment
public AcknowledgeSegment(TransmissionMetrics aTransmissionMetrics)
Instantiates a newAcknowledgeSegment
.- Parameters:
aTransmissionMetrics
- TheTransmissionMetrics
to use.
-
-
Method Detail
-
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).
-
toTransmission
public Sequence toTransmission()
Provides theSequence
representation of thisTransmission
. In case of nestedTransmission
instances, allSequence
representations from all sub-segments are accumulated to the result as well.- Specified by:
toTransmission
in interfaceTransmission
- Returns:
- The according instance's
Sequence
.
-
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.
-
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.
-
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.
-
fromTransmission
public int fromTransmission(Sequence aSequence, int aOffset) throws TransmissionException
(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.
-
getSequenceNumber
public int getSequenceNumber()
Retrieves the sequence number from the sequence number property.- Specified by:
getSequenceNumber
in interfaceSequenceNumberAccessor
- Returns:
- The sequence number stored by the sequence number property.
-
getMagicBytes
public byte[] getMagicBytes()
- Specified by:
getMagicBytes
in interfaceorg.refcodes.mixin.MagicBytesAccessor
-
-