View Source Riot.Util.Varint.LEB128 (Riot LoR v1.0.0)

More on LEB128:

Other LEB128 implementations:

Link to this section Summary

Functions

Decodes all varint sequences

Decodes the next varint sequence

Encode an integer to a varint sequence

Link to this section Functions

Link to this function

decode_all(subject, sign \\ :unsigned)

View Source (since 1.0.0)
@spec decode_all(bitstring(), :unsigned | :signed) ::
  {[integer()], bitstring(), integer()}

Decodes all varint sequences

examples

Examples

iex> Riot.Util.Varint.LEB128.decode_all(<<8, 172, 2, 151, 195, 6>>)
{[8, 300, 106903], "", 6}
Link to this function

decode_next(subject, sign \\ :unsigned)

View Source (since 1.0.0)
@spec decode_next(bitstring(), :unsigned | :signed) ::
  {integer(), bitstring(), integer()}

Decodes the next varint sequence

examples

Examples

iex> {_, rest, _} = Riot.Util.Varint.LEB128.decode_next(<<8, 172, 2>>)
{8, <<172, 2>>, 1}
iex> Riot.Util.Varint.LEB128.decode_next(rest)
{300, "", 2}
Link to this function

encode(int, sign \\ :unsigned)

View Source (since 1.0.0)
@spec encode(integer(), :unsigned | :signed) :: bitstring()

Encode an integer to a varint sequence

examples

Examples

iex> Riot.Util.Varint.LEB128.encode(999)
<<231, 7>>