Here is a sample which send and receive messages through java and in C++:

Serializing in java:

Person person = Person.newBuilder().setName("chand")
    .setEmail("chand@test.com").setId(55555).build();
socket.send(person.toByteArray(), 0);

De-serialize in java:

byte[] reply = socket.recv(0);
Person person2 = Person.parseFrom(reply);

Serializing in C++:

Person p = Person();
std::string str;
p.SerializeToString(&str);
int sz = str.length();
zmq::message_t *query = new message_t(sz);
memcpy(query->data (), str.c_str(), sz);
socket->send (*query);

De-serializign in C++

zmq::message_t resultset(100);
socket->recv (&resultset);

Person p = Person();
p.ParseFromArray(resultset.data(), resultset.size());
printf("\n Server : %s", p.name().c_str());

版权声明:本文为crazy-machine原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/crazy-machine/articles/5574672.html