mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-11-08 05:21:01 +00:00
Unpacker.feed() uses new buffer interface.
This commit is contained in:
parent
0faa1bb558
commit
18215b01bb
1 changed files with 6 additions and 4 deletions
|
|
@ -254,13 +254,15 @@ cdef class Unpacker(object):
|
||||||
|
|
||||||
def feed(self, object next_bytes):
|
def feed(self, object next_bytes):
|
||||||
"""Append `next_bytes` to internal buffer."""
|
"""Append `next_bytes` to internal buffer."""
|
||||||
cdef char* buf
|
cdef Py_buffer pybuff
|
||||||
cdef Py_ssize_t buf_len
|
|
||||||
if self.file_like is not None:
|
if self.file_like is not None:
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
"unpacker.feed() is not be able to use with `file_like`.")
|
"unpacker.feed() is not be able to use with `file_like`.")
|
||||||
PyObject_AsReadBuffer(next_bytes, <const_void_ptr*>&buf, &buf_len)
|
PyObject_GetBuffer(next_bytes, &pybuff, PyBUF_SIMPLE)
|
||||||
self.append_buffer(buf, buf_len)
|
try:
|
||||||
|
self.append_buffer(<char*>pybuff.buf, pybuff.len)
|
||||||
|
finally:
|
||||||
|
PyBuffer_Release(&pybuff)
|
||||||
|
|
||||||
cdef append_buffer(self, void* _buf, Py_ssize_t _buf_len):
|
cdef append_buffer(self, void* _buf, Py_ssize_t _buf_len):
|
||||||
cdef:
|
cdef:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue