Skip to content

Commit db7fcda

Browse files
committed
feat: pass dumps_default, ext_hook
1 parent b423d0e commit db7fcda

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/socketio/msgpack_packet.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,33 @@
55
class MsgPackPacket(packet.Packet):
66
uses_binary_events = False
77

8+
def __init__(
9+
self,
10+
packet_type=packet.EVENT,
11+
data=None,
12+
namespace=None,
13+
id=None,
14+
binary=None,
15+
encoded_packet=None,
16+
dumps_default=None,
17+
ext_hook=None,
18+
):
19+
super().__init__(
20+
packet_type, data, namespace, id, binary, encoded_packet
21+
)
22+
self.dumps_default = dumps_default
23+
self.ext_hook = ext_hook
24+
825
def encode(self):
926
"""Encode the packet for transmission."""
10-
return msgpack.dumps(self._to_dict())
27+
return msgpack.dumps(self._to_dict(), default=self.dumps_default)
1128

1229
def decode(self, encoded_packet):
1330
"""Decode a transmitted package."""
14-
decoded = msgpack.loads(encoded_packet)
31+
if self.ext_hook is None:
32+
decoded = msgpack.loads(encoded_packet)
33+
else:
34+
decoded = msgpack.loads(encoded_packet, ext_hook=self.ext_hook)
1535
self.packet_type = decoded['type']
1636
self.data = decoded.get('data')
1737
self.id = decoded.get('id')

0 commit comments

Comments
 (0)