Skip to content

encoding.leb128 #

The LEB128 decoders return the decoded integer and the number of input bytes consumed. All four decoders return (0, 0) for empty or truncated input. Overflow returns zero and the negative number of bytes inspected (at most 5 for 32-bit values and 10 for 64-bit values). Signed decoders validate that unused bits in the final byte extend the sign correctly. Non-minimal encodings are accepted when their value fits the target integer type.

fn decode_i32 #

fn decode_i32(value []u8) (i32, int)

decode_i32 decodes an i32 and returns the number of bytes used from the given leb128 encoded array value. A non-positive length means the input did not hold a complete value: 0 for a truncated or empty buffer, and a negative length for an overflowing one, like Go's encoding/binary varint functions.

fn decode_i64 #

fn decode_i64(value []u8) (i64, int)

decode_i64 decodes an i64 and returns the number of bytes used from the given leb128 encoded array value. A non-positive length means the input did not hold a complete value: 0 for a truncated or empty buffer, and a negative length for an overflowing one, like Go's encoding/binary varint functions.

fn decode_u32 #

fn decode_u32(value []u8) (u32, int)

decode_u32 decodes an u32 and returns the number of bytes used from the given leb128 encoded array value. A non-positive length means the input did not hold a complete value: 0 for a truncated or empty buffer, and a negative length for an overflowing one, like Go's encoding/binary.Uvarint.

fn decode_u64 #

fn decode_u64(value []u8) (u64, int)

decode_u64 decodes an u64 and returns the number of bytes used from the given leb128 encoded array value. A non-positive length means the input did not hold a complete value: 0 for a truncated or empty buffer, and a negative length for an overflowing one, like Go's encoding/binary.Uvarint.

fn encode_i32 #

fn encode_i32(value i32) []u8

encode_i32 encodes the value as leb128 encoded byte array

fn encode_i64 #

fn encode_i64(value i64) []u8

encode_i64 encodes the value as leb128 encoded byte array

fn encode_u32 #

fn encode_u32(value u32) []u8

encode_u32 encodes the value as leb128 encoded byte array

fn encode_u64 #

fn encode_u64(value u64) []u8

encode_u64 encodes the value as leb128 encoded byte array