@@ -53,7 +53,7 @@ cdef inline int PyBytesLike_CheckExact(object o):
53
53
return PyBytes_CheckExact(o) or PyByteArray_CheckExact(o)
54
54
55
55
56
- cdef class Packer( object ) :
56
+ cdef class Packer:
57
57
"""
58
58
MessagePack Packer
59
59
@@ -97,6 +97,11 @@ cdef class Packer(object):
97
97
:param str unicode_errors:
98
98
The error handler for encoding unicode. (default: 'strict')
99
99
DO NOT USE THIS!! This option is kept for very specific usage.
100
+
101
+ :param int buf_size:
102
+ The size of the internal buffer. (default: 256*1024)
103
+ Useful if serialisation size can be correctly estimated,
104
+ avoid unnecessary reallocations.
100
105
"""
101
106
cdef msgpack_packer pk
102
107
cdef object _default
@@ -107,8 +112,7 @@ cdef class Packer(object):
107
112
cdef bint autoreset
108
113
cdef bint datetime
109
114
110
- def __cinit__ (self ):
111
- cdef int buf_size = 1024 * 1024
115
+ def __cinit__ (self , buf_size = 256 * 1024 , **_kwargs ):
112
116
self .pk.buf = < char * > PyMem_Malloc(buf_size)
113
117
if self .pk.buf == NULL :
114
118
raise MemoryError (" Unable to allocate internal buffer." )
@@ -117,7 +121,8 @@ cdef class Packer(object):
117
121
118
122
def __init__ (self , *, default = None ,
119
123
bint use_single_float = False , bint autoreset = True , bint use_bin_type = True ,
120
- bint strict_types = False , bint datetime = False , unicode_errors = None ):
124
+ bint strict_types = False , bint datetime = False , unicode_errors = None ,
125
+ buf_size = 256 * 1024 ):
121
126
self .use_float = use_single_float
122
127
self .strict_types = strict_types
123
128
self .autoreset = autoreset
0 commit comments