1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-28 02:27:28 +00:00
bazarr/libs/socketio/msgpack_packet.py

18 lines
510 B
Python

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']
self.data = decoded['data']
self.id = decoded.get('id')
self.namespace = decoded['nsp']