Skip to content

Conversation

@ximus
Copy link

@ximus ximus commented Dec 8, 2023

I used maps in my app, and it failed.

Under the hood, maps are implemented as repeated messages of two fields key, value. They are described as such in the descriptor tree, with the only particularity is that the "virtual" key/value message has an option called map_entry set.

The current version of the_pb handles map types naively as those repeated messages. It converts { "foo" => "bar" } to [<MapEntry key="foo", value="bar">]. You would think this is correct, but the whenklass.new(params) is executed, protobuf throws an error. Protobufs actually wants a hash object for the map type. It handles the Hash to MapEntry[] conversion itself.

This fixes it. I'm sure the code could be better, let me know if you want changes.

Without the code change, new test cases would fail.

This also updates gems in the same PR, sorry. It was necessary to run on ruby 3.2 which is what I have installed. Also there is little activity on this project so it should not bother, let me know.

end
end

def serialize(descriptor, value)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better name?

@stomk stomk requested review from a team and qnighy and removed request for a team December 19, 2023 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant