I am trying to serialize a protocol buffers message into a string that
is contained in another protocol buffer.  I am doing the serialization
on the C++ side.

// This is the outer protocol buffer
message Measurement {
  required string id = 1;
  optional string meas_rec_str = 2;
Measurement m;

// This is the protocol buffer message I want to serialize into a
string and store inside meas_rec.
message MeasRec {
  optional int id = 1;

To serialize the MeasRec message, I am doing:
MeasRec meas_rec;
char* str_buf;
str_buf = new char[meas_rec.ByteSize()];
string str = str_buf;

However, when I do this, I encounter the following error on the C++

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

how do I serialize meas_rec into "bytes" instead?

Also, once I have it on the Java side, how do I deserialize?
would I use parseFrom(byte[] data) ?


You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to