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)

Performance

Since I used the most optimized algorithm, it is likely to be the fastest among all pure Python implementations of leb128. The detailed results can refer to the table, which is the result of using a very low-performance CPU.

Case Duration
U encode 1000000 times 0.865 s
U decode 1000000 times 0.808 s
I encode 1000000 times 0.762 s
I decode 1000000 times 0.835 s

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.7.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leb128-1.0.7-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file leb128-1.0.7.tar.gz.

File metadata

  • Download URL: leb128-1.0.7.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for leb128-1.0.7.tar.gz
Algorithm Hash digest
SHA256 a00c9f180e9b6543847fd1d89db5f6a43880588613ab5be8a18b0cbc5ebae18a
MD5 94b7b893d149eef492dc3e21d7d69022
BLAKE2b-256 35c456c40e3c8ae3c6282ecc19c90be03f16efe51d1cd49886bc9fdb52a2696d

See more details on using hashes here.

File details

Details for the file leb128-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: leb128-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for leb128-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 7e89d6c0961f406402618523b46e4eae08208913fb805a9d0f59ce3a10a211d0
MD5 06e2522061f6f2ae819c99237b196667
BLAKE2b-256 f0b13d01ba9b73d1338a22f9e037865efe5313d869d4a977c55928a0d47bd2e6

See more details on using hashes here.

Supported by

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