Skip to content

Commit 85eaff3

Browse files
committed
Add bin type support for fallback Unpacker.
1 parent 84f6b10 commit 85eaff3

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

msgpack/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from msgpack._packer import Packer
1111
from msgpack._unpacker import unpack, unpackb, Unpacker
1212
except ImportError:
13-
from msgpack.fallback import pack, packb, Packer, unpack, unpackb, Unpacker
13+
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
1414

1515

1616
def pack(o, stream, **kwargs):

msgpack/_unpacker.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ from msgpack.exceptions import (
1818
)
1919

2020

21-
2221
cdef extern from "unpack.h":
2322
ctypedef struct msgpack_user:
2423
bint use_list

msgpack/fallback.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def getvalue(self):
5757
TYPE_ARRAY = 1
5858
TYPE_MAP = 2
5959
TYPE_RAW = 3
60+
TYPE_BIN = 4
6061

6162
DEFAULT_RECURSE_LIMIT=511
6263

@@ -297,6 +298,10 @@ def _read_header(self, execute=EX_CONSTRUCT, write_bytes=None):
297298
obj = struct.unpack(">i", self._fb_read(4, write_bytes))[0]
298299
elif b == 0xd3:
299300
obj = struct.unpack(">q", self._fb_read(8, write_bytes))[0]
301+
elif b == 0xd9:
302+
n = struct.unpack("B", self._fb_read(1, write_bytes))[0]
303+
obj = self._fb_read(n, write_bytes)
304+
typ = TYPE_RAW
300305
elif b == 0xda:
301306
n = struct.unpack(">H", self._fb_read(2, write_bytes))[0]
302307
obj = self._fb_read(n, write_bytes)
@@ -305,6 +310,18 @@ def _read_header(self, execute=EX_CONSTRUCT, write_bytes=None):
305310
n = struct.unpack(">I", self._fb_read(4, write_bytes))[0]
306311
obj = self._fb_read(n, write_bytes)
307312
typ = TYPE_RAW
313+
elif b == 0xc4:
314+
n = struct.unpack("B", self._fb_read(1, write_bytes))[0]
315+
obj = self._fb_read(n, write_bytes)
316+
typ = TYPE_BIN
317+
elif b == 0xc5:
318+
n = struct.unpack(">H", self._fb_read(2, write_bytes))[0]
319+
obj = self._fb_read(n, write_bytes)
320+
typ = TYPE_BIN
321+
elif b == 0xc6:
322+
n = struct.unpack(">I", self._fb_read(4, write_bytes))[0]
323+
obj = self._fb_read(n, write_bytes)
324+
typ = TYPE_BIN
308325
elif b == 0xdc:
309326
n = struct.unpack(">H", self._fb_read(2, write_bytes))[0]
310327
typ = TYPE_ARRAY
@@ -373,6 +390,8 @@ def _fb_unpack(self, execute=EX_CONSTRUCT, write_bytes=None):
373390
if self._encoding is not None:
374391
obj = obj.decode(self._encoding, self._unicode_errors)
375392
return obj
393+
if typ == TYPE_BIN:
394+
return obj
376395
assert typ == TYPE_IMMEDIATE
377396
return obj
378397

0 commit comments

Comments
 (0)