Originally, this code was taken from https://github.com/status-im/nim-libp2p/blob/master/libp2p/varint.nim The API was refactored to make it easier to use in the networking back-ends where the data is being consumed byte by byte.