Closed rolandtritsch closed 5 years ago
I think you are calling out that in protobuf3 you get empty strings back and not nils when the input value was nil, right @rolandtritsch? This error from the build:
test/protobuf_test.exs:142
Assertion with == failed
code: assert basic == decoded
left: %ProtobufTest.Basic{f1: 1, f2: nil}
right: %ProtobufTest.Basic{f1: 1, f2: ""}
stacktrace:
test/protobuf_test.exs:149: (test)
@bitwalker @relistan Sorry. Yes. Correct :).
@relistan BTW ... this not only fails for strings. It fails for all optional fields (e.g. for integers a field with value 0 will show up out of nowhere :)).
https://developers.google.com/protocol-buffers/docs/proto3#default
Interesting ...
When you research this a little bit more, then you will find out that nil
s and all default values for all data scalar types (e.g. empty string, 0, etc.) are not serialized to the wire and that on the way back all missing fields are initialized with the default values (because by the time you decode/de-serialize a buffer, you cannot figure out anymore if the field is not there because it was nil
or the default value).
Exec Summary: The implemented behavior is correct. I am closing this PR. (cc: @relistan)
Hi All,
just stumbled over this testcase.
The proto2 behavior makes sense to me.
The proto3 behavior not so much.
Is this a bug?
Regards ... Roland