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

Uploaded Source

Built Distribution

pyvint-1.0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyvint-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e5a2640e2ee37bbac6b4317c6f28b39e95f0fcd94e2435b2a42a473aaf8ffbfc
MD5 d8a77ccfd926f8ccb8f7cc3546a38616
BLAKE2b-256 6270a7838cfca0efefbf412e5667fd0b18264916ae80ac6cca3a00b12ade842b

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: pyvint-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a858beac26fa2d7eb8d94950ae77d37125c890fa4b5a3a9fc13596570430244
MD5 bde50c1e64846a5430c3885591828e18
BLAKE2b-256 a1ceaa227fc8578353151eaafbe93b0162c32392d093c8dc28a552f3964b650a

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