zmq communication using protobuf

 

After protobuf serialized as binary data, the data may contain '\ 0', is directly converted to char * type will cause the transmission of data is incomplete.
Solution:

buildProtobufMsg void (const String & Test, ZMQ message_t :: * MSG)
{
IF (MSG == nullptr a)
{
return;
}
the Test Data :: ProtoBufData;
data.set_test (Test);

int size = data.ByteSize ();
char ARR [size];
data.SerializeToArray (ARR, size);

msg-> the rebuild (size);
the memcpy (msg-> data (), ARR, size);
}
 
not remember the sequence of data after the transmission turn to char *, otherwise lead to incomplete data.

调用:
zmq::message_t msg;
buildProtobufMsg(string("hello“),&msg);
zmqsocket.send(msg);
 
【转】:https://blog.csdn.net/bubbleyang/article/details/82628059

 

Guess you like

Origin www.cnblogs.com/hshy/p/11350314.html
zmq