View Source LEB128 (LEB128 v1.0.0)

Module for encoding and decoding LEB128 (Little Endian Base 128) encoded numbers. Reference: https://en.wikipedia.org/wiki/LEB128#Unsigned_LEB128

Usage

iex> LEB128.encode_unsigned(624_485)
<<0xE5, 0x8E, 0x26>>

iex> LEB128.decode_unsigned!(<<0xE5, 0x8E, 0x26>>)
{624_485, ""}

iex> LEB128.decode_unsigned!(<<0xE5, 0x8E>>)
{:error, :incomplete}

Summary

Functions

Decodes a signed LEB128 encoded number.

Decodes a signed LEB128 encoded number. Crashes if the input is invalid.

Decodes an unsigned LEB128 encoded number.

Decodes an unsigned LEB128 encoded number. Crashes if the input is invalid.

Encodes a signed LEB128 encoded number.

Encodes an unsigned LEB128 encoded number.

Functions

Decodes a signed LEB128 encoded number.

Example:

iex> LEB128.decode_signed(<<0xC0, 0xBB, 0x78>>)
{:ok, -123_456, ""}
iex> LEB128.decode_signed(<<0xE5, 0x8E>>)
{:error, :incomplete}

Decodes a signed LEB128 encoded number. Crashes if the input is invalid.

Example:

iex> LEB128.decode_signed!(<<0xC0, 0xBB, 0x78>>)
{-123_456, ""}

Decodes an unsigned LEB128 encoded number.

Example:

iex> LEB128.decode_unsigned(<<0xE5, 0x8E, 0x26>>)
{:ok, 624_485, ""}
iex> LEB128.decode_unsigned(<<0xE5, 0x8E>>)
{:error, :incomplete}

Decodes an unsigned LEB128 encoded number. Crashes if the input is invalid.

Example:

iex> LEB128.decode_unsigned!(<<0xE5, 0x8E, 0x26>>)
{624_485, ""}

Encodes a signed LEB128 encoded number.

Example:

iex> LEB128.encode_signed(-123_456)
<<0xC0, 0xBB, 0x78>>

Encodes an unsigned LEB128 encoded number.

Example:

iex> LEB128.encode_unsigned(624_485)
<<0xE5, 0x8E, 0x26>>