Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add a 'Bypass' type that just concatenates its contents to output #661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
marcoffee wants to merge 1 commit into msgpack:main
base: main
Choose a base branch
Loading
from marcoffee:feature/bypass
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion msgpack/__init__.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion msgpack/_packer.pyx
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions msgpack/ext.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ def __new__(cls, 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.
Expand Down
5 changes: 4 additions & 1 deletion msgpack/fallback.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def newlist_hint(size):


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
Expand Down Expand Up @@ -773,6 +773,9 @@ def _pack(
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)
Expand Down

AltStyle によって変換されたページ (->オリジナル) /