https://github.com/adrian-lin-1-0-0/go-variable-length-integer-encoding
Variable-Length Integer Encoding Implement (rfc9000)
https://github.com/adrian-lin-1-0-0/go-variable-length-integer-encoding
encoding go golang rfc9000
Last synced: 9 months ago
JSON representation
Variable-Length Integer Encoding Implement (rfc9000)
- Host: GitHub
- URL: https://github.com/adrian-lin-1-0-0/go-variable-length-integer-encoding
- Owner: adrian-lin-1-0-0
- License: mit
- Created: 2022-07-23T14:49:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-23T15:12:19.000Z (over 3 years ago)
- Last Synced: 2025-01-25T18:43:40.350Z (11 months ago)
- Topics: encoding, go, golang, rfc9000
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Variable-Length Integer Encoding
Variable-Length Integer Encoding Implement
[rfc9000](https://datatracker.ietf.org/doc/html/rfc9000#section-16)
```
+======+========+=============+=======================+
| 2MSB | Length | Usable Bits | Range |
+======+========+=============+=======================+
| 00 | 1 | 6 | 0-63 |
+------+--------+-------------+-----------------------+
| 01 | 2 | 14 | 0-16383 |
+------+--------+-------------+-----------------------+
| 10 | 4 | 30 | 0-1073741823 |
+------+--------+-------------+-----------------------+
| 11 | 8 | 62 | 0-4611686018427387903 |
+------+--------+-------------+-----------------------+
```
## Install
```shell
go get "github.com/adrian-lin-1-0-0/go-variable-length-integer-encoding"
```
## Usage
```go
package main
import (
"fmt"
encode "github.com/adrian-lin-1-0-0/go-variable-length-integer-encoding"
)
func main() {
b, _ := encode.ToVarLenInt(0x3f)
fmt.Println(encode.ToUint64(b))
}
```