c++ protobuf序列化报错 Use the ‘bytes‘ type if you intend to send raw bytes.
protobuf报utf-8校验失败问题原因及解决方式
·
1、原始错误信息
com_google_protobuf/src/google/protobuf/wire_format_lite.cc:626
String field 'brpc.policy.RpcMeta.xxx.value' contains invalid UTF-8 data when serializing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
2、原因
实际代码中,将二进制数据(比如序列化后的message数据)赋值给message内的string类型的字段,触发了protobuf内部的UTF-8格式校验,校验失败,导致报错
3、解决方式
方式一(推荐):把message中被赋值的string类型,改为bytes类型;bytes类型不会做UTF-8格式校验;
方式二:增加NDEBUG宏定义,这样protobuf针对string类型,会跳过校验;

更多推荐
所有评论(0)