Thank you, that sounds very convincing. Buffer is in deed just a uchar array. I already prepend the length of the message before I send it via TCP, so I can easily pass this value to ParseFromArray. Thanks :)
2013/8/15 Christopher Head <[email protected]> > On Thu, 15 Aug 2013 08:48:42 -0700 (PDT) > Nikolas Engelhard <[email protected]> wrote: > > > > > Hello > > > > I have a strange problem and need some assistance: I just started > > using protobuf and transmit the serialized messages via TCP-Sockets > > from Python to C++. This works very well if I don't use floats in > > the .proto files. As soon as a message is read, it is parsed via > > ParseFromString(buffer). I used so far the addressbook.proto and > > amessage.proto from the examples and everything worked well. I the > > just wrote a new proto containing a single required float and > > ParseFromString now returns false and also fails to extract the float > > value from the message. If I just replace the float with an int32, > > the message is correctly parsed and ParseFromString returns True. I > > have no idea what I'm doing wrong, so it would be great if someone > > could help me out. > > > > Cheers, > > Nikolas > > > > You never mentioned what data type “buffer” is. The ParseFromString > function takes an std::string. If “buffer” is an array of char/unsigned > char/uint8_t/something similar, you are implicitly invoking the > std::string constructor taking a single const char* parameter, and that > constructor constructs the std::string by assuming the pointed-to > buffer is NUL-terminated, which Protobuf data is not (Protobuf encoded > data can contain bytes whose values are zero). If your buffer is indeed > an array, use ParseFromArray instead of ParseFromString, and pass the > proper size (Protobuf messages are not inherently length-prefixed nor > delimited, so you must pass the size of the encoded data yourself). > > Chris > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/groups/opt_out.
