Add object_hook option to unpack and default option to pack.

(see simplejson for how to use).
This commit is contained in:
INADA Naoki 2010-10-26 01:26:06 +09:00
parent 367f15c247
commit fa157082ac
4 changed files with 92 additions and 10 deletions

View file

@ -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;