summaryrefslogtreecommitdiff
path: root/msgpack/unpack.h
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2010-10-26 02:09:52 +0900
committerINADA Naoki <songofacandy@gmail.com>2010-10-26 02:09:52 +0900
commit3d8978417a177c280b837d72054848e8dd4bc649 (patch)
treeae5a2911d998b9096ae4f0e395070c2ca434ec97 /msgpack/unpack.h
parent0076d42a0ddeb3601f1a0c806c7874da2110a986 (diff)
downloadmsgpack-python-3d8978417a177c280b837d72054848e8dd4bc649.tar.gz
Add list_hook option to unpacker.
Diffstat (limited to 'msgpack/unpack.h')
-rw-r--r--msgpack/unpack.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h
index 404ee5a..453ec2b 100644
--- a/msgpack/unpack.h
+++ b/msgpack/unpack.h
@@ -22,6 +22,7 @@
typedef struct unpack_user {
int use_list;
PyObject *object_hook;
+ PyObject *list_hook;
} unpack_user;
@@ -154,6 +155,16 @@ static inline int template_callback_array_item(unpack_user* u, unsigned int curr
return 0;
}
+static inline int template_callback_array_end(unpack_user* u, msgpack_unpack_object* c)
+{
+ if (u->list_hook) {
+ PyObject *arglist = Py_BuildValue("(O)", *c);
+ *c = PyEval_CallObject(u->list_hook, arglist);
+ Py_DECREF(arglist);
+ }
+ return 0;
+}
+
static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_unpack_object* o)
{
PyObject *p = PyDict_New();
@@ -173,16 +184,14 @@ 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)
+static inline int template_callback_map_end(unpack_user* u, msgpack_unpack_object* c)
{
if (u->object_hook) {
PyObject *arglist = Py_BuildValue("(O)", *c);
*c = PyEval_CallObject(u->object_hook, arglist);
Py_DECREF(arglist);
- return 0;
}
- return -1;
+ return 0;
}
static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o)