On Mon, Oct 25, 2010 at 18:45, Paul <[email protected]> wrote: > 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?
'bytes' will be the same std::string type in C++. The only differnce is that it is not checked for UTF8-ness. > > Also, once I have it on the Java side, how do I deserialize? > would I use parseFrom(byte[] data) ? yes. > > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
