1.data struct
struct DT
{
std::string name;
int id;
DT():name("123"),id(0){ }
MSGPACK_DEFINE(name, id);
};
2.encode
msgpack::sbuffer buffer_;
msgpack::packer<msgpack::sbuffer> pack_(&buffer_);
pack_.pack_map(4);
pack_.pack("key_1");
pack_.pack("value_1");
pack_.pack("key_2");
pack_.pack("value_1");
pack_.pack("key_3");
pack_.pack(3);
std::vector<DT> ts;
ts.push_back(DT());
ts.push_back(DT());
ts.push_back(DT());
pack_.pack("DT");
pack_.pack(ts);
3.decode
4.python 压码解码
4.1 encode
dt = {b'key': b'value', b'key_3': 3, b'DT': [['12e', 1254], ['aa3', 1254]]}
pack = msgpack.packb(dt)
4.2 decode
unpacker = msgpack.unpackb(BUFFER)#BUFFER接收到的buffer