BSV-ex v0.2.3 BSV.Util.VarBin View Source
Module for parsing and serializing variable length binary data as integers, binaries and structs.
Link to this section Summary
Functions
Parses the given binary into a chunk of binary data, using the first byte(s) to determing the size of the chunk. Returns a tuple containing the chunk and any remaining binary data.
Parses the given binary into an integer. Returns a tuple containing the decoded integer and any remaining binary data.
Parses the given binary into a list of parsed structs, using the first byte(s) to determing the number of items, and calling the given callback to parse each repsective chunk of data.
Prefixes the given binary with a variable length integer to indicate the size of the following binary,
Serializes the given integer into a binary.
Serializes the given list of items into a binary, first by prefixing the binary with a variable length integer to indicate the number of items, and then by calling the given callback to serialize each respective item.
Link to this section Functions
Parses the given binary into a chunk of binary data, using the first byte(s) to determing the size of the chunk. Returns a tuple containing the chunk and any remaining binary data.
Examples
iex> BSV.Util.VarBin.parse_bin(<<5, 104, 101, 108, 108, 111>>)
{"hello", ""}
Parses the given binary into an integer. Returns a tuple containing the decoded integer and any remaining binary data.
Examples
iex> BSV.Util.VarBin.parse_int(<<253, 4, 1>>)
{260, ""}
iex> BSV.Util.VarBin.parse_int(<<254, 0, 225, 245, 5>>)
{100_000_000, ""}
Parses the given binary into a list of parsed structs, using the first byte(s) to determing the number of items, and calling the given callback to parse each repsective chunk of data.
Returns a tuple containing a list of parsed items and any remaining binary data.
Examples
BSV.Util.VarBin.parse_items(data, &BSV.Transaction.Input.parse/1)
{[
%BSV.Trasaction.Input{},
%BSV.Trasaction.Input{}
], ""}
Prefixes the given binary with a variable length integer to indicate the size of the following binary,
Examples
iex> BSV.Util.VarBin.serialize_bin("hello")
<<5, 104, 101, 108, 108, 111>>
Serializes the given integer into a binary.
Examples
iex> BSV.Util.VarBin.serialize_int(260)
<<253, 4, 1>>
iex> BSV.Util.VarBin.serialize_int(100_000_000)
<<254, 0, 225, 245, 5>>
Serializes the given list of items into a binary, first by prefixing the binary with a variable length integer to indicate the number of items, and then by calling the given callback to serialize each respective item.
Examples
[
%BSV.Trasaction.Input{},
%BSV.Trasaction.Input{}
]
|> BSV.Util.VarBin.serialize_items(data, &BSV.Transaction.Input.serialize/1)
<< data >>