-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix decoding of maps to match conformance tests #391
Conversation
test "map i32 i32" do | ||
mod = ProtobufTestMessages.Proto2.TestAllTypesProto2 | ||
problematic_payload = <<194, 3, 0>> | ||
assert m = %{map_int32_int32: %{0 => 0}} = mod.decode(problematic_payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without my change, the problematic map decodes to %{nil => nil}
instead of %{0 => 0}
, which is the desired behaviour.
lib/protobuf/decoder.ex
Outdated
val = | ||
if map?, | ||
do: %{ | ||
(embedded_msg.key || map_default(prop, :key)) => | ||
embedded_msg.value || map_default(prop, :value) | ||
}, | ||
else: embedded_msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit but we'll probably want a do
/end
here rather than the inline do:
.
Also, is this gonna be fine with booleans?
Different from the previous fixes in #390, I'm not 100% sure about this one. Feels like it could/should be solved in a different layer, but I didn't find a better way to do it without breaking anything else.