Skip to content

Commit

Permalink
implement buffer protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed May 5, 2024
1 parent 526ec9c commit 19c822f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 7 additions & 3 deletions msgpack/_packer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ cdef extern from "pack.h":
int msgpack_pack_timestamp(msgpack_packer* x, long long seconds, unsigned long nanoseconds);
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
Expand Down Expand Up @@ -371,4 +369,10 @@ cdef class Packer(object):

def getbuffer(self):
"""Return view of internal buffer."""
return buff_to_buff(self.pk.buf, self.pk.length)
return memoryview(self)

def __getbuffer__(self, Py_buffer *buffer, int flags):
PyBuffer_FillInfo(buffer, self, self.pk.buf, self.pk.length, 1, flags)

def __releasebuffer__(self, Py_buffer *buffer):
pass
8 changes: 0 additions & 8 deletions msgpack/buff_converter.h

This file was deleted.

0 comments on commit 19c822f

Please sign in to comment.