https://github.com/samualtnorman/bleb
Better LEB128
https://github.com/samualtnorman/bleb
bigint bleb decode decoder decoding deserialization encode encoder encoding integer leb128 serialization
Last synced: 21 days ago
JSON representation
Better LEB128
- Host: GitHub
- URL: https://github.com/samualtnorman/bleb
- Owner: samualtnorman
- License: mit
- Created: 2023-07-03T08:43:30.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-28T14:22:36.000Z (about 1 month ago)
- Last Synced: 2025-04-28T14:27:09.615Z (about 1 month ago)
- Topics: bigint, bleb, decode, decoder, decoding, deserialization, encode, encoder, encoding, integer, leb128, serialization
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/bleb
- Size: 158 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Better LEB128
bleb| Range | bleb | LEB128 |
|-------------------|---------|---------|
| 0 - 127 | 1 byte | 1 byte |
| 128 - 16383 | 2 bytes | 2 bytes |
| 16384 - 16511 | 2 bytes | 3 bytes |
| 16512 - 2097151 | 3 bytes | 3 bytes |
| 2097152 - 2113663 | 3 bytes | 4 bytes |
| ... |## Encoding
### Basic Usage
```js
import * as Bleb from "bleb"console.log(Bleb.fromBigInt(1000n)) // [ 232, 6 ]
```## Decoding
### Basic Usage
```js
import * as Bleb from "bleb"console.log(Bleb.toBigInt([ 232, 6 ])) // 1000n
```### Less-Basic Usage
```js
import * as Bleb from "bleb"// some data with bleb at byte offset 2
const u8View = new Uint8Array([ 177, 218, 232, 6, 197, 165, 75, 177 ])
const index = { $: 2 }console.log(Bleb.toBigInt(u8View, index)) // 1000n
console.log(index) // { $: 4 }
```