【发布时间】:2017-12-20 09:01:20
【问题描述】:
我使用Protocol Buffers 来序列化/反序列化数据。我已将 Protocol Buffers 消息文件定义如下:
syntax = "proto3";
package Tutorial;
import "google/protobuf/timestamp.proto";
message PointCloud {
int32 width = 1;
int32 height = 2;
message Point {
float x = 1;
float y = 2;
float z = 3;
fixed32 rgb = 4;
}
repeated Point points = 3;
google.protobuf.Timestamp timestamp = 4;
}
我能够接收序列化数据。我正在使用ParseFromArray API 如下:
zmq::message_t msg;
int rc = zmq_socket.recv(&msg);
if (rc){
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
Tutorial::PointCloud point_cloud;
point_cloud.ParseFromArray(msg.data(), msg.size());
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
std::cout << "Time (ms): " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()/1000.0 << std::endl
}
上述方法有效,但反序列化数据需要足够的时间。在 Ubuntu 14.04 LTS 64 位操作系统中,平均需要大约 96 毫秒。仅供参考,我还打印了msg.size(),发现它大约是3773550。
我正在寻找比这更快的反序列化数据的建议。
【问题讨论】:
标签: c++ serialization protocol-buffers