@thi.ng/leb128 3.0.52 → 3.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/binary.js +4 -7
- package/index.js +25 -48
- package/package.json +9 -6
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/binary.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export const BINARY = "AGFzbQEAAAABCgJgAX4Bf2AAAX4DBQQAAQABBQMBABEGCQF/AEGAgMAACwdYBgZtZW1vcnkCAA9sZWIxMjhFbmNvZGVVNjQAAANidWYDAA9sZWIxMjhEZWNvZGVVNjQAAQ9sZWIxMjhFbmNvZGVJNjQAAg9sZWIxMjhEZWNvZGVJNjQAAwrBAwRbAQJ/AkAgAEKAAVoEQANAIAFBgIBAayAAp0H/AHEgAEL/AFZBB3RyOgAAIAFBAWohASAAQoABVCAAQgeIIQBFDQALDAELQYCAwAAgADwAAEEBIQELIAFB/wFxC1ECA38CfgNAAkAgAEEBaiECIABBgIBAaywAACIBQf8Aca0gA4YgBIQhBCABQQBODQAgA0IHfCEDIABBCUkgAiEADQELC0GAgMAAIAI6AAAgBAuRAQEDfwJAIABCQH1CgAFaBEBBASECA0AgAkEBcUUNAiABQYCAQGtBAEGAfyAApyICQcAAcSIDRSAAQoABVHEgA0EGdiAAQgeHIgBCf1FxciIDGyACQf8AcXI6AAAgA0UhAiABQQFqIQEMAAsAC0GAgMAAIABCOYinQcAAcSAAp0E/cXI6AABBASEBCyABQf8BcQt+AgN/A35BfyEAA0ACQCAAQQFqIQEgA0IHfCEFIABBgYDAAGotAAAiAEH/AHGtIAOGIASEIQQgAMAiAkEATg0AIAEhACAFIQMgAUEJSQ0BCwtBgIDAACABQQFqOgAAIARCfyAFhkIAIAJBwABxQQZ2G0IAIAFB/wFxQQlJG4QL";
|
|
1
|
+
const BINARY = "AGFzbQEAAAABCgJgAX4Bf2AAAX4DBQQAAQABBQMBABEGCQF/AEGAgMAACwdYBgZtZW1vcnkCAA9sZWIxMjhFbmNvZGVVNjQAAANidWYDAA9sZWIxMjhEZWNvZGVVNjQAAQ9sZWIxMjhFbmNvZGVJNjQAAg9sZWIxMjhEZWNvZGVJNjQAAwrBAwRbAQJ/AkAgAEKAAVoEQANAIAFBgIBAayAAp0H/AHEgAEL/AFZBB3RyOgAAIAFBAWohASAAQoABVCAAQgeIIQBFDQALDAELQYCAwAAgADwAAEEBIQELIAFB/wFxC1ECA38CfgNAAkAgAEEBaiECIABBgIBAaywAACIBQf8Aca0gA4YgBIQhBCABQQBODQAgA0IHfCEDIABBCUkgAiEADQELC0GAgMAAIAI6AAAgBAuRAQEDfwJAIABCQH1CgAFaBEBBASECA0AgAkEBcUUNAiABQYCAQGtBAEGAfyAApyICQcAAcSIDRSAAQoABVHEgA0EGdiAAQgeHIgBCf1FxciIDGyACQf8AcXI6AAAgA0UhAiABQQFqIQEMAAsAC0GAgMAAIABCOYinQcAAcSAAp0E/cXI6AABBASEBCyABQf8BcQt+AgN/A35BfyEAA0ACQCAAQQFqIQEgA0IHfCEFIABBgYDAAGotAAAiAEH/AHGtIAOGIASEIQQgAMAiAkEATg0AIAEhACAFIQMgAUEJSQ0BCwtBgIDAACABQQFqOgAAIARCfyAFhkIAIAJBwABxQQZ2G0IAIAFB/wFxQQlJG4QL";
|
|
2
|
+
export {
|
|
3
|
+
BINARY
|
|
4
|
+
};
|
package/index.js
CHANGED
|
@@ -5,57 +5,34 @@ import { BINARY } from "./binary.js";
|
|
|
5
5
|
let wasm;
|
|
6
6
|
let U8;
|
|
7
7
|
if (hasWASM()) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const inst = new WebAssembly.Instance(
|
|
9
|
+
new WebAssembly.Module(base64Decode(BINARY))
|
|
10
|
+
);
|
|
11
|
+
wasm = inst.exports;
|
|
12
|
+
U8 = new Uint8Array(wasm.memory.buffer, wasm.buf, 16);
|
|
12
13
|
}
|
|
13
14
|
const ensureWASM = () => !wasm && unsupported("WASM module unavailable");
|
|
14
15
|
const encode = (op, signed) => (x) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
: BigInt.asUintN(64, BigInt(x));
|
|
19
|
-
return U8.slice(0, wasm[op](value));
|
|
16
|
+
ensureWASM();
|
|
17
|
+
const value = signed ? BigInt.asIntN(64, BigInt(x)) : BigInt.asUintN(64, BigInt(x));
|
|
18
|
+
return U8.slice(0, wasm[op](value));
|
|
20
19
|
};
|
|
21
20
|
const decode = (op, signed) => (src, idx = 0) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
ensureWASM();
|
|
22
|
+
U8.set(src.subarray(idx, Math.min(idx + 10, src.length)), 0);
|
|
23
|
+
const value = wasm[op](0, 0);
|
|
24
|
+
return [
|
|
25
|
+
signed ? BigInt.asIntN(64, value) : BigInt.asUintN(64, value),
|
|
26
|
+
U8[0]
|
|
27
|
+
];
|
|
28
|
+
};
|
|
29
|
+
const encodeSLEB128 = encode("leb128EncodeI64", true);
|
|
30
|
+
const decodeSLEB128 = decode("leb128DecodeI64", true);
|
|
31
|
+
const encodeULEB128 = encode("leb128EncodeU64", false);
|
|
32
|
+
const decodeULEB128 = decode("leb128DecodeU64", false);
|
|
33
|
+
export {
|
|
34
|
+
decodeSLEB128,
|
|
35
|
+
decodeULEB128,
|
|
36
|
+
encodeSLEB128,
|
|
37
|
+
encodeULEB128
|
|
29
38
|
};
|
|
30
|
-
/**
|
|
31
|
-
* Encodes signed integer `x` into LEB128 varint format and returns
|
|
32
|
-
* encoded bytes.
|
|
33
|
-
*
|
|
34
|
-
* @param x -
|
|
35
|
-
*/
|
|
36
|
-
export const encodeSLEB128 = encode("leb128EncodeI64", true);
|
|
37
|
-
/**
|
|
38
|
-
* Takes Uint8Array with LEB128 encoded signed varint and an optional
|
|
39
|
-
* start index to decode from. Returns 2-tuple of decoded value and
|
|
40
|
-
* number of bytes consumed. Consumes up to 10 bytes from `src`.
|
|
41
|
-
*
|
|
42
|
-
* @param src -
|
|
43
|
-
* @param idx -
|
|
44
|
-
*/
|
|
45
|
-
export const decodeSLEB128 = decode("leb128DecodeI64", true);
|
|
46
|
-
/**
|
|
47
|
-
* Encodes unsigned integer `x` into LEB128 varint format and returns
|
|
48
|
-
* encoded bytes. Values < 0 will be encoded as zero.
|
|
49
|
-
*
|
|
50
|
-
* @param x -
|
|
51
|
-
*/
|
|
52
|
-
export const encodeULEB128 = encode("leb128EncodeU64", false);
|
|
53
|
-
/**
|
|
54
|
-
* Takes Uint8Array with LEB128 encoded unsigned varint and an optional
|
|
55
|
-
* start index to decode from. Returns 2-tuple of decoded value and
|
|
56
|
-
* number of bytes consumed. Consumes up to 10 bytes from `src`.
|
|
57
|
-
*
|
|
58
|
-
* @param src -
|
|
59
|
-
* @param idx -
|
|
60
|
-
*/
|
|
61
|
-
export const decodeULEB128 = decode("leb128DecodeU64", false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/leb128",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.53",
|
|
4
4
|
"description": "WASM based LEB128 encoder / decoder (signed & unsigned)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,8 +24,10 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
28
|
"build:binary": "tools/build-binary.sh",
|
|
29
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
30
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
29
31
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
30
32
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
31
33
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -34,12 +36,13 @@
|
|
|
34
36
|
"test": "bun test"
|
|
35
37
|
},
|
|
36
38
|
"dependencies": {
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/errors": "^2.4.
|
|
39
|
-
"@thi.ng/transducers-binary": "^2.1.
|
|
39
|
+
"@thi.ng/checks": "^3.4.12",
|
|
40
|
+
"@thi.ng/errors": "^2.4.6",
|
|
41
|
+
"@thi.ng/transducers-binary": "^2.1.82"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@microsoft/api-extractor": "^7.38.3",
|
|
45
|
+
"esbuild": "^0.19.8",
|
|
43
46
|
"rimraf": "^5.0.5",
|
|
44
47
|
"tools": "^0.0.1",
|
|
45
48
|
"typedoc": "^0.25.4",
|
|
@@ -78,5 +81,5 @@
|
|
|
78
81
|
"thi.ng": {
|
|
79
82
|
"year": 2019
|
|
80
83
|
},
|
|
81
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
82
85
|
}
|