Message

class Message(content: RecordDict, dst_node_id: int, message_type: str, *, ttl: float | None = None, group_id: str | None = None)[source]
class Message(content: RecordDict, *, reply_to: Message, ttl: float | None = None)
class Message(error: Error, *, reply_to: Message, ttl: float | None = None)

Bases : InflatableObject

Represents a message exchanged between ClientApp and ServerApp.

This class encapsulates the payload and metadata necessary for communication between a ClientApp and a ServerApp.

Paramètres:
  • content (Optional[RecordDict] (default: None)) – Holds records either sent by another entity (e.g. sent by the server-side logic to a client, or vice-versa) or that will be sent to it.

  • error (Optional[Error] (default: None)) – A dataclass that captures information about an error that took place when processing another message.

  • dst_node_id (Optional[int] (default: None)) – An identifier for the node receiving this message.

  • message_type (Optional[str] (default: None)) – A string that encodes the action to be executed on the receiving end.

  • ttl (Optional[float] (default: None)) – Time-to-live (TTL) for this message in seconds. If None (default), the TTL is set to 43,200 seconds (12 hours).

  • group_id (Optional[str] (default: None)) – An identifier for grouping messages. In some settings, this is used as the FL round.

  • reply_to (Optional[Message] (default: None)) – The instruction message to which this message is a reply. This message does not retain the original message’s content but derives its metadata from it.

Methods

create_error_reply(error[, ttl])

Construct a reply message indicating an error happened.

create_reply(content[, ttl])

Create a reply to this message with specified content and TTL.

deflate()

Deflate message.

has_content()

Return True if message has content, else False.

has_error()

Return True if message has an error, else False.

inflate(object_content[, children])

Inflate an Message from bytes.

Attributes

children

Return a dictionary of a single RecordDict with its Object IDs as key.

content

The content of this message.

error

Error captured by this message.

is_dirty

Check if the object is dirty after the last deflation.

metadata

A dataclass including information about the message to be executed.

object_id

Get object_id.

property children: dict[str, InflatableObject] | None

Return a dictionary of a single RecordDict with its Object IDs as key.

property content: RecordDict

The content of this message.

create_error_reply(error: Error, ttl: float | None = None) Message[source]

Construct a reply message indicating an error happened.

Paramètres:
  • error (Error) – The error that was encountered.

  • ttl (Optional[float] (default: None)) –

    Time-to-live for this message in seconds. If unset, it will be set based on the remaining time for the received message before it expires. This follows the equation:

    ttl = msg.meta.ttl - (reply.meta.created_at - msg.meta.created_at)

Renvoie:

message – A Message containing only the relevant error and metadata.

Type renvoyé:

Message

create_reply(content: RecordDict, ttl: float | None = None) Message[source]

Create a reply to this message with specified content and TTL.

The method generates a new Message as a reply to this message. It inherits “run_id”, “src_node_id”, “dst_node_id”, and “message_type” from this message and sets “reply_to_message_id” to the ID of this message.

Paramètres:
  • content (RecordDict) – The content for the reply message.

  • ttl (Optional[float] (default: None)) –

    Time-to-live for this message in seconds. If unset, it will be set based on the remaining time for the received message before it expires. This follows the equation:

    ttl = msg.meta.ttl - (reply.meta.created_at - msg.meta.created_at)

Renvoie:

A new Message instance representing the reply.

Type renvoyé:

Message

deflate() bytes[source]

Deflate message.

property error: Error

Error captured by this message.

has_content() bool[source]

Return True if message has content, else False.

has_error() bool[source]

Return True if message has an error, else False.

classmethod inflate(object_content: bytes, children: dict[str, InflatableObject] | None = None) Message[source]

Inflate an Message from bytes.

Paramètres:
  • object_content (bytes) – The deflated object content of the Message.

  • children (Optional[dict[str, InflatableObject]] (default: None)) – Dictionary of children InflatableObjects mapped to their Object IDs. These children enable the full inflation of the Message.

Renvoie:

The inflated Message.

Type renvoyé:

Message

property is_dirty: bool

Check if the object is dirty after the last deflation.

An object is considered dirty if its content has changed since the last its object ID was computed.

property metadata: Metadata

A dataclass including information about the message to be executed.

property object_id: str

Get object_id.