使用PrintToString打印protobuffer包

本文介绍了Protobuf中的PrintToString函数,用于在不严格要求打印结果格式的场景下,提供序列化的便捷打印。该函数能帮助开发者快速查看protobuf消息的内容,简化调试过程。
摘要由CSDN通过智能技术生成

对于ProtoBuffer常用到的功能是序列化和反序列化,所以相对熟悉的也是它的这两类函数:

序列化函数:

  // Serialize the message and store it in the given string.  All required
  // fields must be set.
  bool SerializeToString(string* output) const;
  // Serialize the message and store it in the given byte array.  All required
  // fields must be set.
  bool SerializeToArray(void* data, int size) const;
反序列化函数:

  // Parse a protocol buffer contained in a string.
  bool ParseFromString(const string& data);
  // Parse a protocol buffer contained in an array of bytes.
  bool ParseFromArray(const void* data, int size);

但是,偶尔会有打印包中所有字段值的需求,比如测试,这时候如果包结果又比较大,这时候one by one去写就是个苦力活了。

今天同事介绍了这个函数,感觉应付一些对打印的结果要求不太严格的场景还是不错的,毕竟太省时省力了:

    // Like TextFormat::PrintToSt
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值