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