codekingpro/portable-devtools
114k
1import msgpack2from . import packet3 4 5class MsgPackPacket(packet.Packet):6 uses_binary_events = False7 8 def encode(self):9 """Encode the packet for transmission."""10 return msgpack.dumps(self._to_dict())11 12 def decode(self, encoded_packet):13 """Decode a transmitted package."""14 decoded = msgpack.loads(encoded_packet)15 self.packet_type = decoded['type']16 self.data = decoded.get('data')17 self.id = decoded.get('id')18 self.namespace = decoded['nsp']19 