天天看点

zeromq 利用protobuf通信

利用zeromq进行编程时候,服务器和客户端的通信,利用protobuf时候

之前的项目里面,需要对protobuf进行编码解码。

其实并不需要如此繁琐,直接利用 protobuf里面的 MessageLite 的两个函数就可以搞定

 将数据转化为数组,利用zeromq 作为消息发送出去

  // Serialize the message and store it in the given byte array.  All required

  // fields must be set.

  bool SerializeToArray(void* data, int size) const;

利用下面的接口函数再将数据转化为msg

  // Parse a protocol buffer contained in an array of bytes.

bool ParseFromArray(const void* data, int size);

记录备忘之