On Thu, 15 Aug 2013 08:48:42 -0700 (PDT)
Nikolas Engelhard <engelhard.niko...@gmail.com> 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).


Attachment: signature.asc
Description: PGP signature

Reply via email to