View Source Varu64 (Varu64 v1.0.1)
Simple variable-length encoding of U64
Summary
Functions
@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"}
@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>>