Skip to content

Decoder hook ๐Ÿช finnaly available

Choose a tag to compare

@Strech Strech released this 16 Mar 22:06
· 42 commits to master since this release

Initially, the decoder hook was done as a non-configurable no-op function due to clarity โ€“ how much it will be used and will be at all?. Seems the time has come, thanks to the @LostKobrakai ๐Ÿ’œ

The very first use-case is tagging unions, check this out:

defmodule MyClient do
  use Avrora.Client,
    decoder_hook: &__MODULE__.hook/4

  def hook(type, sub_name_or_index, data, decode_fun) do
    tag_unions_hook = :avro_decoder_hooks.tag_unions()
    tag_unions_hook.(type, sub_name_or_index, data, decode_fun)
  end
end

Now all the complex unions will be tagged and result will be passed to the "private" Avrora decoder hook. But there is no limit on what you can do with it, just don't forget to call at the end decode_fun.(data) ๐Ÿ˜‰

Have fun ๐ŸŸ ๐Ÿช