mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-29 00:24:13 +00:00
Add bin type support for fallback Unpacker.
This commit is contained in:
parent
84f6b10019
commit
85eaff344b
3 changed files with 20 additions and 2 deletions
|
|
@ -10,7 +10,7 @@ else:
|
||||||
from msgpack._packer import Packer
|
from msgpack._packer import Packer
|
||||||
from msgpack._unpacker import unpack, unpackb, Unpacker
|
from msgpack._unpacker import unpack, unpackb, Unpacker
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from msgpack.fallback import pack, packb, Packer, unpack, unpackb, Unpacker
|
from msgpack.fallback import Packer, unpack, unpackb, Unpacker
|
||||||
|
|
||||||
|
|
||||||
def pack(o, stream, **kwargs):
|
def pack(o, stream, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ from msgpack.exceptions import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cdef extern from "unpack.h":
|
cdef extern from "unpack.h":
|
||||||
ctypedef struct msgpack_user:
|
ctypedef struct msgpack_user:
|
||||||
bint use_list
|
bint use_list
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ TYPE_IMMEDIATE = 0
|
||||||
TYPE_ARRAY = 1
|
TYPE_ARRAY = 1
|
||||||
TYPE_MAP = 2
|
TYPE_MAP = 2
|
||||||
TYPE_RAW = 3
|
TYPE_RAW = 3
|
||||||
|
TYPE_BIN = 4
|
||||||
|
|
||||||
DEFAULT_RECURSE_LIMIT=511
|
DEFAULT_RECURSE_LIMIT=511
|
||||||
|
|
||||||
|
|
@ -297,6 +298,10 @@ class Unpacker(object):
|
||||||
obj = struct.unpack(">i", self._fb_read(4, write_bytes))[0]
|
obj = struct.unpack(">i", self._fb_read(4, write_bytes))[0]
|
||||||
elif b == 0xd3:
|
elif b == 0xd3:
|
||||||
obj = struct.unpack(">q", self._fb_read(8, write_bytes))[0]
|
obj = struct.unpack(">q", self._fb_read(8, write_bytes))[0]
|
||||||
|
elif b == 0xd9:
|
||||||
|
n = struct.unpack("B", self._fb_read(1, write_bytes))[0]
|
||||||
|
obj = self._fb_read(n, write_bytes)
|
||||||
|
typ = TYPE_RAW
|
||||||
elif b == 0xda:
|
elif b == 0xda:
|
||||||
n = struct.unpack(">H", self._fb_read(2, write_bytes))[0]
|
n = struct.unpack(">H", self._fb_read(2, write_bytes))[0]
|
||||||
obj = self._fb_read(n, write_bytes)
|
obj = self._fb_read(n, write_bytes)
|
||||||
|
|
@ -305,6 +310,18 @@ class Unpacker(object):
|
||||||
n = struct.unpack(">I", self._fb_read(4, write_bytes))[0]
|
n = struct.unpack(">I", self._fb_read(4, write_bytes))[0]
|
||||||
obj = self._fb_read(n, write_bytes)
|
obj = self._fb_read(n, write_bytes)
|
||||||
typ = TYPE_RAW
|
typ = TYPE_RAW
|
||||||
|
elif b == 0xc4:
|
||||||
|
n = struct.unpack("B", self._fb_read(1, write_bytes))[0]
|
||||||
|
obj = self._fb_read(n, write_bytes)
|
||||||
|
typ = TYPE_BIN
|
||||||
|
elif b == 0xc5:
|
||||||
|
n = struct.unpack(">H", self._fb_read(2, write_bytes))[0]
|
||||||
|
obj = self._fb_read(n, write_bytes)
|
||||||
|
typ = TYPE_BIN
|
||||||
|
elif b == 0xc6:
|
||||||
|
n = struct.unpack(">I", self._fb_read(4, write_bytes))[0]
|
||||||
|
obj = self._fb_read(n, write_bytes)
|
||||||
|
typ = TYPE_BIN
|
||||||
elif b == 0xdc:
|
elif b == 0xdc:
|
||||||
n = struct.unpack(">H", self._fb_read(2, write_bytes))[0]
|
n = struct.unpack(">H", self._fb_read(2, write_bytes))[0]
|
||||||
typ = TYPE_ARRAY
|
typ = TYPE_ARRAY
|
||||||
|
|
@ -373,6 +390,8 @@ class Unpacker(object):
|
||||||
if self._encoding is not None:
|
if self._encoding is not None:
|
||||||
obj = obj.decode(self._encoding, self._unicode_errors)
|
obj = obj.decode(self._encoding, self._unicode_errors)
|
||||||
return obj
|
return obj
|
||||||
|
if typ == TYPE_BIN:
|
||||||
|
return obj
|
||||||
assert typ == TYPE_IMMEDIATE
|
assert typ == TYPE_IMMEDIATE
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue