varint

Varint encoder/decoder

Implementation of a variable-length integer encoding scheme.

Based on implementation by Peter Ruibal:
https://github.com/fmoo/python-varint

It’s copied here so we can use it stably without adding a dependency.

License: Since this is copied from someone else’s code, its license is that of the original code, the MIT license. See LICENSE below for details.

Varints are a common encoding for variable-length integer data, used in libraries such as sqlite, protobuf, v8, and more.

Here’s a quick and dirty module to help avoid reimplementing the same thing over and over again.

encode(number)[source]

Pack number into varint bytes

decode_stream(stream)[source]

Read a varint from stream

decode_bytes(buf)[source]

Read a varint from from buf bytes