Module avro_union

Implements unions support for Avro.

Authors: Ilya Staheev (ilya.staheev@klarna.com).

Description

Implements unions support for Avro.

Unions may not contain more than one schema with the same type, except for the named types record, fixed and enum. For example, unions containing two array types or two map types are not permitted, but two types with different names are permitted. (Names permit efficient resolution when reading and writing unions.)

Unions may not immediately contain other unions.

Data Types

array_type()

array_type() = #avro_array_type{type = avro:type_or_name(), custom = [avro:custom_prop()]}

avro_binary()

avro_binary() = iolist()

avro_json()

avro_json() = jsone:json_object()

avro_type()

avro_type() = primitive_type() | array_type() | enum_type() | fixed_type() | map_type() | record_type() | union_type()

avro_value()

avro_value() = avro:canonicalized_value() | #avro_value{type = avro:type_or_name(), data = avro:avro_value()} | [#avro_value{type = avro:type_or_name(), data = avro:avro_value()}] | [{avro:name(), #avro_value{type = avro:type_or_name(), data = avro:avro_value()}}] | avro_map:data() | {json, binary()} | {binary, binary()}

encode_fun()

encode_fun() = fun((avro_type(), avro:in(), union_index()) -> encode_result())

encode_result()

encode_result() = avro_binary() | avro_json()

enum_type()

enum_type() = #avro_enum_type{name = avro:name(), namespace = avro:namespace(), aliases = [avro:name()], doc = avro:typedoc(), symbols = [avro:enum_symbol()], fullname = avro:fullname(), custom = [avro:custom_prop()]}

fixed_type()

fixed_type() = #avro_fixed_type{name = avro:name(), namespace = avro:namespace(), aliases = [avro:name()], size = pos_integer(), fullname = avro:fullname(), custom = [avro:custom_prop()]}

id2type()

id2type() = gb_trees:tree(union_index(), type_or_name())

map_type()

map_type() = #avro_map_type{type = avro:type_or_name(), custom = [avro:custom_prop()]}

name()

name() = binary()

name2id()

name2id() = gb_trees:tree(name(), {union_index(), boolean()})

name_raw()

name_raw() = atom() | string() | binary()

namespace()

namespace() = binary()

primitive_type()

primitive_type() = #avro_primitive_type{name = avro:name(), custom = [avro:custom_prop()]}

record_type()

record_type() = #avro_record_type{name = avro:name(), namespace = avro:namespace(), doc = avro:typedoc(), aliases = [avro:name()], fields = [avro:record_field()], fullname = avro:fullname(), custom = [avro:custom_prop()]}

type_or_name()

type_or_name() = avro_type() | name_raw()

union_index()

union_index() = non_neg_integer()

union_type()

union_type() = #avro_union_type{id2type = avro_union:id2type(), name2id = avro_union:name2id()}

Function Index

encode/3Encode shared logic for JSON and binary encoder.
get_child_type_index/1Get member type index.
get_types/1Get the union member types in a list.
get_value/1Get current value of a union type variable.
lookup_type/2Search for a union member by its index or full name.
new/2Create a wrapped (boxed) value.
resolve_fullname/2Resolve fullname by newly discovered enclosing namespace.
to_term/1Recursively unbox typed value.
type/1Define a union type.
update_member_types/2Update member types by evaluating callback function.

Function Details

encode/3

encode(Type::type_or_name(), Value::avro:in(), EncodeFun::encode_fun()) -> encode_result() | no_return()

Encode shared logic for JSON and binary encoder. Encoding logic is implemented in EncodeFun.

get_child_type_index/1

get_child_type_index(Union::avro_value()) -> union_index()

Get member type index.

get_types/1

get_types(Avro_union_type::union_type()) -> [avro_type()]

Get the union member types in a list.

get_value/1

get_value(Union) -> any()

Get current value of a union type variable

lookup_type/2

lookup_type(Id::name_raw() | union_index(), Avro_union_type::union_type()) -> {ok, avro_type() | name()} | false

Search for a union member by its index or full name.

new/2

new(Type::union_type(), Value::avro:in()) -> avro_value() | no_return()

Create a wrapped (boxed) value.

resolve_fullname/2

resolve_fullname(Union::union_type(), Ns::namespace()) -> union_type()

Resolve fullname by newly discovered enclosing namespace.

to_term/1

to_term(Union::avro_value()) -> term()

Recursively unbox typed value.

type/1

type(Types0::[type_or_name()]) -> union_type() | no_return()

Define a union type. Exception when any of the below constraints is violated: 1. A union should have at least one member and no duplication 2. Union should no have union as direct member 3. No duplicated types are allowed in members

update_member_types/2

update_member_types(T0::union_type(), F::fun((type_or_name()) -> type_or_name())) -> union_type()

Update member types by evaluating callback function.


Generated by EDoc