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
转载请注明原文地址: https://ju.6miu.com/read-665108.html