thanks kenton. the string thing worked very well. Paul On Oct 26, 9:20 pm, Kenton Varda <[email protected]> wrote: > The others answered your main question, but there is another problem: > > On Mon, Oct 25, 2010 at 6:45 PM, Paul <[email protected]> wrote: > > char* str_buf; > > str_buf = new char[meas_rec.ByteSize()]; > > string str = str_buf; > > Here you are allocating a char array, and then *copying* it into a > std::string. This does nothing useful, and it may actually crash depending > on the random contents of the allocated array. > > These three lines should be replaced with just: > > string str; > > You do not have to resize the string ahead of time, as this is done > automatically by SerializeToString(). > > > meas_rec.SerializeToString(&str); > > m.set_meas_rec_str(str); > > Incidentally, another, more efficient way to write this would be: > > meas_req.SerializeToString(&m.mutable_meas_rec_str()); > > Also, you probably know this, but just in case: You can just do: > > message Measurement { > required string id = 1; > optional MeasRec meas_rec = 2; > > } > > message MeasRec { > optional int id = 1; > > } > > This way you don't have to manually encode the sub-message.
-- 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.
