https://github.com/osoken/pyvlq
A Python library for pure Python encoding and decoding of integers using Variable-length quantity.
https://github.com/osoken/pyvlq
Last synced: 5 months ago
JSON representation
A Python library for pure Python encoding and decoding of integers using Variable-length quantity.
- Host: GitHub
- URL: https://github.com/osoken/pyvlq
- Owner: osoken
- License: mit
- Created: 2024-06-25T12:37:02.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-26T15:49:08.000Z (almost 2 years ago)
- Last Synced: 2025-09-20T11:18:20.574Z (9 months ago)
- Language: Python
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyvlq
pyvlq is a Python library for encoding and decoding [Variable-Length Quantity](https://en.wikipedia.org/wiki/Variable-length_quantity).
The library is available on PyPI and can be installed using pip:
```bash
pip install pyvlq
```
## Usage
```python
from io import BytesIO
import pyvlq
# Encode
encoded = pyvlq.encode(128)
print(encoded) # b'\x81\x00'
# Decode
decoded = pyvlq.decode(encoded)
print(decoded) # 128
# Decode from readable bytes
buffer = BytesIO(b'\x81\x00\xff\xff')
decoded = pyvlq.decode_stream(buffer)
print(decoded) # 128 (0xff\xff is ignored)
print(buffer.read(2)) # b'\xff\xff' (0xff\xff is left in the buffer)
```