Metadata-Version: 2.1
Name: pyvint
Version: 1.1.2
Summary: A Python library for pure Python encoding and decoding of integers using Variable-Size Integer (VINT).
Keywords: vint,variable-size integer,integer
Author: osoken
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: black ; extra == "dev"
Requires-Dist: flake8 ; extra == "dev"
Requires-Dist: pyproject-flake8 ; extra == "dev"
Requires-Dist: pytest ; extra == "dev"
Requires-Dist: mypy ; extra == "dev"
Requires-Dist: tox ; extra == "dev"
Requires-Dist: isort ; extra == "dev"
Requires-Dist: pytest-cov ; extra == "dev"
Requires-Dist: pytest-random-order ; extra == "dev"
Requires-Dist: mkdocs ; extra == "docs"
Requires-Dist: mkdocs-material ; extra == "docs"
Requires-Dist: mkdocstrings[python] ; extra == "docs"
Requires-Dist: mkdocs-include-markdown-plugin ; extra == "docs"
Project-URL: Documentation, https://osoken.github.io/pyvint/
Project-URL: Source, https://github.com/osoken/pyvint
Provides-Extra: dev
Provides-Extra: docs

# 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](https://datatracker.ietf.org/doc/rfc8794/)

## Installation

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

```bash
pip install pyvint
```

## Usage

### Encoding (Integer to VINT)

```python
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)

```python
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.

```python
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'
```

