diff options
| author | INADA Naoki <songofacandy@gmail.com> | 2013-10-17 08:35:08 +0900 |
|---|---|---|
| committer | INADA Naoki <songofacandy@gmail.com> | 2013-10-17 08:35:08 +0900 |
| commit | da12e177a31445492795f4003bbe0328645325b2 (patch) | |
| tree | 8e4d4d8ff30e9d0ff8fa8298cf9c64d74a7af8b5 /msgpack/pack_template.h | |
| parent | f45d7b4e2d362222698b755444ffb61f1cf74b02 (diff) | |
| download | msgpack-python-da12e177a31445492795f4003bbe0328645325b2.tar.gz | |
Add bin type support.
Diffstat (limited to 'msgpack/pack_template.h')
| -rw-r--r-- | msgpack/pack_template.h | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/msgpack/pack_template.h b/msgpack/pack_template.h index 9e00d7e..ff1cbaa 100644 --- a/msgpack/pack_template.h +++ b/msgpack/pack_template.h @@ -667,7 +667,10 @@ static inline int msgpack_pack_raw(msgpack_packer* x, size_t l) if(l < 32) { unsigned char d = 0xa0 | (uint8_t)l; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); - } else if(l < 65536) { + } else if (x->use_bin_type && l < 256) { // str8 is new format introduced with bin. + unsigned char buf[2] = {0xd9, (uint8_t)l}; + msgpack_pack_append_buffer(x, buf, 2); + } else if (l < 65536) { unsigned char buf[3]; buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l); msgpack_pack_append_buffer(x, buf, 3); @@ -678,6 +681,28 @@ static inline int msgpack_pack_raw(msgpack_packer* x, size_t l) } } +/* + * bin + */ +static inline int msgpack_pack_bin(msgpack_packer *x, size_t l) +{ + if (!x->use_bin_type) { + return msgpack_pack_raw(x, l) + } + if (l < 256) { + unsigned char buf[2] = {0xc4, (unsigned char)l}; + msgpack_pack_append_buffer(x, buf, 2); + } else if (l < 65536) { + unsigned char buf[3] = {0xc5}; + _msgpack_store16(&buf[1], (uint16_t)l); + msgpack_pack_append_buffer(x, buf, 3); + } else { + unsigned char buf[5] = {0xc6}; + _msgpack_store32(&buf[1], (uint32_t)l); + msgpack_pack_append_buffer(x, buf, 5); + } +} + static inline int msgpack_pack_raw_body(msgpack_packer* x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); |
