解析和打印 Google Protobuf 的快速方法

Fast way to Parse and Print a Google Protobuffer

我收到 Google Protobuffer and save it in a QByteArray。 现在我用

将接收到的数据解析到相应的 protobuff 中
::proto::dummy * protobuffer; 
QByteArray * ByteArray;

//receive Data
...

protobuffer->ParseFromArray(ByteArray->data(), ByteArray->size);
if(protobuffer->has_XY) /* print it to Log */; 

因为我的 protobuffer 有几个数据字段,所以我想避免查询上面方法中显示的每个条目。有什么快速打印protobuffer所有信息的方法吗?

如果你只是想获得协议缓冲区的人类可读表示,你可以调用它的DebugString()(或ShortDebugString())方法。您可以在 Message class 文档 here.

中阅读有关这些方法的更多信息