diff options
author | Antonio Cuni <anto.cuni@gmail.com> | 2013-10-19 17:27:16 +0200 |
---|---|---|
committer | Antonio Cuni <anto.cuni@gmail.com> | 2013-10-19 17:27:16 +0200 |
commit | 56dd1650a42a454027ba335b494100a9f211758e (patch) | |
tree | bb40490af6a940e75d91d0e2e19a9975c78c8a15 /msgpack/unpack.h | |
parent | 985d4c1496d8c9186079ebc4e42aee319e67c385 (diff) | |
download | msgpack-python-56dd1650a42a454027ba335b494100a9f211758e.tar.gz |
implement unpacking for all the fixtext formats
Diffstat (limited to 'msgpack/unpack.h')
-rw-r--r-- | msgpack/unpack.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h index baeed1f..97ebd3f 100644 --- a/msgpack/unpack.h +++ b/msgpack/unpack.h @@ -24,6 +24,7 @@ typedef struct unpack_user { PyObject *object_hook; bool has_pairs_hook; PyObject *list_hook; + PyObject *ext_type_hook; const char *encoding; const char *unicode_errors; } unpack_user; @@ -226,4 +227,21 @@ static inline int unpack_callback_raw(unpack_user* u, const char* b, const char* return 0; } +static inline int unpack_callback_ext(unpack_user* u, const char* base, const char* pos, + unsigned int lenght, msgpack_unpack_object* o) +{ + PyObject *py; + int8_t typecode = (int8_t)*pos++; + if (!u->ext_type_hook) { + PyErr_SetString(PyExc_AssertionError, "u->ext_type_hook cannot be NULL"); + return -1; + } + // lenght also includes the typecode, so the actual data is lenght-1 + py = PyEval_CallFunction(u->ext_type_hook, "(is#)", typecode, pos, lenght-1); + if (!py) + return -1; + *o = py; + return 0; +} + #include "unpack_template.h" |