c++ - Sending a vector through zeromq with msgpack -
i can't seem send vector
of struct
serialized msgpack through zeromq.
it's vector of struct:
struct mydata { mydata() : id(0), x(0), y(0), a(0) {} mydata(const obj &r) : id(0), x(r.pose[0]), y(r.pose[1]), a(r.pose[2]) {} mydata(const obj *r) : id(0), x(r->pose[0]), y(r->pose[1]), a(r->pose[2]) {} double id; double x; double y; double a; msgpack_define(id, x, y, a); };
on sending side:
data
std::vector<mydata>
msgpack::sbuffer sbuf; msgpack::pack(sbuf, data); zmq::message_t msg(sbuf.data(), sizeof(char *) * sbuf.size(), null, null); local_socket->send(msg); // zeromq's send function
did construct sbuffer
or message_t
wrong?
on receiving side:
i'm not sure if supposed cast msg.data()
or not can't find documentation on how work zeromq , messagepack.
message_t msg; server_socket->recv(&msg); msgpack::unpacked unpacked; msgpack::unpack(&unpacked, reinterpret_cast<char*>(msg.data()), msg.size()); msgpack::object obj = unpacked.get(); std::vector<mydata> data; obj.convert(&data); printf("size %d\n", data.size());
i following error:
terminate called after throwing instance of 'msgpack::type_error'
what(): std::bad_cast aborted
i appreciate help.
this seems have done trick me:
msgpack::sbuffer sbuf; msgpack::pack(sbuf, data); zmq::message_t msg(sbuf.size()); memcpy(msg.data(), sbuf.data(), sbuf.size());
Comments
Post a Comment