Skip to content
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

Make default packing configurable #60

Open
lexmag opened this issue Jan 25, 2021 · 1 comment · May be fixed by #68
Open

Make default packing configurable #60

lexmag opened this issue Jan 25, 2021 · 1 comment · May be fixed by #68

Comments

@lexmag
Copy link
Owner

lexmag commented Jan 25, 2021

The idea is to support :packer option in pack/2 that defaults to Msgpax.Packer.
This way any default packing can be overwritten with:

defmodule MyPacker do
  use Msgpax.Packer

  def pack(value) when is_float(value) do
    # pack into 32-bit format
  end
end

Where use Msgpax.Packer expands to @behaviour Msgpax.Packer and also defines the @before_compile callback that should inject Msgpax.Packer.pack for catch-all clause.

We still need to think how to efficiently pass the user-provided packer into Msgpax.Packer for usage when unpacking collections.

@elcritch
Copy link

It seems like a good way to handle it, but I'm not sure I follow all the details. Would this impose a performance hit on every user of the library? My first thought was to always check an option and do a callback, but that's probably too slow. I haven't used @before_compile before. It would be able to (at compile time) add the user defined protocol handler and override the default one?

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 a pull request may close this issue.

2 participants