mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 10:19:51 +00:00
Add Unpacker.read_bytes().
It reads from inner buffer without unpacking. Merge remote-tracking branch 'jnothman/patch-2' Conflicts: msgpack/_msgpack.pyx
This commit is contained in:
commit
c1d15df87a
2 changed files with 26 additions and 0 deletions
|
|
@ -501,6 +501,16 @@ cdef class Unpacker(object):
|
|||
else:
|
||||
raise ValueError("Unpack failed: error = %d" % (ret,))
|
||||
|
||||
def read_bytes(self, Py_ssize_t nbytes):
|
||||
"""read a specified number of raw bytes from the stream"""
|
||||
cdef size_t nread
|
||||
nread = min(self.buf_tail - self.buf_head, nbytes)
|
||||
ret = PyBytes_FromStringAndSize(self.buf + self.buf_head, nread)
|
||||
self.buf_head += nread
|
||||
if len(ret) < nbytes and self.file_like is not None:
|
||||
ret += self.file_like.read(nbytes - len(ret))
|
||||
return ret
|
||||
|
||||
def unpack(self, object write_bytes=None):
|
||||
"""
|
||||
unpack one object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue