Google 协议缓冲区错误:“在序列化协议缓冲区时遇到包含无效 UTF-8 数据的字符串" [英] Google Protocol Buffer error: "Encountered string containing invalid UTF-8 data while serializing protocol buffer"

查看:487
本文介绍了Google 协议缓冲区错误:“在序列化协议缓冲区时遇到包含无效 UTF-8 数据的字符串"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码

int lenSend = odl->ByteSize();
char* buf = (char *)malloc(lenSend);
odl->SerializeToArray(buf, lenSend);

我收到此错误,但我不明白为什么会收到此错误(是的,我收到了 3 次):

I get this error and I can't understand why I get it (yes I get it three times):

libprotobuf ERROR google/protobuf/wire_format.cc:1059] 在序列化协议缓冲区时遇到包含无效 UTF-8 数据的字符串.字符串必须仅包含 UTF-8;对原始字节使用 'bytes' 类型.
libprotobuf ERROR google/protobuf/wire_format.cc:1059] 在序列化协议缓冲区时遇到包含无效 UTF-8 数据的字符串.字符串必须仅包含 UTF-8;对原始字节使用 'bytes' 类型.
libprotobuf ERROR google/protobuf/wire_format.cc:1059] 在序列化协议缓冲区时遇到包含无效 UTF-8 数据的字符串.字符串必须仅包含 UTF-8;对原始字节使用 'bytes' 类型.

libprotobuf ERROR google/protobuf/wire_format.cc:1059] Encountered string containing invalid UTF-8 data while serializing protocol buffer. Strings must contain only UTF-8; use the 'bytes' type for raw bytes.
libprotobuf ERROR google/protobuf/wire_format.cc:1059] Encountered string containing invalid UTF-8 data while serializing protocol buffer. Strings must contain only UTF-8; use the 'bytes' type for raw bytes.
libprotobuf ERROR google/protobuf/wire_format.cc:1059] Encountered string containing invalid UTF-8 data while serializing protocol buffer. Strings must contain only UTF-8; use the 'bytes' type for raw bytes.

谢谢.

推荐答案

您可以按照消息中的建议去除警告!

You can get rid of the warning by following the advice in the message!

您必须在 odl(在您的 .proto 文件中)的定义中有一个或多个字段,这些字段被定义为 string 但您将非 UTF-8 个字符.文档声明您不应该这样做.如果您将这些更改为 bytes,警告应该会消失.

You must have a field or fields in the definition of odl (in your .proto file) which are defined as string but into which you are putting non-UTF-8 characters. The docs state that you shouldn't do this. If you change these to bytes, the warnings should disappear.

这篇关于Google 协议缓冲区错误:“在序列化协议缓冲区时遇到包含无效 UTF-8 数据的字符串"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆