mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
Add object_hook
option to unpack and default
option to pack.
(see simplejson for how to use).
This commit is contained in:
parent
367f15c247
commit
fa157082ac
4 changed files with 92 additions and 10 deletions
|
@ -21,6 +21,7 @@
|
|||
|
||||
typedef struct unpack_user {
|
||||
int use_list;
|
||||
PyObject *object_hook;
|
||||
} unpack_user;
|
||||
|
||||
|
||||
|
@ -172,6 +173,19 @@ static inline int template_callback_map_item(unpack_user* u, msgpack_unpack_obje
|
|||
return -1;
|
||||
}
|
||||
|
||||
//static inline int template_callback_map_end(unpack_user* u, msgpack_unpack_object* c)
|
||||
int template_callback_map_end(unpack_user* u, msgpack_unpack_object* c)
|
||||
{
|
||||
if (u->object_hook) {
|
||||
PyObject *arglist = Py_BuildValue("(O)", *c);
|
||||
Py_INCREF(*c);
|
||||
*c = PyEval_CallObject(u->object_hook, arglist);
|
||||
Py_DECREF(arglist);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o)
|
||||
{
|
||||
PyObject *py;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue