Powerful little-endian base-128 encoding/decoding library for Python 3.
Project description
pyleb128
Powerful little-endian base-128 encoding/decoding library for Python 3.
Supports the following types:
- Unsigned LEB128
- Signed LEB128
- Unsigned LEB128 +1 (ULEB128P1)
Note
The LEB classes all inherit from int
and have all the operations implemented. The type of the result from any int operation will always be the type of the lhs. If the lhs is an int, then the type is an int. If the lhs is a LEB type, then the resulting type is a LEB.
Installing
python -m pip install -U pyleb128
Example Usage
from pyleb128 import uleb128, sleb128
# unsigned
print(uleb128(0xffff).size) # 2
print((uleb128(0xffff) * 2).encoded) # b'\xfe\xff\x07'
print(uleb128.decode(b'\xff\xff\x03')) # 65535
print(uleb128.decode(b'\xff\xff\x03').encoded) # b'\xff\xff\x03'
print(uleb128.decode(b'\xff\xff\x03', p1=True)) # decode with as ULEB128P1
# signed
print(sleb128.decode(b'\xf3\xff\xff\xff\x0f')) # -13
print(uleb128.decode(b'\xf3\xff\xff\xff\x0f').encoded) # b'\xf3\xff\xff\xff\x0f'
# can decode from a binary stream, too:
import io
stream = io.BytesIO(b'\xff\xff\x03')
print(uleb128.decode_stream(stream, p1=True))
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
pyleb128-0.2.4.tar.gz
(15.7 kB
view details)
Built Distribution
pyleb128-0.2.4-py3-none-any.whl
(18.6 kB
view details)
File details
Details for the file pyleb128-0.2.4.tar.gz
.
File metadata
- Download URL: pyleb128-0.2.4.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.4 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bcd3339e65eb319b78acb8036e28a15c8bfee68237f3f42e0c69ea12e252541 |
|
MD5 | b57e951aec31d9872b397a1954fbf3c9 |
|
BLAKE2b-256 | 26a82cf3d0ec4a73abd8fc2b1e059bb540842c3ca9f927b33099467ea89f38b4 |
File details
Details for the file pyleb128-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: pyleb128-0.2.4-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.4 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c24de16ef33369e37a26f636f398039e411d13df6a9dc69cda544a7c617ec49 |
|
MD5 | 5b5192154779c017d3cf0685e2804fe7 |
|
BLAKE2b-256 | e93bd66071706d5a006f1e7f975ad3ba315f8f1c0ea7f983195cc9453a40f46f |