summaryrefslogtreecommitdiff
path: root/msgpack/pack_template.h
diff options
context:
space:
mode:
Diffstat (limited to 'msgpack/pack_template.h')
-rw-r--r--msgpack/pack_template.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/msgpack/pack_template.h b/msgpack/pack_template.h
index 9e00d7e..d228d7a 100644
--- a/msgpack/pack_template.h
+++ b/msgpack/pack_template.h
@@ -664,10 +664,13 @@ static inline int msgpack_pack_map(msgpack_packer* x, unsigned int n)
static inline int msgpack_pack_raw(msgpack_packer* x, size_t l)
{
- if(l < 32) {
+ 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);