https://github.com/zypeh/go-leb128
Little Endian Base 128, a variable-length code compression for arbitrarily large integer in a small number of bytes.
https://github.com/zypeh/go-leb128
compression encoder-decoder leb128
Last synced: 12 months ago
JSON representation
Little Endian Base 128, a variable-length code compression for arbitrarily large integer in a small number of bytes.
- Host: GitHub
- URL: https://github.com/zypeh/go-leb128
- Owner: zypeh
- License: mit
- Created: 2020-04-24T05:44:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-02T03:53:51.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T15:51:13.695Z (almost 2 years ago)
- Topics: compression, encoder-decoder, leb128
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-leb128
> Little Endian Base 128, a variable-length code compression for arbitrarily large integer in a small number of bytes.
# Usage
The bytes payload is typed in this library. So instead of using `[]byte` we are using
* `SLeb128` for Signed LEB128 encoding
* `ULeb128` for Unsigned LEB128 encoding
So for unsigned LEB128 encoding it should be written in
```go
sleb624485 := ULeb128{[]byte{0xE5, 0x8E, 0x26}}
```
And it cannot be consumed by signed LEB128 decoder (typed)
```go
DecodeSLeb128(sleb624485) // this will not compile
DecodeULeb128(sleb624485) // compiles !
```
### Encoding
**EncodeFromUint64(uint64) ULeb128**
Encode `uint64` typed integer into `ULeb128`
**EncodeFromInt64(int64) SLeb128**
Encode `int64` typed integer into `SLeb128`
### Decoding
**DecodeULeb128(ULeb128) (uint64, error)**
Decode `ULeb128` to uint64 with error flag
**DecodeSLeb128(SLeb128) (int64, error)**
Decode `SLeb128` to int64 with error flag
> If the error is not equal to nil (means error occurred). The result is always 0
### Utilities
**AppendSLeb128(x, y SLeb128) SLeb128**
Append two `Sleb128` into one `SLeb128`
**AppendULeb128(x, y ULeb128) ULeb128**
Append two `Uleb128` into one `ULeb128`