https://github.com/hyperpy/pyvarint
Varints, a method of serializing integers using one or more bytes
https://github.com/hyperpy/pyvarint
hypercore hypercore-protocol
Last synced: 14 days ago
JSON representation
Varints, a method of serializing integers using one or more bytes
- Host: GitHub
- URL: https://github.com/hyperpy/pyvarint
- Owner: hyperpy
- License: gpl-3.0
- Created: 2020-07-07T10:51:43.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-05T06:28:50.000Z (over 5 years ago)
- Last Synced: 2025-10-28T02:32:11.053Z (6 months ago)
- Topics: hypercore, hypercore-protocol
- Language: Python
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# pyvarint
[](https://drone.autonomic.zone/hyperpy/pyvarint)
## Varints, a method of serializing integers using one or more bytes
> Generally in Python, integers are stored as long meaning that they will use
> at least 32 bits. When storing many numbers which do not require 32 bits,
> this would seem to be significantly wasteful; variable length representation
> should be able to assist in such cases.
## Install
```sh
$ pip install pyvarint
```
## Example
```python
from pyvarint import decode, encode
encoded = encode(666)
decoded = decode(encoded)
print("number: 666", f"encoded: {encoded}", f"decoded: {decoded}", sep="\n")
```
Output:
```sh
number: 666
encoded: b'\x9a\x05'
decoded: 666
```