API Reference bin_struct v0.2.16
Modules
Overview
iex> defmodule SimpleChildStruct do
...> use BinStruct
...> field :data, :uint8
...> end
...>
...> defmodule SimpleStructWithChild do
...> use BinStruct
...> field :child, SimpleChildStruct
...> end
...>
...> SimpleStructWithChild.new(child: SimpleChildStruct.new(data: 1))
...> |> SimpleStructWithChild.dump_binary()
...> |> SimpleStructWithChild.parse()
...> |> then(fn {:ok, struct, _rest } -> struct end)
...> |> SimpleStructWithChild.decode()
%{ child: SimpleChildStruct.new(data: 1) }
As you can see from example on above parsed structs and newly created are always equal thanks to intermediate type conversion called unmanaged
.
It's neither binary or managed and you are not suppose to work with it directly, by any type (including custom types) can perform
automatic type conversion between binary
, managed
and unmanaged
on developer request (using registered_callback
api)
Asn1 is BinStructCustomType
and it uses erlang asn1
compiler output as implementation.
A custom type for handling recursive structures within BinStruct
.
Terminated binary implemented as BinStructCustomType
.
Useful in registered_callbacks
when library can't achieve automatic type conversion.
Useful in registered_callbacks
when library can't achieve automatic type conversion.
Useful in registered_callbacks
when library can't achieve automatic type conversion.
Useful in registered_callbacks
when library can't achieve automatic type conversion.
Useful in registered_callbacks
when library can't achieve automatic type conversion.
BinStructCustomType
is user defined type when you need most control of how data are parsed.
iex> defmodule SharedOptions do
...> use BinStructOptionsInterface
...>
...> @type runtime_context1 :: :context_a
...> @type runtime_context2 :: :context_b
...>
...> register_option :runtime_context1
...> register_option :runtime_context2
...>
...> end
...>
...> SharedOptions.option_runtime_context1(:context_a)
...> |> SharedOptions.option_runtime_context2(:context_b)