Skip to main content

Unsigned variable-length integers

Project description

uvarint

Unsigned variable-length integers. A type of variable-length quantity.

Usage

import uvarint

buffer = uvarint.encode(16384)                  # b'\x80\x80\x01'
integer, bytes_read = uvarint.decode(buffer)    # 16384

big = uvarint.encode(2 ** 63)
uvarint.decode(big)              # Raises OverflowError; decoder limited to 9 bytes by default
uvarint.decode(big, limit=16)    # Success; use math.inf for unlimited decoding

multiple  = uvarint.encode(100)
multiple += uvarint.encode(200)
multiple += uvarint.encode(300)
uvarint.expect(3, multiple).integers    # [100, 200, 300]
uvarint.cut(0, multiple)                # Slice(integers=[], rest=b'd\xc8\x01\xac\x02')
uvarint.cut(1, multiple)                # Slice(integers=[100], rest=b'\xc8\x01\xac\x02')
uvarint.cut(2, multiple)                # Slice(integers=[100, 200], rest=b'\xac\x02')
uvarint.cut(3, multiple)                # Slice(integers=[100, 200, 300], rest=b'')

References

License

This module is licensed under the MIT license.

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

uvarint-1.2.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

uvarint-1.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file uvarint-1.2.0.tar.gz.

File metadata

  • Download URL: uvarint-1.2.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for uvarint-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7cc17481c9af8ebe3978f5357412b57ff93ce8b14712236338f782cc8ae9a989
MD5 423c6ff04f490d4ae42fcf695cc0daf1
BLAKE2b-256 faec8ef0e69448c879b4319337aa2deb49bf493f3b42d930fcc8bf71c4cf30ea

See more details on using hashes here.

File details

Details for the file uvarint-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: uvarint-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for uvarint-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dcc98ad92b642c57494bed9370c4f93479d2d36223b2c3702823f0aa8b1a9a3
MD5 13263269e59e5b30c47c4081b5dfb01c
BLAKE2b-256 306fc51f9f0d9c5345121c73de882ae22a7206ecb8e5b072c217a90f4abdea06

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