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 is used in pywasm, which the WebAssembly virtual machine.
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(-123456) == bytearray([0xc0, 0xbb, 0x78])
assert leb128.i.decode(bytearray([0xc0, 0xbb, 0x78])) == -123456
assert leb128.i.decode_reader(io.BytesIO(bytearray([0xc0, 0xbb, 0x78]))) == (-123456, 3)
Performance
Since I used the most optimized algorithm, it is likely to be the fastest among all pure Python implementations of leb128.
| 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
Release history Release notifications | RSS feed
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.4.tar.gz
(2.6 kB
view details)
File details
Details for the file leb128-1.0.4.tar.gz.
File metadata
- Download URL: leb128-1.0.4.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3552deeae400b835f86e0d32eb7c737a75eb167c0eb551b70268d522633581af
|
|
| MD5 |
0aac4a367cc461ff1018bad2365d8c9d
|
|
| BLAKE2b-256 |
322bbe0f3e71d892cb024ffd4a824f7aa9727272a2dae4b7f6bf9d498efd8284
|