spinnman.messages.eieio.data_messages package

Module contents

class spinnman.messages.eieio.data_messages.AbstractDataElement

Bases: object

A marker interface for possible data elements in the EIEIO data packet.

abstract get_bytestring(eieio_type: EIEIOType) bytes[source]

Get a byte-string for the given type

Parameters:

eieio_type (EIEIOType) – The type of the message being written

Returns:

A byte-string for the element

Return type:

bytes

Raises:

SpinnmanInvalidParameterException – If the type is incompatible with the element

class spinnman.messages.eieio.data_messages.EIEIODataHeader(eieio_type: EIEIOType, tag: int = 0, prefix: int | None = None, prefix_type: EIEIOPrefix = EIEIOPrefix.LOWER_HALF_WORD, payload_base: int | None = None, is_time: bool = False, count: int = 0)

Bases: object

The header part of EIEIO data.

EIEIO header for data packets.

Parameters:
  • eieio_type (EIEIOType) – the type of message

  • tag (int) – the tag of the message (0 by default)

  • prefix (int or None) – the key prefix of the message or None if not prefixed

  • prefix_type (EIEIOPrefix) – the position of the prefix (upper or lower)

  • payload_base (int or None) – The base payload to be applied, or None if no base payload

  • is_time (bool) – True if the payloads should be taken to be timestamps, or False otherwise

  • count (int) – Count of the number of items in the packet

property bytestring: bytes

The byte-string of the header.

Return type:

bytes

property count: int

Count of the number of items in the packet

Return type:

int

property eieio_type: EIEIOType

Gets the eieio_type passed into the init.

Return type:

EIEIOType

static from_bytestring(data: bytes, offset: int) EIEIODataHeader[source]

Read an EIEIO data header from a byte-string.

Parameters:
  • data (bytes) – The byte-string to be read

  • offset (int) – The offset at which the data starts

Returns:

an EIEIO header

Return type:

EIEIODataHeader

static get_header_size(eieio_type, is_prefix=False, is_payload_base=False)[source]

Get the size of a header with the given parameters.

Parameters:
  • eieio_type (EIEIOType) – the type of message

  • is_prefix (bool) – True if there is a prefix, False otherwise

  • is_payload_base (bool) – True if there is a payload base, False otherwise

Returns:

The size of the header in bytes

Return type:

int

increment_count() None[source]

Increase the count by 1.

property is_time: bool

Gets the is_time value passed into the init.

Return type:

bool

property payload_base: int | None

Gets the payload_base value passed into the init (if applicable).

Return type:

int or None

property prefix: int | None

Gets prefix passed into the init (if applicable).

Return type:

int or None

property prefix_type: EIEIOPrefix

Gets the prefix_type passed into the init.

Return type:

EIEIOPrefix

reset_count() None[source]

Resets the count back to zero.

property size: int

Get the size of a header with the given parameters.

Return type:

int

property tag: int

Gets the tag value passed into the init.

Return type:

int

class spinnman.messages.eieio.data_messages.EIEIODataMessage(eieio_header, data=None, offset=0)

Bases: AbstractEIEIOMessage

An EIEIO Data message.

Parameters:
  • eieio_header (EIEIODataHeader) – The header of the message

  • data (bytes) – Optional data contained within the packet

  • offset (int) – Optional offset where the valid data starts

add_element(element: AbstractDataElement)[source]

Add an element to the message. The correct type of element must be added, depending on the header values.

Parameters:

element (AbstractDataElement) – The element to be added

Raises:
add_key(key: int)[source]

Add a key to the packet.

Parameters:

key (int) – The key to add

Raises:

SpinnmanInvalidParameterException – If the key is too big for the format, or the format expects a payload

add_key_and_payload(key: int, payload: int)[source]

Adds a key and payload to the packet.

Parameters:
  • key (int) – The key to add

  • payload (int) – The payload to add

Raises:

SpinnmanInvalidParameterException – If the key or payload is too big for the format, or the format doesn’t expect a payload

property bytestring: bytes

The bytes of the message.

Return type:

bytes

static create(eieio_type, count=0, data=None, offset=0, key_prefix=None, payload_prefix=None, timestamp=None, prefix_type=EIEIOPrefix.LOWER_HALF_WORD)[source]

Create a data message.

Parameters:
  • eieio_type (EIEIOType) – The type of the message

  • count (int) – The number of items in the message

  • data (bytes) – The data in the message

  • offset (int) – The offset in the data where the actual data starts

  • key_prefix (int) – The prefix of the keys

  • payload_prefix (int) – The prefix of the payload

  • timestamp (int) – The timestamp of the packet

  • prefix_type (EIEIOPrefix) – The type of the key prefix if 16-bits

property eieio_header: EIEIODataHeader

The header of the message.

Return type:

EIEIODataHeader

get_min_packet_length() int[source]

Get the minimum length of a message instance in bytes.

Return type:

int

property is_next_element: bool

Whether there is another element to be read.

Return type:

bool

property max_n_elements: int

The maximum number of elements that can fit in the packet.

Return type:

int

static min_packet_length(eieio_type, is_prefix=False, is_payload_base=False, is_timestamp=False)[source]

The minimum length of a message with the given header, in bytes.

Parameters:
  • eieio_type (EIEIOType) – the type of message

  • is_prefix (bool) – True if there is a prefix, False otherwise

  • is_payload_base (bool) – True if there is a payload base, False otherwise

  • is_timestamp (bool) – True if there is a timestamp, False otherwise

Returns:

The minimum size of the packet in bytes

Return type:

int

property n_elements: int

The number of elements in the packet.

Return type:

int

property next_element: AbstractDataElement | None

The next element to be read, or None if no more elements. The exact type of element returned depends on the packet type.

Return type:

AbstractDataElement

property size: int

The size of the packet with the current contents.

Return type:

int

class spinnman.messages.eieio.data_messages.KeyDataElement(key: int)

Bases: AbstractDataElement

A data element that contains just a key.

get_bytestring(eieio_type: EIEIOType) bytes[source]

Get a byte-string for the given type

Parameters:

eieio_type (EIEIOType) – The type of the message being written

Returns:

A byte-string for the element

Return type:

bytes

Raises:

SpinnmanInvalidParameterException – If the type is incompatible with the element

property key: int

The key value passed into the init.

Return type:

int

class spinnman.messages.eieio.data_messages.KeyPayloadDataElement(key: int, payload: int, payload_is_timestamp: bool = False)

Bases: AbstractDataElement

A data element that contains a key and a payload.

get_bytestring(eieio_type: EIEIOType) bytes[source]

Get a byte-string for the given type

Parameters:

eieio_type (EIEIOType) – The type of the message being written

Returns:

A byte-string for the element

Return type:

bytes

Raises:

SpinnmanInvalidParameterException – If the type is incompatible with the element

property key: int

The key value passed into the init.

Return type:

int

property payload: int

Gets the payload value passed into the init.

Return type:

int

property payload_is_timestamp: bool

Gets the payload_is_timestamp passed into the init.

Return type:

int