Skip to main content

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


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

Uploaded Source

Built Distribution

pyleb128-0.2.3-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file pyleb128-0.2.3.tar.gz.

File metadata

  • Download URL: pyleb128-0.2.3.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

Hashes for pyleb128-0.2.3.tar.gz
Algorithm Hash digest
SHA256 29207ee2c71f927ea9a0dc100bd70343d83e4579f28204f7d851cd17c00aaa13
MD5 139d26b633209c001d3c8fc0bf368a56
BLAKE2b-256 f0ad0c56ca4008e4b3684be6052e256457f8611f34c962ec265e840aa1d87451

See more details on using hashes here.

File details

Details for the file pyleb128-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pyleb128-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.4 Windows/10

File hashes

Hashes for pyleb128-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f4a3996fbbeae8241219f7e6853769bb2898a39be804b1dc9b0ac584841743b8
MD5 2c89f16f52d88c4a89971f977b391184
BLAKE2b-256 d2317e219ad2e9f550bf5220591c023fa47796360d26430cd246bfc6af792436

See more details on using hashes here.

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