@@ -26,6 +26,7 @@ cdef extern from "unpack.h":
26
26
ctypedef struct msgpack_user:
27
27
bint use_list
28
28
bint raw
29
+ bint bytes_memoryview
29
30
bint has_pairs_hook # call object_hook with k-v pairs
30
31
bint strict_map_key
31
32
int timestamp
@@ -60,7 +61,8 @@ cdef extern from "unpack.h":
60
61
cdef inline init_ctx(unpack_context * ctx,
61
62
object object_hook, object object_pairs_hook,
62
63
object list_hook, object ext_hook,
63
- bint use_list, bint raw, int timestamp,
64
+ bint use_list, bint raw, bint bytes_memoryview,
65
+ int timestamp,
64
66
bint strict_map_key,
65
67
const char * unicode_errors,
66
68
Py_ssize_t max_str_len, Py_ssize_t max_bin_len,
@@ -69,6 +71,7 @@ cdef inline init_ctx(unpack_context *ctx,
69
71
unpack_init(ctx)
70
72
ctx.user.use_list = use_list
71
73
ctx.user.raw = raw
74
+ ctx.user.bytes_memoryview = bytes_memoryview
72
75
ctx.user.strict_map_key = strict_map_key
73
76
ctx.user.object_hook = ctx.user.list_hook = < PyObject* > NULL
74
77
ctx.user.max_str_len = max_str_len
@@ -141,7 +144,8 @@ cdef inline int get_data_from_buffer(object obj,
141
144
142
145
143
146
def unpackb (object packed , *, object object_hook = None , object list_hook = None ,
144
- bint use_list = True , bint raw = False , int timestamp = 0 , bint strict_map_key = True ,
147
+ bint use_list = True , bint raw = False , bint bytes_memoryview = False ,
148
+ int timestamp = 0 , bint strict_map_key = True ,
145
149
unicode_errors = None ,
146
150
object_pairs_hook = None , ext_hook = ExtType,
147
151
Py_ssize_t max_str_len = - 1 ,
@@ -189,7 +193,7 @@ def unpackb(object packed, *, object object_hook=None, object list_hook=None,
189
193
190
194
try :
191
195
init_ctx(& ctx, object_hook, object_pairs_hook, list_hook, ext_hook,
192
- use_list, raw, timestamp, strict_map_key, cerr,
196
+ use_list, raw, bytes_memoryview, timestamp, strict_map_key, cerr,
193
197
max_str_len, max_bin_len, max_array_len, max_map_len, max_ext_len)
194
198
ret = unpack_construct(& ctx, buf, buf_len, & off)
195
199
finally :
@@ -227,9 +231,13 @@ cdef class Unpacker(object):
227
231
Otherwise, unpack to Python tuple. (default: True)
228
232
229
233
:param bool raw:
230
- If true, unpack msgpack raw to Python bytes.
234
+ If true, unpack msgpack raw strings to Python bytes.
231
235
Otherwise, unpack to Python str by decoding with UTF-8 encoding (default).
232
236
237
+ :param bool bytes_memoryview:
238
+ If true, and if possible, unpack msgpack bytes to a memory_view.
239
+ Otherwise, unpack into a Python bytes (default).
240
+
233
241
:param int timestamp:
234
242
Control how timestamp type is unpacked:
235
243
@@ -325,7 +333,8 @@ cdef class Unpacker(object):
325
333
self .buf = NULL
326
334
327
335
def __init__ (self , file_like = None , *, Py_ssize_t read_size = 0 ,
328
- bint use_list = True , bint raw = False , int timestamp = 0 , bint strict_map_key = True ,
336
+ bint use_list = True , bint raw = False , bint bytes_memoryview = False ,
337
+ int timestamp = 0 , bint strict_map_key = True ,
329
338
object object_hook = None , object object_pairs_hook = None , object list_hook = None ,
330
339
unicode_errors = None , Py_ssize_t max_buffer_size = 100 * 1024 * 1024 ,
331
340
object ext_hook = ExtType,
@@ -380,7 +389,7 @@ cdef class Unpacker(object):
380
389
cerr = unicode_errors
381
390
382
391
init_ctx(& self .ctx, object_hook, object_pairs_hook, list_hook,
383
- ext_hook, use_list, raw, timestamp, strict_map_key, cerr,
392
+ ext_hook, use_list, raw, bytes_memoryview, timestamp, strict_map_key, cerr,
384
393
max_str_len, max_bin_len, max_array_len,
385
394
max_map_len, max_ext_len)
386
395
0 commit comments