MessagePack: disable integer compression

410 Views Asked by At

I am using the MessagePack for CLI (https://github.com/msgpack/msgpack-cli) library and I am wondering, if it's possible to disable the integer compression.

For example:

// The following collection
object[] { (Int32)10, (Int32)100, (Int32)1000 };
// will look like this after unpacking
MessagePackObject[] { (Byte)10, (Byte)100, (Int16)1000 }

This forces me to explicitly convert each item of the collection in order to cast it back to int[], which is quite time consuming.

1

There are 1 best solutions below

2
o2gy On

Use directly fixed-sized types:

msgpack::sbuffer buffer;
msgpack::packer<msgpack::sbuffer> pk(&buffer); 

msgpack::type::fix_uint32 code(0x00);
msgpack::type::fix_uint32 type(123);

pk.pack(code);
pk.pack(type);