Message¶
Classes:
|
A formatted message. |
- class Message(msg=None, expand_arrays=False, **kwargs)[source]¶
Bases:
object
A formatted message.
id, to, sender, and key are required attributes, but any other key-value pair passed on init is added to the message’s attributes and included in the message.
Can be indexed and set like a dictionary (message[‘key’], etc.)
- Variables
id (str) – ID that uniquely identifies a message. format {sender.id}_{number}
to (str) – ID of socket this message is addressed to
sender (str) – ID of socket where this message originates
key (str) – Type of message, used to select a listen method to process it
value – Body of message, can be any type but must be JSON serializable.
timestamp (str) – Timestamp of message creation
ttl (int) – Time-To-Live, each message is sent this many times at max, each send decrements ttl.
- Parameters
*args
**kwargs
Attributes:
Methods:
__getitem__
(key)- Parameters
key
__setitem__
(key, value)- Parameters
key
_serialize_numpy
(array)Serialize a numpy array for sending over the wire
expand
()Don’t decompress numpy arrays by default for faster IO, explicitly expand them when needed
__delitem__
(key)- Parameters
key
__contains__
(key)- Parameters
key
Get a Python timestamp
validate
()Checks if id, to, sender, and key are all defined.
Serializes all attributes in __dict__ using json.
- id = None¶
- to = None¶
- sender = None¶
- key = None¶
- value = None¶
- changed = False¶
- flags = {}¶
- timestamp = None¶
- ttl = 2¶
- serialized = None¶
- _serialize_numpy(array)[source]¶
Serialize a numpy array for sending over the wire
- Parameters
array
Returns:
- expand()[source]¶
Don’t decompress numpy arrays by default for faster IO, explicitly expand them when needed
- Returns
- get_timestamp()[source]¶
Get a Python timestamp
- Returns
Isoformatted timestamp from
datetime
- Return type