| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | import os | |
| 3 | 3 | ||
| 4 | 4 | from .exceptions import * # noqa: F403 | |
| 5 | - from .ext import ExtType, Timestamp | ||
| 5 | + from .ext import Bypass, ExtType, Timestamp | ||
| 6 | 6 | ||
| 7 | 7 | version = (1, 1, 2) | |
| 8 | 8 | __version__ = "1.1.2" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ from cpython.datetime cimport ( | |||
| 8 | 8 | cdef ExtType | |
| 9 | 9 | cdef Timestamp | |
| 10 | 10 | ||
| 11 | - from .ext import ExtType, Timestamp | ||
| 11 | + from .ext import ExtType, Timestamp, Bypass | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | cdef extern from "Python.h": | |
@@ -222,6 +222,8 @@ cdef class Packer: | |||
| 222 | 222 | llval = o.seconds | |
| 223 | 223 | ulval = o.nanoseconds | |
| 224 | 224 | msgpack_pack_timestamp(&self.pk, llval, ulval) | |
| 225 | + elif type(o) is Bypass: | ||
| 226 | + msgpack_pack_raw_body(&self.pk, o.data, len(o.data)) | ||
| 225 | 227 | elif PyList_CheckExact(o) if strict else (PyTuple_Check(o) or PyList_Check(o)): | |
| 226 | 228 | L = Py_SIZE(o) | |
| 227 | 229 | if L > ITEM_LIMIT: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,19 @@ def __new__(cls, code, data): | |||
| 16 | 16 | return super().__new__(cls, code, data) | |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | + class Bypass: | ||
| 20 | + """Bypass is a placeholder class to skip serialization and pass the bytes value as is.""" | ||
| 21 | + | ||
| 22 | + __slots__ = ["data"] | ||
| 23 | + | ||
| 24 | + def __init__(self, data): | ||
| 25 | + if isinstance(data, bytes): | ||
| 26 | + self.data = data | ||
| 27 | + | ||
| 28 | + else: | ||
| 29 | + self.data = memoryview(data).tobytes() | ||
| 30 | + | ||
| 31 | + | ||
| 19 | 32 | class Timestamp: | |
| 20 | 33 | """Timestamp represents the Timestamp extension type in msgpack. | |
| 21 | 34 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ def newlist_hint(size): | |||
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | 40 | from .exceptions import BufferFull, ExtraData, FormatError, OutOfData, StackError | |
| 41 | - from .ext import ExtType, Timestamp | ||
| 41 | + from .ext import Bypass, ExtType, Timestamp | ||
| 42 | 42 | ||
| 43 | 43 | EX_SKIP = 0 | |
| 44 | 44 | EX_CONSTRUCT = 1 | |
@@ -773,6 +773,9 @@ def _pack( | |||
| 773 | 773 | self._buffer.write(struct.pack("b", code)) | |
| 774 | 774 | self._buffer.write(data) | |
| 775 | 775 | return | |
| 776 | + if check(obj, Bypass): | ||
| 777 | + self._buffer.write(obj.data) | ||
| 778 | + return | ||
| 776 | 779 | if check(obj, list_types): | |
| 777 | 780 | n = len(obj) | |
| 778 | 781 | self._pack_array_header(n) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments