protobuf
protobuf copied to clipboard
gogo vs gogofast: different behavior on invalid field encoding
We discovered that Java & gogo treat a message with an invalid field encoding as an unrecognized field, while gogofast treats it as an unmarshal error. I'm not sure if this is important or not.
Details
This protobuf message:
enum Bool {
FALSE = 0;
TRUE = 1;
NULL = 2;
}
optional Bool bit = 19 [default = NULL];
Incorrectly encoded as:
9a 01 04
^
1 0011 = field number 19
010 = wire type 2, length delimited
^
0000 0001 = 1 length
.. does not report an unmarshal error using gogo, but does using gogofast.
It also does not report an error from the Java library.
It appears that gogo treats it as an unrecognized field instead of a decoding error. I'm not sure what the spec requires in this case.
Reproducer
Here's a reproducer; run genprotos.sh with gogo or gogofast and then run main.go to unmarshal the checked-in message: https://github.com/robfig/gogofast-repro