mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-04-09 21:10:18 +00:00
Merge e4ec35b7d3 into 6357bc272c
This commit is contained in:
commit
4aed8c695e
4 changed files with 21 additions and 3 deletions
|
|
@ -2,7 +2,7 @@
|
|||
import os
|
||||
|
||||
from .exceptions import * # noqa: F403
|
||||
from .ext import ExtType, Timestamp
|
||||
from .ext import Bypass, ExtType, Timestamp
|
||||
|
||||
version = (1, 1, 2)
|
||||
__version__ = "1.1.2"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from cpython.datetime cimport (
|
|||
cdef ExtType
|
||||
cdef Timestamp
|
||||
|
||||
from .ext import ExtType, Timestamp
|
||||
from .ext import ExtType, Timestamp, Bypass
|
||||
|
||||
|
||||
cdef extern from "Python.h":
|
||||
|
|
@ -222,6 +222,8 @@ cdef class Packer:
|
|||
llval = o.seconds
|
||||
ulval = o.nanoseconds
|
||||
msgpack_pack_timestamp(&self.pk, llval, ulval)
|
||||
elif type(o) is Bypass:
|
||||
msgpack_pack_raw_body(&self.pk, o.data, len(o.data))
|
||||
elif PyList_CheckExact(o) if strict else (PyTuple_Check(o) or PyList_Check(o)):
|
||||
L = Py_SIZE(o)
|
||||
if L > ITEM_LIMIT:
|
||||
|
|
|
|||
|
|
@ -16,6 +16,19 @@ class ExtType(namedtuple("ExtType", "code data")):
|
|||
return super().__new__(cls, code, data)
|
||||
|
||||
|
||||
class Bypass:
|
||||
"""Bypass is a placeholder class to skip serialization and pass the bytes value as is."""
|
||||
|
||||
__slots__ = ["data"]
|
||||
|
||||
def __init__(self, data):
|
||||
if isinstance(data, bytes):
|
||||
self.data = data
|
||||
|
||||
else:
|
||||
self.data = memoryview(data).tobytes()
|
||||
|
||||
|
||||
class Timestamp:
|
||||
"""Timestamp represents the Timestamp extension type in msgpack.
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ else:
|
|||
|
||||
|
||||
from .exceptions import BufferFull, ExtraData, FormatError, OutOfData, StackError
|
||||
from .ext import ExtType, Timestamp
|
||||
from .ext import Bypass, ExtType, Timestamp
|
||||
|
||||
EX_SKIP = 0
|
||||
EX_CONSTRUCT = 1
|
||||
|
|
@ -773,6 +773,9 @@ class Packer:
|
|||
self._buffer.write(struct.pack("b", code))
|
||||
self._buffer.write(data)
|
||||
return
|
||||
if check(obj, Bypass):
|
||||
self._buffer.write(obj.data)
|
||||
return
|
||||
if check(obj, list_types):
|
||||
n = len(obj)
|
||||
self._pack_array_header(n)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue