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

Uploaded Source

Built Distribution

pyleb128-0.2.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyleb128-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 9b612c8144a13446e2b1b577ca358693e36a6a655804bad276f1300899922cfa
MD5 5d848fd6d174b14a397bceac246a099f
BLAKE2b-256 6ece413eab3966580a55c7923cd0f237ece08c1ae057c6b68278987dc8336dcf

See more details on using hashes here.

File details

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

File metadata

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

Hashes for pyleb128-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6b11fedc2012e4d6ee5b3147ad87ce0ec830f802a1c99f911f06c9d8cdaf677
MD5 b3c71192216534296aedec0003b06a5b
BLAKE2b-256 e05846ecd28b2be0ee2a90dc50ca04344e16d980cba96f20d9f2044ea05dc24f

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