Skip to main content

LEB128(Little Endian Base 128)

Project description

LEB128

LEB128 or Little Endian Base 128 is a form of variable-length code compression used to store an arbitrarily large integer in a small number of bytes. LEB128 is used in the DWARF debug file format and the WebAssembly binary encoding for all integer literals.

$ pip3 install leb128

leb128 has been used in pywasm and emscripten.

Example

import io
import leb128

# unsigned leb128
assert leb128.u.encode(624485) == bytearray([0xe5, 0x8e, 0x26])
assert leb128.u.decode(bytearray([0xe5, 0x8e, 0x26])) == 624485
assert leb128.u.decode_reader(io.BytesIO(bytearray([0xe5, 0x8e, 0x26]))) == (624485, 3)

#   signed leb128
assert leb128.i.encode(-12345) == bytearray([0xc7, 0x9f, 0x7f])
assert leb128.i.decode(bytearray([0xc7, 0x9f, 0x7f])) == -12345
assert leb128.i.decode_reader(io.BytesIO(bytearray([0xc7, 0x9f, 0x7f]))) == (-12345, 3)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leb128-1.0.8.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

leb128-1.0.8-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page