Class EIEIODataMessage

java.lang.Object
uk.ac.manchester.spinnaker.messages.eieio.EIEIODataMessage
All Implemented Interfaces:
Iterable<AbstractDataElement>, EIEIOMessage<EIEIODataMessage.Header>, SerializableMessage, MappableIterable<AbstractDataElement>

public class EIEIODataMessage
extends Object
implements EIEIOMessage<EIEIODataMessage.Header>, MappableIterable<AbstractDataElement>
An EIEIO message containing data.
Author:
Sergio Davies, Donal Fellows
  • Constructor Details

    • EIEIODataMessage

      public EIEIODataMessage​(EIEIOType eieioType)
      Create a data message.
      Parameters:
      eieioType - The type of data components in the message.
    • EIEIODataMessage

      public EIEIODataMessage​(EIEIOType eieioType, byte count, ByteBuffer data, Short keyPrefix, Integer payloadPrefix, Integer timestamp, EIEIOPrefix prefixType)
      Create a data message.
      Parameters:
      eieioType - The type of data components in the message.
      count - The number of data components in the message.
      data - The serialized data components.
      keyPrefix - Any key prefix to apply to the data components.
      payloadPrefix - The prefix to apply. Overridden by a non-null timestamp.
      timestamp - The timestamp base to apply.
      prefixType - The type of prefix to apply.
  • Method Details

    • minPacketLength

      public int minPacketLength()
      Specified by:
      minPacketLength in interface EIEIOMessage<EIEIODataMessage.Header>
      Returns:
      the minimum length of a message instance in bytes.
    • getMaxNumElements

      public int getMaxNumElements()
      Returns:
      The maximum number of elements that can fit in the packet.
    • getNumElements

      public int getNumElements()
      Returns:
      The number of elements in the packet.
    • getSize

      public int getSize()
      Returns:
      The size of the packet with the current contents.
    • addKeyAndPayload

      public void addKeyAndPayload​(int key, int payload)
      Adds a key and payload to the packet.
      Parameters:
      key - The key to add
      payload - The payload to add
      Throws:
      IllegalArgumentException - If the key or payload is too big for the format, or the format doesn't expect a payload
    • addKey

      public void addKey​(int key)
      Adds a key to the packet.
      Parameters:
      key - The key to add
      Throws:
      IllegalArgumentException - If the key is too big for the format, or the format expects a payload
    • getData

      public ByteBuffer getData()
      Returns:
      The raw data of this message.
    • addElement

      public void addElement​(AbstractDataElement element)
      Add an element to the message. The correct type of element must be added, depending on the header values.
      Parameters:
      element - The element to be added
      Throws:
      IllegalArgumentException - If the element is not compatible with the header
      IllegalStateException - If the message was created to read data
    • addToBuffer

      public void addToBuffer​(ByteBuffer buffer)
      Description copied from interface: SerializableMessage
      Writes this message into the given buffer as a contiguous range of bytes. This is so that a message can be sent. Implementors may assume that the buffer has been configured to be little-endian and that its position is at the point where they should begin writing. Once it has finished, the position should be immediately after the last byte written by this method.

      Calling this method should not update the internal state of the message. It should be possible to add the message to multiple buffers without special precautions by the caller.

      Specified by:
      addToBuffer in interface SerializableMessage
      Parameters:
      buffer - The buffer to write into.
    • iterator

      public Iterator<AbstractDataElement> iterator()
      Specified by:
      iterator in interface Iterable<AbstractDataElement>
    • getHeader

      public EIEIODataMessage.Header getHeader()
      Specified by:
      getHeader in interface EIEIOMessage<EIEIODataMessage.Header>
      Returns:
      the header of this message.