@12core/varint-wasm 中文文档教程
varint-wasm
Installation
Node
$ npm install @12core/varint-wasm
WAPM
$ wapm install jwerle/varint-wasm
Usage
const varint = require('varint-wasm')
// wait for module to be ready if loading in a browser environment
varint.ready(() => {
const encoded = varint.encode(64 * 1024)
console.log(encoded) // <Buffer 80 80 04>
const decoded = varint.decode(encoded)
console.log(decoded) // 65536
})
API
buffer = encode(number[, buffer[, offset]])
将一个 number
可选地编码到 buffer
中 指定的<代码>偏移量。
number = decode(buffer[, offset])
可选地将输入缓冲区解码为整数 指定的<代码>偏移量。
promise = ready(callback)
在 WebAssembly 导出时返回解决或拒绝的承诺 正在加载。 在某些情况下,这可能会同步发生 模块已加载。
await b64.ready()
Limits
Max Integer
因为当时 WASM 只支持 32 位整数 写作,你只能编码 2**31 -1
的数字。
Initial Memory
默认情况下,该模块为 WebAssembly 模块分配 2 页内存。 即 2 * 64 * 1024
字节。
Maximum Memory
该模块最多允许 256 页内存。 即 256 * 64 * 1024
字节。
See Also
- https://github.com/chrisdickinson/varint
License
麻省理工学院
varint-wasm
A varint implementation for WebAssembly (WASM) written in ZZ that implements an Abstract Encoding interface.
Installation
Node
$ npm install @12core/varint-wasm
WAPM
$ wapm install jwerle/varint-wasm
Usage
const varint = require('varint-wasm')
// wait for module to be ready if loading in a browser environment
varint.ready(() => {
const encoded = varint.encode(64 * 1024)
console.log(encoded) // <Buffer 80 80 04>
const decoded = varint.decode(encoded)
console.log(decoded) // 65536
})
API
buffer = encode(number[, buffer[, offset]])
Encode a number
optionally into buffer
at an optionally specified offset
.
number = decode(buffer[, offset])
Decode an input buffer into an integer optionally an optionally specified offset
.
promise = ready(callback)
Returns a promise that resolves or rejects when the WebAssembly exports are loading. In some cases, this may happen synchronously when this module is loaded.
await b64.ready()
Limits
Max Integer
Because 32-bit integers are only supported in WASM at the time of writing, you can only encode numbers up 2**31 -1
.
Initial Memory
By default, this module allocates 2 pages of memory for the WebAssembly module. That is 2 * 64 * 1024
bytes.
Maximum Memory
This module allows at most 256 pages of memory. That is 256 * 64 * 1024
bytes.
See Also
- https://github.com/chrisdickinson/varint
License
MIT