LEB128 Encoding


LEB128 (Little Endian Base 128) is a variable-length encoding format designed to store arbitrarily large integers in a small number of bytes. There are two versions: unsigned and signed. These vary slightly, so a user program that wants to decode LEB128 values should use the appropriate unsigned or signed decode method.

Unsigned LEB128:
>uleb128 ( n: integer -- byte-array )

uleb128> ( byte-array: byte-array -- n )

write-uleb128 ( n -- )

stream-write-uleb128 ( n: integer stream -- )

read-uleb128 ( -- n )

stream-read-uleb128 ( stream -- n )


Signed LEB128:
>leb128 ( n: integer -- byte-array )

leb128> ( byte-array: byte-array -- n )

write-leb128 ( n -- )

stream-write-leb128 ( n: integer stream -- )

read-leb128 ( -- n )

stream-read-leb128 ( stream -- n )