From fa157082ac8db71e3312ca97fe1ceb7f56546fcb Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Tue, 26 Oct 2010 01:26:06 +0900 Subject: Add `object_hook` option to unpack and `default` option to pack. (see simplejson for how to use). --- msgpack/unpack.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'msgpack/unpack.h') 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; -- cgit v1.2.1