gleb128

Functions

pub fn decode_signed(
  data: BitArray,
) -> Result(#(Int, Int), String)

Decodes a bit array containing some LEB128 integer as an signed (positive or negative) native integer.

Returns a tuple containing the decoded value in its first position, followed by the count of bytes read in its second position. Returns an error when the given data can’t be decoded.

pub fn decode_unsigned(
  data: BitArray,
) -> Result(#(Int, Int), String)

Decodes a bit array containing some LEB128 integer as an unsigned (positive) native integer.

Returns a tuple containing the decoded value in its first position, followed by the count of bytes read in its second position. Returns an error when the given data can’t be decoded.

pub fn encode_signed(value: Int) -> BitArray

Encodes an signed (positive or negative) integer to a bit array containing its LEB128 representation.

pub fn encode_unsigned(value: Int) -> Result(BitArray, String)

Encodes an unsigned (positive) integer to a bit array containing its LEB128 representation.

Returns an error when the given value to encode is negative.

pub fn fast_decode_signed(
  data: BitArray,
) -> Result(#(Int, Int), String)

Decodes a bit array containing some LEB128 integer as an signed (positive or negative) native integer. When the length of the data is less than or equal to 8 bytes, this function will treat and process the data as an native integer, thus enabling a performance boost. It will fallback to the default decoding function when the length of the data is greater than 8 bytes.

Returns a tuple containing the decoded value in its first position, followed by the count of bytes read in its second position. Returns an error when the given data can’t be decoded.

pub fn fast_decode_unsigned(
  data: BitArray,
) -> Result(#(Int, Int), String)

Decodes a bit array containing some LEB128 integer as an unsigned (positive) native integer. When the length of the data is less than or equal to 8 bytes, this function will treat and process the data as an native integer, thus enabling a performance boost. It will fallback to the default decoding function when the length of the data is greater than 8 bytes.

Returns a tuple containing the decoded value in its first position, followed by the count of bytes read in its second position. Returns an error when the given data can’t be decoded.

Search Document