Module org.refcodes.serial
Package org.refcodes.serial
Class AbstractReferenceeLengthSegment<REFERENCEE extends Transmission>
java.lang.Object
org.refcodes.serial.AbstractReferenceeLengthSegment<REFERENCEE>
- Type Parameters:
REFERENCEE- the generic type
- All Implemented Interfaces:
Serializable,org.refcodes.mixin.LengthAccessor,org.refcodes.mixin.Resetable,org.refcodes.numerical.EndianessAccessor,org.refcodes.schema.Schemable,AllocLengthAccessor,LengthWidthAccessor,Segment,Transmission,Transmission.TransmissionMixin
- Direct Known Subclasses:
AbstractLengthDecoratorSegment,AllocSegmentHead,LengthSegment
public abstract class AbstractReferenceeLengthSegment<REFERENCEE extends Transmission>
extends Object
implements Segment, Transmission.TransmissionMixin, LengthWidthAccessor, org.refcodes.numerical.EndianessAccessor, AllocLengthAccessor
The
AbstractReferenceeLengthSegment represents a allocated length
value as of the referenced Transmission element's length.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.serial.AllocLengthAccessor
AllocLengthAccessor.AllocLengthBuilder<B extends AllocLengthAccessor.AllocLengthBuilder<B>>, AllocLengthAccessor.AllocLengthMutator, AllocLengthAccessor.AllocLengthPropertyNested 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.EndianessPropertyNested 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.serial.LengthWidthAccessor
LengthWidthAccessor.LengthWidthBuilder<B extends LengthWidthAccessor.LengthWidthBuilder<B>>, LengthWidthAccessor.LengthWidthMutator, LengthWidthAccessor.LengthWidthPropertyNested classes/interfaces inherited from interface org.refcodes.serial.Segment
Segment.SegmentMixinNested classes/interfaces inherited from interface org.refcodes.serial.Transmission
Transmission.TransmissionMixin -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected org.refcodes.numerical.Endianessprotected intprotected REFERENCEEstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty allocation value with a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTHbytes used to specify the decoratee's length and aTransmissionMetrics.DEFAULT_ENDIANESSendian representation of the decoratee's length.AbstractReferenceeLengthSegment(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.AbstractReferenceeLengthSegment(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.AbstractReferenceeLengthSegment(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.AbstractReferenceeLengthSegment(TransmissionMetrics aTransmissionMetrics) Constructs an according instance.AbstractReferenceeLengthSegment(REFERENCEE aReferencee) Constructs the allocation value with the given decoratee and a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTHbytes used to specify the decoratee's length aTransmissionMetrics.DEFAULT_ENDIANESSendian representation of the decoratee's length.AbstractReferenceeLengthSegment(REFERENCEE aReferencee, int aLengthWidth) Constructs the allocation value with the given decoratee and with the given number of bytes used to specify the decoratee's length and aTransmissionMetrics.DEFAULT_ENDIANESSendian representation of the decoratee's length.AbstractReferenceeLengthSegment(REFERENCEE aReferencee, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess) Constructs the allocation value with the given decoratee and with the given number of bytes used to specify the decoratee's length and the providedEndianessrepresentation of the decoratee's length.AbstractReferenceeLengthSegment(REFERENCEE aReferencee, org.refcodes.numerical.Endianess aEndianess) Constructs the allocation value with the given decoratee and a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTHbytes used to specify the decoratee's length and the providedEndianessrepresentation of the decoratee's length.AbstractReferenceeLengthSegment(REFERENCEE aReferencee, TransmissionMetrics aTransmissionMetrics) Constructs an according instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanintfromTransmission(Sequence aSequence, int aOffset) (Re-)initializes this instance with the the givenSequencedata.intReturns the allocated length in bytes declared by this instance.org.refcodes.numerical.EndianessintDetermines the overall length of thisTransmission.intRetrieves the length width (in bytes) from the length width (in bytes) property.inthashCode()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(!)toSchema()Provides theSequencerepresentation of thisTransmission.org.refcodes.struct.SimpleTypeMapReturns theSimpleTypeMaprepresentation of thisTransmission.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.refcodes.serial.Segment
fromTransmission, fromTransmission, fromTransmission, receiveFrom, receiveFromMethods inherited from interface org.refcodes.serial.Transmission
transmitTo, transmitToMethods inherited from interface org.refcodes.serial.Transmission.TransmissionMixin
transmitTo
-
Field Details
-
ALLOC_LENGTH
- See Also:
-
ALLOC_LENGTH_WIDTH
- See Also:
-
ENDIANESS
- See Also:
-
_endianess
protected org.refcodes.numerical.Endianess _endianess -
_lengthWidth
protected int _lengthWidth -
_allocLength
protected int _allocLength -
_referencee
-
-
Constructor Details
-
AbstractReferenceeLengthSegment
Constructs an according instance. 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.
-
AbstractReferenceeLengthSegment
public AbstractReferenceeLengthSegment(REFERENCEE aReferencee, TransmissionMetrics aTransmissionMetrics) Constructs an according instance. The configuration attributes are taken from theTransmissionMetricsconfiguration object, though only those attributes are supported which are also supported by the other constructors!- Parameters:
aReferencee- The referencedTransmissionwhich's length is to be used.aTransmissionMetrics- TheTransmissionMetricsto be used for configuring this instance.
-
AbstractReferenceeLengthSegment
public AbstractReferenceeLengthSegment()Constructs an empty allocation value with a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTHbytes used to specify the decoratee's length and aTransmissionMetrics.DEFAULT_ENDIANESSendian representation of the decoratee's length. -
AbstractReferenceeLengthSegment
public AbstractReferenceeLengthSegment(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.
-
AbstractReferenceeLengthSegment
public AbstractReferenceeLengthSegment(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.
-
AbstractReferenceeLengthSegment
public AbstractReferenceeLengthSegment(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.
-
AbstractReferenceeLengthSegment
Constructs the allocation value with the given decoratee and a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTHbytes used to specify the decoratee's length aTransmissionMetrics.DEFAULT_ENDIANESSendian representation of the decoratee's length.- Parameters:
aReferencee- The decoratee used for this allocation value.
-
AbstractReferenceeLengthSegment
public AbstractReferenceeLengthSegment(REFERENCEE aReferencee, org.refcodes.numerical.Endianess aEndianess) Constructs the allocation value with the given decoratee and a width ofTransmissionMetrics.DEFAULT_LENGTH_WIDTHbytes used to specify the decoratee's length and the providedEndianessrepresentation of the decoratee's length.- Parameters:
aReferencee- The decoratee used for this allocation value.aEndianess- TheEndianessto be used for length values.
-
AbstractReferenceeLengthSegment
Constructs the allocation value with the given decoratee and with the given number of bytes used to specify the decoratee's length and aTransmissionMetrics.DEFAULT_ENDIANESSendian representation of the decoratee's length.- Parameters:
aReferencee- The decoratee used for this allocation value.aLengthWidth- The width (in bytes) to be used for length values.
-
AbstractReferenceeLengthSegment
public AbstractReferenceeLengthSegment(REFERENCEE aReferencee, int aLengthWidth, org.refcodes.numerical.Endianess aEndianess) Constructs the allocation value with the given decoratee and with the given number of bytes used to specify the decoratee's length and the providedEndianessrepresentation of the decoratee's length.- Parameters:
aReferencee- The decoratee used for this allocation value.aLengthWidth- The width (in bytes) to be used for length values.aEndianess- TheEndianessto be used for length values.
-
-
Method Details
-
getLengthWidth
public int getLengthWidth()Retrieves the length width (in bytes) from the length width (in bytes) property.- Specified by:
getLengthWidthin interfaceLengthWidthAccessor- Returns:
- The length width (in bytes) stored by the length width (in bytes) property.
-
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).
-
getEndianess
public org.refcodes.numerical.Endianess getEndianess()- Specified by:
getEndianessin interfaceorg.refcodes.numerical.EndianessAccessor
-
getAllocLength
public int getAllocLength()Returns the allocated length in bytes declared by this instance.- Specified by:
getAllocLengthin interfaceAllocLengthAccessor- Returns:
- The allocated length in bytes.
-
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
-
hashCode
public int hashCode() -
equals
-
toString
-
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.
-