Bijou64 (Bijou64 v0.1.2)

Copy Markdown View Source

Bijou64 is a purely canonical variable length encoding for u64 integers.

Each integer can only be represented by a single encoded value, which aids security if the data is signed.

See https://www.inkandswitch.com/tangents/bijou64/

Summary

Types

Valid integers are unsigned integers up to 64 bits.

Functions

Decodes valid u64 integers according to the bijou64 format from the start of a binary.

Encodes valid u64 integers according to the bijou64 format.

Types

u64()

@type u64() :: 0..18_446_744_073_709_551_615

Valid integers are unsigned integers up to 64 bits.

Functions

decode(arg)

@spec decode(binary()) :: {u64(), binary()}

Decodes valid u64 integers according to the bijou64 format from the start of a binary.

iex> Bijou64.decode(<<0>>)
{0, ""}

iex> Bijou64.decode(<<247>>)
{247, ""}

iex> Bijou64.decode(<<248, 0>>)
{248, ""}

iex> Bijou64.decode(<<255, 254, 254, 254, 254, 254, 254, 254, 7>>)
{18446744073709551615, ""}

encode(int)

@spec encode(u64()) :: binary()

Encodes valid u64 integers according to the bijou64 format.

iex> Bijou64.encode(0)
<<0>>

iex> Bijou64.encode(247)
<<247>>

iex> Bijou64.encode(248)
<<248, 0>>

iex> Bijou64.encode(2 ** 64 - 1)
<<255, 254, 254, 254, 254, 254, 254, 254, 7>>