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.
The idea is to support
:packeroption inpack/2that defaults toMsgpax.Packer.This way any default packing can be overwritten with:
Where
use Msgpax.Packerexpands to@behaviour Msgpax.Packerand also defines the@before_compilecallback that should injectMsgpax.Packer.packfor catch-all clause.We still need to think how to efficiently pass the user-provided packer into
Msgpax.Packerfor usage when unpacking collections.