summaryrefslogtreecommitdiff
path: root/msgpack/unpack.h
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2010-10-26 01:26:06 +0900
committerINADA Naoki <songofacandy@gmail.com>2010-10-26 01:26:06 +0900
commitfa157082ac8db71e3312ca97fe1ceb7f56546fcb (patch)
treeee9cfaa2f1470e2c6229cb5bf7bfcfaf7404f96f /msgpack/unpack.h
parent367f15c247bf37beb37e2a81d1d707bc8ef2e085 (diff)
downloadmsgpack-python-fa157082ac8db71e3312ca97fe1ceb7f56546fcb.tar.gz
Add `object_hook` option to unpack and `default` option to pack.
(see simplejson for how to use).
Diffstat (limited to 'msgpack/unpack.h')
-rw-r--r--msgpack/unpack.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h
index 9eb8ce7..e4c03bd 100644
--- a/msgpack/unpack.h
+++ b/msgpack/unpack.h
@@ -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;