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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EIEIODataMessage.Header
EIEIO header for data packets. -
Constructor Summary
Constructors Constructor Description EIEIODataMessage(EIEIOType eieioType)
Create a data message.EIEIODataMessage(EIEIOType eieioType, byte count, ByteBuffer data, Short keyPrefix, Integer payloadPrefix, Integer timestamp, EIEIOPrefix prefixType)
Create a data message. -
Method Summary
Modifier and Type Method Description void
addElement(AbstractDataElement element)
Add an element to the message.void
addKey(int key)
Adds a key to the packet.void
addKeyAndPayload(int key, int payload)
Adds a key and payload to the packet.void
addToBuffer(ByteBuffer buffer)
Writes this message into the given buffer as a contiguous range of bytes.ByteBuffer
getData()
EIEIODataMessage.Header
getHeader()
int
getMaxNumElements()
int
getNumElements()
int
getSize()
Iterator<AbstractDataElement>
iterator()
int
minPacketLength()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface uk.ac.manchester.spinnaker.utils.MappableIterable
filter, first, first, map, nth, toCollectingMap, toCollectingMap, toCollectingMap, toCollectingMap, toList, toList, toMap, toMap, toSet, toSet
-
Constructor Details
-
EIEIODataMessage
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 interfaceEIEIOMessage<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 addpayload
- 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
- Returns:
- The raw data of this message.
-
addElement
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 headerIllegalStateException
- If the message was created to read data
-
addToBuffer
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 interfaceSerializableMessage
- Parameters:
buffer
- The buffer to write into.
-
iterator
- Specified by:
iterator
in interfaceIterable<AbstractDataElement>
-
getHeader
- Specified by:
getHeader
in interfaceEIEIOMessage<EIEIODataMessage.Header>
- Returns:
- the header of this message.
-