title: Google Protocol Buffer error: "Encountered string containing invalid UTF-8 data while serializing protocol buffer"
body: <p>I am using the following code </p>
  
  <pre><code>int lenSend = odl-&gt;ByteSize();
  char* buf = (char *)malloc(lenSend);
  odl-&gt;SerializeToArray(buf, lenSend);
  </code></pre>
  
  <p>I get this error and I can't understand why I get it (yes I get it three times):</p>
  
  <blockquote>
    <p>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.<br>
    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.<br>
    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.  </p>
  </blockquote>
  
  <p>Thanks.</p>