I ParseFromArray the protocol buffer's protocol, the protocol is not lack any filed. But the ParseFromArray function returns false
. Why?
I'm assuming you are using C++. ParseFromArray()
fails if:
If you are sure that all required fields are set, then it must be the case that your input data is corrupted. You should verify that the bytes and size you are passing into ParseFromArray()
are exactly the bytes and size that you got from SerializeToArray()
and ByteSize()
on the sending side. You will probably find that you are losing some bytes somewhere, or that some bytes got corrupted.
Common reasons for corruption include:
String
, the data will become corrupted, as these channels expect text, and encoded protobufs are not text.char*
, i.e. assuming NUL-termination. Encoded protobufs can contain '\0'
bytes, meaning that you cannot represent one as a char*
alone -- you must include the size separately.SerializeToArray()
, you must also call ByteSize()
to see how large the message is, and you must make sure the receiving end receives that size and passes it to ParseFromArray()
. Otherwise, the parser will think that the extra bytes at the end of the buffer are part of the message, and will fail to parse them.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With