Message
Classes:
|
A formatted message that takes |
- class Message(msg=None, expand_arrays=False, **kwargs)[source]
Bases:
object
A formatted message that takes
value
, sends it toid
, who should call the listen method indicated by thekey
.Additional message behavior can be indicated by passing
flags
Numpy arrays given in the value field are automatically serialized and deserialized when sending and receiving using bas64 encoding and blosc compression.
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.
flags (dict) –
Flags determine additional message behavior. If a flag has no value associated with it, add it as a key with
None
as the value (eg. self.flags[‘MINPRINT’] = None), the value doesn’t matter.MINPRINT
- don’t print the value in logs (eg. when a large array is being sent)NOREPEAT
- sender will not seek, and recipients will not attempt to send message receipt confirmationsNOLOG
- don’t log this message! for streaming, or other instances where the constant printing of the logger is performance prohibitive
- Parameters
*args
**kwargs
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.
- _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