socktools.msgpack_mixin - msgpack formatted messages¶
This module implements a mixin that implements the parse_msg() method using msgpack - see http://www.msgpack.org for details on the msgpack format.
-
class
socktools.msgpack_mixin.MsgpackParseMixin[source]¶ Bases:
objectA mixin for parsing msgpack messages
See http://msgpack.org/ for details
-
parse_msg(data)[source]¶ Parse a raw msgpack message
This method assumes the message is encoded as a list or tuple of (msg_type,msg_data).
For performance reasons garbage collection is turned off while parsing. Should an exception occur while parsing, self.log_debug() is invoked.
If an exception does occur, this method might return None.
Parameters: data (str) – The raw packet to parse Returns: a tuple of (msg_type,msg_data) Return type: tuple
-
serialise_msg(msg_type, msg_data)[source]¶ Serialise a msgpack message
Similar to the JSON mixin, this method serialises messages as msgpack lists of (msg_type,msg_data)
Parameters: - msg_type (int) – the message type as an integer
- msg_data (dict) – usually a dict, the actual message contents
Returns: the msgpack encoded message
Return type: str
-