Hype/hypenv/lib/python3.11/site-packages/socketio/msgpack_packet.py

17 lines
478 B
Python
Raw Permalink Normal View History

2023-06-22 13:30:22 +00:00
import msgpack
from . import packet
class MsgPackPacket(packet.Packet):
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']