Class SerialP2PMessage

  • All Implemented Interfaces:
    Serializable, org.refcodes.mixin.BodyAccessor<org.refcodes.serial.Sequence>, org.refcodes.mixin.HeaderAccessor<SerialP2PHeader>, org.refcodes.mixin.LengthAccessor, org.refcodes.mixin.MagicNumberAccessor<Integer>, org.refcodes.mixin.Message<SerialP2PHeader,​org.refcodes.serial.Sequence>, org.refcodes.p2p.P2PMessage<Integer,​SerialP2PHeader,​org.refcodes.serial.Sequence>, org.refcodes.serial.Segment, org.refcodes.serial.Segment.SegmentMixin, org.refcodes.serial.Transmission, org.refcodes.serial.Transmission.TransmissionMixin

    public class SerialP2PMessage
    extends org.refcodes.p2p.AbstractP2PMessage<Integer,​SerialP2PHeader,​org.refcodes.serial.Sequence>
    implements org.refcodes.p2p.P2PMessage<Integer,​SerialP2PHeader,​org.refcodes.serial.Sequence>, org.refcodes.serial.Segment, org.refcodes.serial.Segment.SegmentMixin, org.refcodes.mixin.MagicNumberAccessor<Integer>
    Basic implementation of the P2PMessage optimized for local area microcontroller wiring (networks) and microcontroller memory layout.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.refcodes.mixin.BodyAccessor

        org.refcodes.mixin.BodyAccessor.BodyBuilder<T extends Object,​B extends org.refcodes.mixin.BodyAccessor.BodyBuilder<T,​B>>, org.refcodes.mixin.BodyAccessor.BodyMutator<T extends Object>, org.refcodes.mixin.BodyAccessor.BodyProperty<T extends Object>
      • Nested classes/interfaces inherited from interface org.refcodes.mixin.HeaderAccessor

        org.refcodes.mixin.HeaderAccessor.HeaderBuilder<T extends Object,​B extends org.refcodes.mixin.HeaderAccessor.HeaderBuilder<T,​B>>, org.refcodes.mixin.HeaderAccessor.HeaderMutator<T extends Object>, org.refcodes.mixin.HeaderAccessor.HeaderProperty<T extends Object>
      • 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.mixin.MagicNumberAccessor

        org.refcodes.mixin.MagicNumberAccessor.MagicNumberBuilder<T extends Object,​B extends org.refcodes.mixin.MagicNumberAccessor.MagicNumberBuilder<T,​B>>, org.refcodes.mixin.MagicNumberAccessor.MagicNumberMutator<T extends Object>, org.refcodes.mixin.MagicNumberAccessor.MagicNumberProperty<T extends Object>
      • Nested classes/interfaces inherited from interface org.refcodes.serial.Segment

        org.refcodes.serial.Segment.SegmentMixin
      • Nested classes/interfaces inherited from interface org.refcodes.serial.Transmission

        org.refcodes.serial.Transmission.TransmissionMixin
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_MAGIC_NUMBER
      Default magic number in case none has been specified.
      • Fields inherited from class org.refcodes.p2p.AbstractP2PMessage

        _body, _header
    • Field Detail

      • DEFAULT_MAGIC_NUMBER

        public static final int DEFAULT_MAGIC_NUMBER
        Default magic number in case none has been specified.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SerialP2PMessage

        public SerialP2PMessage​(org.refcodes.serial.TransmissionMetrics aTransmissionMetrics)
        Constructs an empty SerialP2PMessage.
        Parameters:
        aTransmissionMetrics - the a TransmissionMetrics to use.
      • SerialP2PMessage

        public SerialP2PMessage​(int aDestination,
                                P aPayload)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Type Parameters:
        P - The type of the payload in question.
        Parameters:
        aDestination - The destination locator of the peer being addressed.
        aPayload - The payload to be sent.
      • SerialP2PMessage

        public SerialP2PMessage​(int aDestination,
                                P aPayload,
                                org.refcodes.serial.TransmissionMetrics aTransmissionMetrics)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Type Parameters:
        P - The type of the payload in question.
        Parameters:
        aDestination - The destination locator of the peer being addressed.
        aPayload - The payload to be sent.
        aTransmissionMetrics - the a TransmissionMetrics to use.
      • SerialP2PMessage

        public SerialP2PMessage​(int aMagicNumber,
                                int aDestination,
                                P aPayload)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Type Parameters:
        P - The type of the payload in question.
        Parameters:
        aMagicNumber - The magic bytes to prefix to this message when being transmitted.
        aDestination - The destination locator of the peer being addressed.
        aPayload - The payload to be sent.
      • SerialP2PMessage

        public SerialP2PMessage​(int aMagicNumber,
                                int aDestination,
                                P aPayload,
                                org.refcodes.serial.TransmissionMetrics aTransmissionMetrics)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Type Parameters:
        P - The type of the payload in question.
        Parameters:
        aMagicNumber - The magic bytes to prefix to this message when being transmitted.
        aDestination - The destination locator of the peer being addressed.
        aPayload - The payload to be sent.
        aTransmissionMetrics - the a TransmissionMetrics to use.
      • SerialP2PMessage

        public SerialP2PMessage​(int aDestination,
                                org.refcodes.serial.Sequence aPayload)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Parameters:
        aDestination - The destination locator of the peer being addressed.
        aPayload - the a payload
      • SerialP2PMessage

        public SerialP2PMessage​(int aDestination,
                                org.refcodes.serial.Sequence aPayload,
                                org.refcodes.serial.TransmissionMetrics aTransmissionMetrics)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Parameters:
        aDestination - The destination locator of the peer being addressed.
        aPayload - the a payload
        aTransmissionMetrics - the a TransmissionMetrics to use.
      • SerialP2PMessage

        public SerialP2PMessage​(int aMagicNumber,
                                int aDestination,
                                org.refcodes.serial.Segment aPayload)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Parameters:
        aMagicNumber - The magic bytes to prefix to this message when being transmitted.
        aDestination - The destination locator of the peer being addressed.
        aPayload - the a payload
      • SerialP2PMessage

        public SerialP2PMessage​(int aMagicNumber,
                                int aDestination,
                                org.refcodes.serial.Segment aPayload,
                                org.refcodes.serial.TransmissionMetrics aTransmissionMetrics)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Parameters:
        aMagicNumber - The magic bytes to prefix to this message when being transmitted.
        aDestination - The destination locator of the peer being addressed.
        aPayload - the a payload
        aTransmissionMetrics - the a TransmissionMetrics to use.
      • SerialP2PMessage

        public SerialP2PMessage​(int aDestination,
                                org.refcodes.serial.Segment aPayload)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Parameters:
        aDestination - The destination locator of the peer being addressed.
        aPayload - the a payload
      • SerialP2PMessage

        public SerialP2PMessage​(int aDestination,
                                org.refcodes.serial.Segment aPayload,
                                org.refcodes.serial.TransmissionMetrics aTransmissionMetrics)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Parameters:
        aDestination - The destination locator of the peer being addressed.
        aPayload - the a payload
        aTransmissionMetrics - the a TransmissionMetrics to use.
      • SerialP2PMessage

        public SerialP2PMessage​(int aMagicNumber,
                                int aDestination,
                                org.refcodes.serial.Sequence aPayload)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Parameters:
        aMagicNumber - The magic bytes to prefix to this message when being transmitted.
        aDestination - The destination locator of the peer being addressed.
        aPayload - The payload to be sent.
      • SerialP2PMessage

        public SerialP2PMessage​(int aMagicNumber,
                                int aDestination,
                                org.refcodes.serial.Sequence aPayload,
                                org.refcodes.serial.TransmissionMetrics aTransmissionMetrics)
        Constructs an SerialP2PMessage. The source is added upon transmission as first stop-over.
        Parameters:
        aMagicNumber - The magic bytes to prefix to this message when being transmitted.
        aDestination - The destination locator of the peer being addressed.
        aPayload - The payload to be sent.
        aTransmissionMetrics - the a TransmissionMetrics to use.
    • Method Detail

      • toSequence

        public org.refcodes.serial.Sequence toSequence()
        Specified by:
        toSequence in interface org.refcodes.serial.Transmission
      • transmitTo

        public void transmitTo​(OutputStream aOutputStream,
                               InputStream aReturnStream)
                        throws IOException
        Specified by:
        transmitTo in interface org.refcodes.serial.Transmission
        Specified by:
        transmitTo in interface org.refcodes.serial.Transmission.TransmissionMixin
        Throws:
        IOException
      • fromTransmission

        public int fromTransmission​(org.refcodes.serial.Sequence aSequence,
                                    int aOffset)
                             throws org.refcodes.serial.TransmissionException
        Specified by:
        fromTransmission in interface org.refcodes.serial.Segment
        Throws:
        org.refcodes.serial.TransmissionException
      • receiveFrom

        public void receiveFrom​(InputStream aInputStream,
                                OutputStream aFeedbackStream)
                         throws IOException,
                                org.refcodes.serial.TransmissionException
        Specified by:
        receiveFrom in interface org.refcodes.serial.Segment
        Specified by:
        receiveFrom in interface org.refcodes.serial.Segment.SegmentMixin
        Throws:
        IOException
        org.refcodes.serial.TransmissionException
      • toSchema

        public org.refcodes.serial.Schema toSchema()
        Specified by:
        toSchema in interface org.refcodes.serial.Transmission
      • getLength

        public int getLength()
        Specified by:
        getLength in interface org.refcodes.mixin.LengthAccessor
        Specified by:
        getLength in interface org.refcodes.serial.Transmission
      • toSimpleTypeMap

        public org.refcodes.struct.SimpleTypeMap toSimpleTypeMap()
        Specified by:
        toSimpleTypeMap in interface org.refcodes.serial.Transmission
      • getPayload

        public <P> P getPayload​(Class<P> aResponseType)
                         throws org.refcodes.exception.UnmarshalException
        Specified by:
        getPayload in interface org.refcodes.p2p.P2PMessage<Integer,​SerialP2PHeader,​org.refcodes.serial.Sequence>
        Throws:
        org.refcodes.exception.UnmarshalException
      • getMagicNumber

        public Integer getMagicNumber()
        Specified by:
        getMagicNumber in interface org.refcodes.mixin.MagicNumberAccessor<Integer>