gleb128
Functions
pub fn decode_signed(data: BitArray) -> Result(#(Int, Int), Nil)
Decodes a bit array containing some LEB128 integer as an signed (positive or negative) 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.
This function is designed to optimize small inputs (whose length is less than or equal to 8 bytes) by treating them as integers; since the input size is close to the word size of a 64-bit CPU, the Erlang runtime will internally treat it as a “native” integer and not as a bignum/boxed integer (which are stored on the heap and referenced via pointers), thus significantly reducing memory consumption and speeding up arithmetic operations. See erl_arith.c.
pub fn decode_unsigned(
data: BitArray,
) -> Result(#(Int, Int), Nil)
Decodes a bit array containing some LEB128 integer as an unsigned (positive) 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.
This function is designed to optimize small inputs (whose length is less than or equal to 8 bytes) by treating them as integers; since the input size is close to the word size of a 64-bit CPU, the Erlang runtime will internally treat it as a “native” integer and not as a bignum/boxed integer (which are stored on the heap and referenced via pointers), thus significantly reducing memory consumption and speeding up arithmetic operations. See erl_arith.c.
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, Nil)
Encodes an unsigned (positive) integer to a bit array containing its LEB128 representation.
Returns an error when the given value to encode is negative.