Skip to content

Commit 52f8bc2

Browse files
authored
implement buffer protocol (#602)
Fix #479
1 parent 526ec9c commit 52f8bc2

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

Diff for: msgpack/_packer.pyx

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ cdef extern from "pack.h":
4444
int msgpack_pack_timestamp(msgpack_packer* x, long long seconds, unsigned long nanoseconds);
4545
int msgpack_pack_unicode(msgpack_packer* pk, object o, long long limit)
4646

47-
cdef extern from "buff_converter.h":
48-
object buff_to_buff(char *, Py_ssize_t)
4947

5048
cdef int DEFAULT_RECURSE_LIMIT=511
5149
cdef long long ITEM_LIMIT = (2**32)-1
@@ -371,4 +369,10 @@ cdef class Packer(object):
371369

372370
def getbuffer(self):
373371
"""Return view of internal buffer."""
374-
return buff_to_buff(self.pk.buf, self.pk.length)
372+
return memoryview(self)
373+
374+
def __getbuffer__(self, Py_buffer *buffer, int flags):
375+
PyBuffer_FillInfo(buffer, self, self.pk.buf, self.pk.length, 1, flags)
376+
377+
def __releasebuffer__(self, Py_buffer *buffer):
378+
pass

Diff for: msgpack/buff_converter.h

-8
This file was deleted.

0 commit comments

Comments
 (0)