diff options
author | INADA Naoki <inada-n@klab.com> | 2013-10-20 15:08:31 +0900 |
---|---|---|
committer | INADA Naoki <inada-n@klab.com> | 2013-10-20 15:08:31 +0900 |
commit | 27f0cba8a5f36393517ee85d2c339847b76e0c6b (patch) | |
tree | 470bc84905240c82d2e1f4e710d55a288661f635 /msgpack/_packer.pyx | |
parent | 7123341ca89a9a3afee8521cc16a1a419ea8871e (diff) | |
parent | 6386481024ec045d9ef991a2c975902276812508 (diff) | |
download | msgpack-python-27f0cba8a5f36393517ee85d2c339847b76e0c6b.tar.gz |
Merge branch 'master' of https://github.com/antocuni/msgpack-python into newspec
Conflicts:
msgpack/fallback.py
msgpack/unpack.h
msgpack/unpack_define.h
msgpack/unpack_template.h
Diffstat (limited to 'msgpack/_packer.pyx')
-rw-r--r-- | msgpack/_packer.pyx | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx index 7082445..df670ed 100644 --- a/msgpack/_packer.pyx +++ b/msgpack/_packer.pyx @@ -5,6 +5,7 @@ from cpython cimport * from libc.stdlib cimport * from libc.string cimport * from libc.limits cimport * +from libc.stdint cimport int8_t from msgpack.exceptions import PackValueError @@ -29,6 +30,7 @@ cdef extern from "pack.h": int msgpack_pack_raw(msgpack_packer* pk, size_t l) int msgpack_pack_bin(msgpack_packer* pk, size_t l) int msgpack_pack_raw_body(msgpack_packer* pk, char* body, size_t l) + int msgpack_pack_ext(msgpack_packer* pk, int8_t typecode, size_t l) cdef int DEFAULT_RECURSE_LIMIT=511 @@ -183,6 +185,9 @@ cdef class Packer(object): for v in o: ret = self._pack(v, nest_limit-1) if ret != 0: break + elif self.handle_unknown_type(o): + # it means that obj was succesfully packed, so we are done + return 0 elif self._default: o = self._default(o) ret = self._pack(o, nest_limit-1) @@ -202,6 +207,13 @@ cdef class Packer(object): self.pk.length = 0 return buf + def handle_unknown_type(self, obj): + return None + + def pack_extended_type(self, typecode, data): + msgpack_pack_ext(&self.pk, typecode, len(data)) + msgpack_pack_raw_body(&self.pk, data, len(data)) + def pack_array_header(self, size_t size): cdef int ret = msgpack_pack_array(&self.pk, size) if ret == -1: |