Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dchest/varuint
Go package varuint implements SQLite4-like variable unsigned integer encoding.
https://github.com/dchest/varuint
Last synced: about 1 month ago
JSON representation
Go package varuint implements SQLite4-like variable unsigned integer encoding.
- Host: GitHub
- URL: https://github.com/dchest/varuint
- Owner: dchest
- Created: 2012-10-05T09:34:08.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2016-01-17T09:32:53.000Z (almost 9 years ago)
- Last Synced: 2024-04-15T01:16:20.270Z (7 months ago)
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
Go package varuint implements SQLite4-like variable unsigned integer encoding
as described in http://www.sqlite.org/src4/doc/trunk/www/varint.wiki.Unlike varint from encoding/binary package, this encoding uses fewer bytes
for smaller values, and the number of encoded bytes can be determined by
looking at the first byte. Varuint also preserves numeric and lexicographical
ordering.INSTALLATION
$ go get github.com/dchest/varuintEXAMPLE
import "github.com/dchest/varuint"
...
buf := make([]byte, varuint.MaxUint64Len)
n := varuint.PutUint64(buf, 12345)
buf = buf[:n]
fmt.Printf("% x\n", buf)
// Output: f9 27 49v, n := varuint.Uint64(buf)
if n < 1 {
panic("buffer is too small to contain the expected number")
}
fmt.Println(v)
// Output: 12345LICENSE / PUBLIC DOMAIN DEDICATION
Written in 2012 by Dmitry Chestnykh.
To the extent possible under law, the author have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
http://creativecommons.org/publicdomain/zero/1.0/