protocol buffers - zeromq with protobuf segmentation fault while parsing in c++ -
i using zeromq protobuf send/recieve messages code crashing on receiver end segmentation fault (core dumped)
error while parsing received data.
scan
message.
sender.cpp
scan proto_ls_msg; proto_ls_msg.set_angle_min(0.0); proto_ls_msg.set_angle_max(180.5); std::string ls_msg_str; proto_ls_msg.serializetostring(&ls_msg_str); zmq::message_t request (ls_msg_str.size()); memcpy (request.data(), ls_msg_str.c_str(),ls_msg_str.size()); socket.send (request);
collector.cpp
zmq::message_t recieved; socket.recv (&recieved); //thanks πάντα ῥεῖ std::string ls_msg_str((char*)recieved.data(),recieved.size()); scan *pb_laser_msg_rcv; pb_laser_msg_rcv->parsefromstring(ls_msg_str); // <-- segmentation fault here
i tried different way of converting zmq::message_t
std::string
still gives segmentation fault.
edit update:
//std::string ls_msg_str((char*)recieved); std::string ls_msg_str((char*)recieved.data(),recieved.size());
thanks.
iirc can't directly cast zmq::message_t
string. should use data
member create string. recieved.data
not '\0'
terminated, need pass size when construct ls_msg_str
instance:
std::string ls_msg_str((char*)recieved.data,recieved.size); // ^^^^ ^^^^
Comments
Post a Comment