View Source Tezex.Micheline (tezex v2.0.0)

Serialize/deserialize data to/from Tezos Micheline optimized binary representation.

Summary

Functions

Serialize a piece of data to its optimized binary representation.

Deserialize a piece of data from its optimized binary representation.

Types

@type pack_types() :: nil | :address | :bytes | :int | :key_hash | :nat | :string
@type unpack_result() :: binary() | integer() | map() | [unpack_result()]

Functions

Link to this function

pack(value, type \\ nil)

View Source
@spec pack(binary() | integer() | map(), pack_types()) :: nonempty_binary()

Serialize a piece of data to its optimized binary representation.

Examples

iex> pack(-6407, :int)
"0500c764"
iex> pack(%{"prim" => "Pair", "args" => [%{"int" => "-33"}, %{"int" => "71"}]})
"0507070061008701"
Link to this function

unpack(hex_value, type \\ nil)

View Source
@spec unpack(binary(), pack_types()) :: unpack_result()

Deserialize a piece of data from its optimized binary representation.

Examples

iex> unpack("050a0000001601e67bac124dff100a57644de0cf26d341ebf9492600", :address)
"KT1VbT8n6YbrzPSjdAscKfJGDDNafB5yHn1H"
iex> unpack("0507070001000c")
%{"prim" => "Pair", "args" => [%{"int" => "1"}, %{"int" => "12"}]}