Hi,
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;
meas_rec.set_id(100);
char* str_buf;
str_buf = new char[meas_rec.ByteSize()];
string str = str_buf;
meas_rec.SerializeToString(&str);
m.set_meas_rec_str(str);

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

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.

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) ?

Thanks,
Paul

-- 
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 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to