Module avro_decoder_hooks

This module is a collection of eravro supported decoder hooks.

Description

This module is a collection of eravro supported decoder hooks

Decoder hook is an anonymous function to be evaluated by the JSON or binary decoder to amend either schmea or data (input or output).

For example:

A hook can be used to fast-skip undesired data fields of records or undesired data of big maps etc. e.g. To dig out only the field named "MyField" in "MyRecord", the JSON decoder hook may probably look like:

  fun(Type, SubNameOrIndex, Data, DecodeFun) ->
       case {avro:get_type_fullname(Type), SubNameOrIndex} of
         {"com.example.MyRecord", "MyField"} ->
           DecodeFun(Data);
         {"com.example.MyRecord", _OtherFields} ->
           ignored;
         _OtherType ->
           DecodeFun(Data)
       end
  end.
  

A hook can be used for debug. For example, below hook should print the decoding stack along the decode function traverses through the bytes.

  fun(Type, SubNameOrIndex, Data, DecodeFun) ->
       SubInfo = case is_integer(SubNameOrIndex) of
                   true  -> integer_to_list(SubNameOrIndex);
                   false -> SubNameOrIndex
                 end,
       io:format("~s.~s\n", [avro:get_type_name(Type), SubInfo]),
       DecodeFun(Data)
  end
  
A hook can also be used as a monkey patch to fix some corrupted data.

Data Types

count()

count() = non_neg_integer()

Function Index

pretty_print_hist/0This hook prints the type tree with indentation, and the leaf values to the current group leader.
print_debug_trace/2This hook is useful when a decoder has failed on decoding, try to decode it again with this hook to inspect the decode history and the avro type stack where the failure happened NOTE: Always call this API to retrieve the hook, never save the hook and re-use for different decode attempts.
tag_unions/0By default, decoders do not tag union values.

Function Details

pretty_print_hist/0

pretty_print_hist() -> avro:decoder_hook_fun()

This hook prints the type tree with indentation, and the leaf values to the current group leader.

print_debug_trace/2

print_debug_trace(PrintFun::fun((iodata()) -> ok), MaxHistoryLength::count()) -> avro:decoder_hook_fun()

This hook is useful when a decoder has failed on decoding, try to decode it again with this hook to inspect the decode history and the avro type stack where the failure happened NOTE: Always call this API to retrieve the hook, never save the hook and re-use for different decode attempts

tag_unions/0

tag_unions() -> avro:decoder_hook_fun()

By default, decoders do not tag union values. This hook function is to tag union values with union type names NOTE: null values are not tagged


Generated by EDoc