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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyvint-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d89d9aa413dc37f54c97e1ac5dc6bf0adc9ccb3d53a35e990dc6db1d498b721d
MD5 dc82152c50bf42fed58159566eab6ae2
BLAKE2b-256 4f0253de7f4cce1c8fa327d4aeccef4a2d9414487eef4e357c047992daec5d82

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: pyvint-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 00dbd05e60b3928ecdc39f768a250393a514bb94f01837f59289f9688b47c3b2
MD5 6a0258e7bbf7a126c3fbb04c85022b03
BLAKE2b-256 835ef38c79096c6146a82f789b5cffe30c8e59c6ceb2d663a5b672d4a8fde6e0

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