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

Uploaded Source

Built Distribution

pyleb128-0.1.4-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyleb128-0.1.4.tar.gz
  • Upload date:
  • Size: 15.2 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.1.4.tar.gz
Algorithm Hash digest
SHA256 aa8418c2ea9f94b2dd05fca653bdf6f7173877b5f9c4584d6b9716f3dad597fb
MD5 ca9ab799417d322e07cf796674c06126
BLAKE2b-256 b1ce620359bc71664202dd169e89ae71c528b4e74914d86e0d669937931973b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyleb128-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 15.8 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.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ebf87a6938b127939ba746334612954c323929038d478474d50ce5403032f40e
MD5 ed50d0c3b8c204014fb39ece837b0003
BLAKE2b-256 b6e5c1705320820250d66a6e62b4f74ccbb534e0c1f3677596d5b5faf66f266d

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