lundi 25 juin 2018

zmq error in setting value of a protobuf serializable class?

I am testing a code that uses zmq as socket and networking tool, and protobuf for serialization. The code receives a zmq_message and parses it to a protobuf class, in return I change the value of one of the class members and send the same class back to the requestor. somehow during this process zmq assertion "check()" fails. I don't really know why it is happening as everything looks okay to me. the code looks like this in the main file.

zmq::socket_t external(context, ZMQ_REP);
external.bind("tcp://*:29067");

zmq::message_t request;
external.recv(&request);
msg.deserialize(request);

msg.set_probed_value(12.0);
zmq::message_t response = msg.serialize();
external.send(response);

deserialize method looks like this.

_msg.ParseFromString(reinterpret_cast<const char*>(msg.data()));

and serialize method as below:

zmq::message_t request;
std::string value = _msg.SerializeAsString();
memcpy(request.data(), reinterpret_cast<const void*>(value.c_str()), value.size());
return request;

I know for a fact that problem is caused when I set the valued of probed to a different number than what it was set at parse time. If I remove that line msg.set_probed_value(12.0), no exception happens and everything is okay.

Assertion failed: check () (/apps/zmq/libzmq/src/msg.cpp:347)

Aucun commentaire:

Enregistrer un commentaire