Open pallix opened 5 years ago
It would be better if the decode function would fail with an explicit error instead of giving an invalid result.
Thinking more about it, a failure would not be preferable as this would prevent to decode the message at all: some applications may want to retrieve the available data even if the oneof field cannot be decoded.
The real problem is that it is not possible to distinguish between a missing oneof field and an undecodable oneof field.
When decoding a message using a oneof with a field that has not been defined by the code doing the decoding, no error is thrown. Instead, the field has the
nil
value. It would be better if the decode function would fail with an explicit error instead of giving an invalid result.Example:
one_of.proto
This code:
will return: