summaryrefslogtreecommitdiff
path: root/msgpack/_packer.pyx
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2018-11-09 20:55:13 +0900
committerGitHub <noreply@github.com>2018-11-09 20:55:13 +0900
commit9e210bfc1a922031db67bf42e508b1b4550814c6 (patch)
tree1bbef6a155df89e6fef0a9b5efbae4928fa40772 /msgpack/_packer.pyx
parenta8b3e97fe588a2411a8e869b52be1946ed9f0f86 (diff)
downloadmsgpack-python-9e210bfc1a922031db67bf42e508b1b4550814c6.tar.gz
Add Packer.buffer() (#320)
Diffstat (limited to 'msgpack/_packer.pyx')
-rw-r--r--msgpack/_packer.pyx14
1 files changed, 12 insertions, 2 deletions
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx
index 225f24a..fd05ae0 100644
--- a/msgpack/_packer.pyx
+++ b/msgpack/_packer.pyx
@@ -41,6 +41,9 @@ cdef extern from "pack.h":
int msgpack_pack_ext(msgpack_packer* pk, char typecode, size_t l)
int msgpack_pack_unicode(msgpack_packer* pk, object o, long long limit)
+cdef extern from "buff_converter.h":
+ object buff_to_buff(char *, Py_ssize_t)
+
cdef int DEFAULT_RECURSE_LIMIT=511
cdef long long ITEM_LIMIT = (2**32)-1
@@ -349,9 +352,16 @@ cdef class Packer(object):
return buf
def reset(self):
- """Clear internal buffer."""
+ """Reset internal buffer.
+
+ This method is usaful only when autoreset=False.
+ """
self.pk.length = 0
def bytes(self):
- """Return buffer content."""
+ """Return internal buffer contents as bytes object"""
return PyBytes_FromStringAndSize(self.pk.buf, self.pk.length)
+
+ def getbuffer(self):
+ """Return view of internal buffer."""
+ return buff_to_buff(self.pk.buf, self.pk.length)