Interface Segment

All Superinterfaces:
org.refcodes.mixin.LengthAccessor, org.refcodes.mixin.Resetable, org.refcodes.mixin.Schemable, Serializable, Transmission
All Known Subinterfaces:
ArraySegment<SEGMENT>, DecoratorSegment<DECORATEE>, PayloadSegment<T>, Segment.SegmentMixin
All Known Implementing Classes:
AbstractLengthDecoratorSegment, AbstractPayloadSegment, AbstractReferenceeLengthSegment, AbstractSegmentDecorator, AllocSectionDecoratorSegment, AllocSegmentBody, AllocSegmentHead, AsciizArraySegment, AsciizSegment, AssertMagicBytesSegment, AssertMagicBytesSegmentDecorator, BooleanSegment, BreakerSegmentDecorator, ByteSegment, CipherSegmentDecorator, ComplexTypeSegment, CrcSegmentDecorator, DoubleSegment, DynamicTypeSegment, EnumSegment, FixedLengthSequenceSegment, FloatSegment, IntSegment, InvertibleSegmentDecorator, LengthSegment, LengthSegmentDecoratorSegment, LongSegment, MagicBytesSegment, MagicBytesSegmentDecorator, MagicBytesSegmentMultiplexer, NullSegment, NumberSegment, ReadyToReceiveSegmentDecorator, ReadyToSendSegmentDecorator, SegmentComposite, SequenceNumberSegment, ShortSegment, StopAndWaitPacketStreamSegmentDecorator, StopAndWaitSegmentDecorator, StringSegment

public interface Segment extends Transmission
The Segment interface enables an implementing type to provide a Sequence representation of itself or to transmit its Sequence representation through an OutputStream (with an optional feedback InputStream) as of Transmission.transmitTo(OutputStream, InputStream) and to initialize with a Sequence representation for itself or to receive a Sequence representation for itself through an InputStream (with an optional feedback OutputStream) as of receiveFrom(InputStream, OutputStream). A Segment has a predictable length or it can (by itself) determine itself's length.
  • Method Details

    • fromTransmission

      default int fromTransmission(byte[] aChunk) throws TransmissionException
      (Re-)initializes this instance with the the given byte array data.
      Parameters:
      aChunk - The byte array data from which to (re-)initialize this instance.
      Returns:
      The index after the last offset into the given byte array processed by this method.
      Throws:
      TransmissionException - thrown in case a given Sequence cannot be processed.
    • fromTransmission

      default int fromTransmission(Sequence aSequence) throws TransmissionException
      (Re-)initializes this instance with the the given Sequence data.
      Parameters:
      aSequence - The Sequence data from which to (re-)initialize this instance.
      Returns:
      The index after the last offset into the given Sequence processed by this method.
      Throws:
      TransmissionException - thrown in case a given Sequence cannot be processed.
    • fromTransmission

      default int fromTransmission(byte[] aChunk, int aOffset) throws TransmissionException
      (Re-)initializes this instance with the the given byte array data.
      Parameters:
      aChunk - The byte array data from which to (re-)initialize this instance.
      aOffset - The offset where to start processing the provided byte array.
      Returns:
      The index after the last offset into the given byte array processed by this method.
      Throws:
      TransmissionException - thrown in case a given Sequence cannot be processed.
    • fromTransmission

      int fromTransmission(Sequence aSequence, int aOffset) throws TransmissionException
      (Re-)initializes this instance with the the given Sequence data.
      Parameters:
      aSequence - The Sequence data from which to (re-)initialize this instance.
      aOffset - The offset where to start processing the provided Sequence.
      Returns:
      The index after the last offset into the given Sequence processed by this method.
      Throws:
      TransmissionException - thrown in case a given Sequence cannot be processed.
    • receiveFrom

      default void receiveFrom(InputStream aInputStream) throws IOException
      (Re-)initializes this instance by receiving the according Sequence from the given InputStream. This is a convenience method in case there is no feedback OutputStream available (actually the receiveFrom(InputStream, OutputStream) method is invoked with null for the feedback OutputStream). Override receiveFrom(InputStream, OutputStream) for your custom receiving functionality.
      Parameters:
      aInputStream - The InputStream from which to read the instance's (re-)initialization Sequence from.
      Throws:
      IOException - thrown in case reading data from the InputStream caused problems.
      TransmissionException - thrown in case a given transmission cannot be processed.
    • receiveFrom

      default void receiveFrom(SerialTransceiver aSerialTransceiver) throws IOException
      (Re-)initializes this instance by receiving the according Sequence from the given SerialTransceiver's InputStream. Implementations providing error correction methods use the provided SerialTransceiver's feedback OutputStream to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data. This is a convenience method (actually the receiveFrom(InputStream, OutputStream) method is invoked). Override receiveFrom(InputStream, OutputStream) for your custom receiving functionality.
      Parameters:
      aSerialTransceiver - The SerialTransceiver providing the InputStream where to read this instance's Sequence from and providing the OutputStream being the feedback channel to handle "stop-and-wait ARQ".
      Throws:
      IOException - thrown in case reading data from the InputStream caused problems.
      TransmissionException - thrown in case a given transmission cannot be processed.
    • receiveFrom

      void receiveFrom(InputStream aInputStream, OutputStream aReturnStream) throws IOException
      (Re-)initializes this instance by receiving the according Sequence from the given InputStream. Implementations providing error correction methods use the provided feedback OutputStream to do some sort of "stop-and-wait ARQ" or apply similar methods to ensure correctness of the received data.
      Parameters:
      aInputStream - The InputStream from which to read the instance's (re-)initialization Sequence from.
      aReturnStream - An OutputStream 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 the InputStream caused problems.
      TransmissionException - thrown in case a given transmission cannot be processed.