Skip to main content

A Python library for pure Python encoding and decoding of integers using Variable-Size Integer (VINT).

Project description

pyvint

A pure Python library for encoding and decoding Variable-Sized Integer (VINT) values. VINT is used in EBML (Extensible Binary Meta Language) to encode integers with a variable number of bytes. Detailed information about VINT can be found in the Extensible Binary Meta Language RFC 8794

Installation

The library is available on PyPI and can be installed using pip:

pip install pyvint

Usage

Encoding (Integer to VINT)

import pyvint

vint = pyvint.encode(2)  # just passing an integer returns the minimum length VINT
print(vint)  # b'\x82'
vint2 = pyvint.encode(2, 2)  # passing an integer and the octet length returns a VINT with the specified octet length
print(vint2)  # b'\x40\x02'

Decoding (VINT to Integer)

import pyvint

value = pyvint.decode(b'\x82')
print(value)  # 2
value2 = pyvint.decode(b'\x40\x02')
print(value2)  # 2

pyvint also provides decoding of VINTs from a stream of bytes. This is useful when reading VINTs from a file or a network stream. The decode_stream function returns the integer value of the VINT and advances the buffer to the next byte after the VINT.

from io import BytesIO
import pyvint

data = b'\x82\x40\x02'
buffer = BytesIO(data)
value = pyvint.decode_stream(data)
print(value)  # 2
print(buffer.read())  # b'\x40\x02'

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

pyvint-1.1.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

pyvint-1.1.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file pyvint-1.1.2.tar.gz.

File metadata

  • Download URL: pyvint-1.1.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for pyvint-1.1.2.tar.gz
Algorithm Hash digest
SHA256 8b15d18719ec34d2aa51e1a1b0ee269704a7cf97b78b299964aaf56d60e79c62
MD5 6564be11d1bf9b20ba4391c712d6e729
BLAKE2b-256 514193a121d2616e607b77a2ae05ea3ec8262b88cf3effe0bec3eba32e995b34

See more details on using hashes here.

Provenance

File details

Details for the file pyvint-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyvint-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for pyvint-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c04954bf6212356f9877444fe7b022a1c9ab50ce18e81dbdbcceb1a908fcacc3
MD5 041e8bad30540c0f7fe34e6d84aa0e8f
BLAKE2b-256 246b02948158eb4db55f663a9029f2c738469e6451079d2827d89f0a30154d2a

See more details on using hashes here.

Provenance

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