zeromq 利用protobuf通信

来源:互联网 发布:linux下安装navicat 编辑:程序博客网 时间:2024/05/19 12:25

利用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);


记录备忘之

原创粉丝点击