Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Protocol Buffer error: "Encountered string containing invalid UTF-8 data while serializing protocol buffer"

I am using the following code

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

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] 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.

Thanks.

like image 681
user1676605 Avatar asked Feb 28 '13 15:02

user1676605


1 Answers

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

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.

like image 196
Fraser Avatar answered Oct 05 '22 08:10

Fraser