summaryrefslogtreecommitdiff
path: root/msgpack/unpack.h
diff options
context:
space:
mode:
authortailhook <pc@gafol.net>2011-04-15 17:36:17 +0300
committertailhook <pc@gafol.net>2011-04-15 18:39:17 +0300
commit752e3d1b783fc1c12a28e05a93aa73ac7c6b751c (patch)
tree1b22ff0771d1164468253bed6d0fd668e7e49a79 /msgpack/unpack.h
parentaf7113bb31877f337eef3d43048c0a9f1cb74258 (diff)
downloadmsgpack-python-752e3d1b783fc1c12a28e05a93aa73ac7c6b751c.tar.gz
Implemented encoding for strings
* Packer by default uses `utf-8` encoding by default * Unpacker uses `None` by default, so no decoding is done * Both pack and unpack has `encoding` and `unicode_errors` arguments, if `encoding` is `None` no encoding/decoding is done, otherwise it is python codec. `unicode_errors` is supplied as `errors` parameter to codec
Diffstat (limited to 'msgpack/unpack.h')
-rw-r--r--msgpack/unpack.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h
index 453ec2b..0586ca8 100644
--- a/msgpack/unpack.h
+++ b/msgpack/unpack.h
@@ -23,6 +23,8 @@ typedef struct unpack_user {
int use_list;
PyObject *object_hook;
PyObject *list_hook;
+ const char *encoding;
+ const char *unicode_errors;
} unpack_user;
@@ -197,7 +199,11 @@ static inline int template_callback_map_end(unpack_user* u, msgpack_unpack_objec
static inline int template_callback_raw(unpack_user* u, const char* b, const char* p, unsigned int l, msgpack_unpack_object* o)
{
PyObject *py;
- py = PyBytes_FromStringAndSize(p, l);
+ if(u->encoding) {
+ py = PyUnicode_Decode(p, l, u->encoding, u->unicode_errors);
+ } else {
+ py = PyBytes_FromStringAndSize(p, l);
+ }
if (!py)
return -1;
*o = py;