mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-11-09 05:51:02 +00:00
Add use_tuple option that returns tuple for array object to Unpacker.
This commit is contained in:
parent
af7c4d2a60
commit
77e3e59620
2 changed files with 21 additions and 3 deletions
|
|
@ -20,6 +20,7 @@
|
|||
#include "unpack_define.h"
|
||||
|
||||
typedef struct unpack_user {
|
||||
int use_tuple;
|
||||
} unpack_user;
|
||||
|
||||
|
||||
|
|
@ -135,7 +136,8 @@ static inline int template_callback_false(unpack_user* u, msgpack_unpack_object*
|
|||
|
||||
static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *p = PyList_New(n);
|
||||
PyObject *p = u->use_tuple ? PyTuple_New(n) : PyList_New(n);
|
||||
|
||||
if (!p)
|
||||
return -1;
|
||||
*o = p;
|
||||
|
|
@ -143,7 +145,15 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac
|
|||
}
|
||||
|
||||
static inline int template_callback_array_item(unpack_user* u, unsigned int current, msgpack_unpack_object* c, msgpack_unpack_object o)
|
||||
{ PyList_SET_ITEM(*c, current, o); return 0; }
|
||||
{
|
||||
if (u->use_tuple) {
|
||||
PyTuple_SET_ITEM(*c, current, o);
|
||||
}
|
||||
else {
|
||||
PyList_SET_ITEM(*c, current, o);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue