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.

Files for uvarint, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size uvarint-1.2.0-py3-none-any.whl (4.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size uvarint-1.2.0.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page