- java.lang.Object
-
- org.refcodes.serial.EnvelopeSegment
-
- All Implemented Interfaces:
Serializable
,org.refcodes.mixin.LengthAccessor
,org.refcodes.mixin.MagicBytesAccessor
,MagicBytesAccessor
,Segment
,SequenceNumberAccessor
,Transmission
,Transmission.TransmissionMixin
public class EnvelopeSegment extends Object implements Segment, Transmission.TransmissionMixin, SequenceNumberAccessor, MagicBytesAccessor
TheEnvelopeSegment
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
-
-
Constructor Summary
Constructors Constructor Description EnvelopeSegment()
Instantiates a newEnvelopeSegment
with a plainSequence
as payload.EnvelopeSegment(Section aCargoSection, int aSequenceNumber)
Instantiates a newEnvelopeSegment
containing the given cargoSection
.EnvelopeSegment(Section aCargoSection, int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
containing the given cargoSection
.EnvelopeSegment(Segment aCargoSegment, int aSequenceNumber)
Instantiates a newEnvelopeSegment
containing the given cargoSegment
.EnvelopeSegment(Segment aCargoSegment, int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
containing the given cargoSegment
.EnvelopeSegment(Sequence aCargoSequence, int aSequenceNumber)
Instantiates a newEnvelopeSegment
containing the given cargoSequence
.EnvelopeSegment(Sequence aCargoSequence, int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
containing the given cargoSequence
.EnvelopeSegment(TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
with a plainSequence
as payload ready to receive an according cargo.EnvelopeSegment(T aPayload, int aSequenceNumber)
Instantiates a newEnvelopeSegment
with the provided cargo'spayload.EnvelopeSegment(T aPayload, int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
with the provided payload.
-
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
.<SEGMENT extends Segment>
SEGMENTtoCargoSegment(SEGMENT aMessageSegment)
<T> T
toPayload(Class<T> aType)
Decodes the cargo's payload to an instance of the given type.<SEGMENT extends PayloadSegment<T>,T>
TtoPayload(SEGMENT aMessageSegment)
Extracts the payload from thisEnvelopeSegment
's explicitly carriedTransmission
as of the provided preconfiguredPayloadSegment
.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
-
-
-
-
Constructor Detail
-
EnvelopeSegment
public EnvelopeSegment(T aPayload, int aSequenceNumber)
Instantiates a newEnvelopeSegment
with the provided cargo'spayload. It is up to theEnvelopeSegment
how to encode and (decode as oftoPayload(Class)
) the provided cargo's payload!- Type Parameters:
T
- The generic type of the payload to be carried byEnvelopeSegment
.- Parameters:
aPayload
- The payload to be carried by theEnvelopeSegment
.aSequenceNumber
- The sequence number to be assigned to theEnvelopeSegment
.
-
EnvelopeSegment
public EnvelopeSegment(T aPayload, int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
with the provided payload. It is up to theEnvelopeSegment
how to encode and (decode as oftoPayload(Class)
the provided payload!- Type Parameters:
T
- The generic type of the payload to be carried byEnvelopeSegment
.- Parameters:
aPayload
- The payload to be carried by theEnvelopeSegment
.aSequenceNumber
- The sequence number to be assigned to theEnvelopeSegment
.aTransmissionMetrics
- TheTransmissionMetrics
to use.
-
EnvelopeSegment
public EnvelopeSegment(Section aCargoSection, int aSequenceNumber)
Instantiates a newEnvelopeSegment
containing the given cargoSection
.- Parameters:
aCargoSection
- The cargoSection
to be carried.aSequenceNumber
- The sequence number to be assigned to theEnvelopeSegment
.
-
EnvelopeSegment
public EnvelopeSegment(Section aCargoSection, int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
containing the given cargoSection
.- Parameters:
aCargoSection
- The cargoSection
to be carried.aSequenceNumber
- The sequence number to be assigned to theEnvelopeSegment
.aTransmissionMetrics
- TheTransmissionMetrics
to use.
-
EnvelopeSegment
public EnvelopeSegment(Segment aCargoSegment, int aSequenceNumber)
Instantiates a newEnvelopeSegment
containing the given cargoSegment
.- Parameters:
aCargoSegment
- The cargoSegment
to be carried.aSequenceNumber
- The sequence number to be assigned to theEnvelopeSegment
.
-
EnvelopeSegment
public EnvelopeSegment(Segment aCargoSegment, int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
containing the given cargoSegment
.- Parameters:
aCargoSegment
- The cargoSegment
to be carried.aSequenceNumber
- The sequence number to be assigned to theEnvelopeSegment
.aTransmissionMetrics
- TheTransmissionMetrics
to use.
-
EnvelopeSegment
public EnvelopeSegment(Sequence aCargoSequence, int aSequenceNumber)
Instantiates a newEnvelopeSegment
containing the given cargoSequence
. The cargoSequence
is automatically labeled with the according cargo's length.- Parameters:
aCargoSequence
- The payload aSequence
.aSequenceNumber
- The sequence number to be assigned to theEnvelopeSegment
.
-
EnvelopeSegment
public EnvelopeSegment(Sequence aCargoSequence, int aSequenceNumber, TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
containing the given cargoSequence
. The cargoSequence
is automatically labeled with the according cargo's length.- Parameters:
aCargoSequence
- The cargoSequence
to be carried.aSequenceNumber
- The sequence number to be assigned to theEnvelopeSegment
.aTransmissionMetrics
- TheTransmissionMetrics
to use.
-
EnvelopeSegment
public EnvelopeSegment()
Instantiates a newEnvelopeSegment
with a plainSequence
as payload.
-
EnvelopeSegment
public EnvelopeSegment(TransmissionMetrics aTransmissionMetrics)
Instantiates a newEnvelopeSegment
with a plainSequence
as payload ready to receive an according cargo.- 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
-
toCargoSegment
public <SEGMENT extends Segment> SEGMENT toCargoSegment(SEGMENT aMessageSegment) throws TransmissionException
- Type Parameters:
SEGMENT
- The generic type of theSegment
to be extracted.- Parameters:
aMessageSegment
- The preconfiguredSegment
to be initialized from thisEnvelopeSegment
's explicitly carriedTransmission
.- Returns:
- The provided
Segment
initialized with thisEnvelopeSegment
's explicitly carriedTransmission
. - Throws:
TransmissionException
- thrown in case theTransmission
cannot be processed by the providedSegment
.
-
toPayload
public <SEGMENT extends PayloadSegment<T>,T> T toPayload(SEGMENT aMessageSegment) throws TransmissionException
Extracts the payload from thisEnvelopeSegment
's explicitly carriedTransmission
as of the provided preconfiguredPayloadSegment
.- Type Parameters:
SEGMENT
- The generic type of thePayloadSegment
from which to extract the payload.T
- The generic type of the actual payload.- Parameters:
aMessageSegment
- The preconfiguredPayloadSegment
to use for extracting the payload from thisEnvelopeSegment
- Returns:
- The payload as of this
EnvelopeSegment
's encapsulatedTransmission
. - Throws:
TransmissionException
- thrown in case theTransmission
cannot be processed by the providedPayloadSegment
.
-
toPayload
public <T> T toPayload(Class<T> aType) throws TransmissionException
Decodes the cargo's payload to an instance of the given type. The payload must be either be passed to one of the constructorsEnvelopeSegment(Object, int)
orEnvelopeSegment(Object, int, TransmissionMetrics)
or be encoded by aComplexTypeSegment
constructed with the sameTransmissionMetrics
as thisEnvelopeSegment
instance (and passed to either the constructorEnvelopeSegment(Segment, int)
orEnvelopeSegment(Segment, int, TransmissionMetrics)
).- Type Parameters:
T
- The generic type of the actual payload.- Parameters:
aType
- The type of the payload for which to retrieve an instance created from theEnvelopeSegment
instance's cargo.- Returns:
- The according instance created from the
EnvelopeSegment
instance's cargo. - Throws:
TransmissionException
- in case creating the given instance failed in case a givenTransmission
cannot be processed accordingly.
-
-