pyvarint/README.md

36 lines
794 B
Markdown
Raw Permalink Normal View History

2020-06-26 15:19:34 +00:00
# pyvarint
2020-06-29 23:40:01 +00:00
[![Build Status](https://drone.autonomic.zone/api/badges/hyperpy/pyvarint/status.svg)](https://drone.autonomic.zone/hyperpy/pyvarint)
2020-06-29 23:47:23 +00:00
## Varints, a method of serializing integers using one or more bytes
2020-06-29 23:40:01 +00:00
2020-07-09 08:12:54 +00:00
> 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.
2020-07-07 13:59:42 +00:00
## Install
2020-06-29 23:40:01 +00:00
```sh
$ pip install pyvarint
```
2020-07-07 13:59:42 +00:00
## Example
```python
from pyvarint import decode, encode
2020-08-05 06:28:38 +00:00
encoded = encode(666)
decoded = decode(encoded)
2020-07-07 13:59:42 +00:00
2020-08-05 06:28:38 +00:00
print("number: 666", f"encoded: {encoded}", f"decoded: {decoded}", sep="\n")
```
Output:
```sh
number: 666
encoded: b'\x9a\x05'
decoded: 666
2020-07-07 13:59:42 +00:00
```