Skip to content

Commit 94c96c9

Browse files
committed
updates for flexibility
1 parent c3701df commit 94c96c9

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/msgpack_streams/_msgpack.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ def pack_stream(
202202
if ext_hook is not None:
203203
result = ext_hook(obj)
204204
if result is not None:
205-
# pack the ext type
206-
pack_stream(stream, result)
205+
# pack the ext type (doesn't exactly need to be an ExtType)
206+
# if the same type is returned it will cause infinite recursion
207+
pack_stream(stream, result, float32=float32, ext_hook=ext_hook)
207208
return
208209
raise TypeError("unsupported type", _type, obj)
209210

@@ -316,12 +317,12 @@ def unpack_stream(
316317
else:
317318
raise NotImplementedError("unsupported reserved extension", code)
318319
else:
319-
ext = ExtType(code, data)
320+
obj = ExtType(code, data)
320321
if ext_hook is not None:
321-
result = ext_hook(ext)
322-
obj = result if result is not None else ext
323-
else:
324-
obj = ext
322+
result = ext_hook(obj)
323+
if result is not None:
324+
obj = result
325+
325326
elif first_byte == 0xD9: # str8
326327
sl = u8_b_unpack(stream)
327328
obj = stream.read(sl).decode("utf-8")

0 commit comments

Comments
 (0)