Simple type-length-value. Type and length are encoded as Varu64

Summary

Functions

Decode arbitrary binary in stlv form.

Encode arbitrary binary in stlv form.

Functions

decode(stlv)

@spec decode(binary()) :: {non_neg_integer(), binary(), binary()} | :error

Decode arbitrary binary in stlv form.

Returns {type, value, rest_of_binary} on success.

Examples

iex> Stlv.decode(<<249, 1, 0, 4, 240, 159, 146, 169, 77, 111, 114, 101>>)
{256, "💩", "More"}

encode(value, type)

@spec encode(binary(), non_neg_integer()) :: binary()

Encode arbitrary binary in stlv form.

Examples

iex> Stlv.encode("💩", 256)               
<<249, 1, 0, 4, 240, 159, 146, 169>>