2022-01-24 04:07:52 +00:00
|
|
|
import msgpack
|
|
|
|
from . import packet
|
|
|
|
|
|
|
|
|
|
|
|
class MsgPackPacket(packet.Packet):
|
|
|
|
uses_binary_events = False
|
|
|
|
|
|
|
|
def encode(self):
|
|
|
|
"""Encode the packet for transmission."""
|
|
|
|
return msgpack.dumps(self._to_dict())
|
|
|
|
|
|
|
|
def decode(self, encoded_packet):
|
|
|
|
"""Decode a transmitted package."""
|
|
|
|
decoded = msgpack.loads(encoded_packet)
|
|
|
|
self.packet_type = decoded['type']
|
2022-11-07 18:06:49 +00:00
|
|
|
self.data = decoded.get('data')
|
2022-01-24 04:07:52 +00:00
|
|
|
self.id = decoded.get('id')
|
|
|
|
self.namespace = decoded['nsp']
|