Varu64 (Varu64 v1.0.2)

View Source

Simple variable-length encoding of U64

Summary

Functions

Decode a Varu64 at the head of a binary

Encode to Varu64 format

Functions

decode(b)

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

Decode a Varu64 at the head of a binary

Returns a {u64, rest_of_binary} tuple on success :error on failure. Will fail on noncanonical representations

Examples

iex> Varu64.decode(<<0>>)
{0, ""}
iex> Varu64.decode(<<248, 255, 72, 105>>)
{255, "Hi"}

encode(n)

@spec encode(non_neg_integer()) :: binary() | :error

Encode to Varu64 format

Examples

iex> Varu64.encode(0)
<<0>>
iex> Varu64.encode(18446744073709551615)
<<255, 255, 255, 255, 255, 255, 255, 255, 255>>