@solana/codecs-core 2.0.0-experimental.0983bae → 2.0.0-experimental.0af01ac
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/README.md +390 -5
- package/dist/index.browser.cjs +147 -85
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +140 -85
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +140 -85
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +147 -85
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +140 -85
- package/dist/index.node.js.map +1 -1
- package/dist/types/assertions.d.ts +0 -7
- package/dist/types/assertions.d.ts.map +1 -0
- package/dist/types/bytes.d.ts.map +1 -0
- package/dist/types/codec.d.ts +98 -32
- package/dist/types/codec.d.ts.map +1 -0
- package/dist/types/combine-codec.d.ts +4 -2
- package/dist/types/combine-codec.d.ts.map +1 -0
- package/dist/types/fix-codec.d.ts +4 -7
- package/dist/types/fix-codec.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/map-codec.d.ts +13 -5
- package/dist/types/map-codec.d.ts.map +1 -0
- package/dist/types/reverse-codec.d.ts +4 -4
- package/dist/types/reverse-codec.d.ts.map +1 -0
- package/package.json +12 -30
- package/dist/index.development.js +0 -191
- package/dist/index.development.js.map +0 -1
- package/dist/index.production.min.js +0 -26
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import { Codec, Decoder, Encoder } from './codec';
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from './codec.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a fixed-size encoder from a given encoder.
|
|
4
4
|
*
|
|
5
5
|
* @param encoder - The encoder to wrap into a fixed-size encoder.
|
|
6
6
|
* @param fixedBytes - The fixed number of bytes to write.
|
|
7
|
-
* @param description - A custom description for the encoder.
|
|
8
7
|
*/
|
|
9
|
-
export declare function fixEncoder<
|
|
8
|
+
export declare function fixEncoder<TFrom, TSize extends number>(encoder: Encoder<TFrom>, fixedBytes: TSize): FixedSizeEncoder<TFrom, TSize>;
|
|
10
9
|
/**
|
|
11
10
|
* Creates a fixed-size decoder from a given decoder.
|
|
12
11
|
*
|
|
13
12
|
* @param decoder - The decoder to wrap into a fixed-size decoder.
|
|
14
13
|
* @param fixedBytes - The fixed number of bytes to read.
|
|
15
|
-
* @param description - A custom description for the decoder.
|
|
16
14
|
*/
|
|
17
|
-
export declare function fixDecoder<
|
|
15
|
+
export declare function fixDecoder<TTo, TSize extends number>(decoder: Decoder<TTo>, fixedBytes: TSize): FixedSizeDecoder<TTo, TSize>;
|
|
18
16
|
/**
|
|
19
17
|
* Creates a fixed-size codec from a given codec.
|
|
20
18
|
*
|
|
21
19
|
* @param codec - The codec to wrap into a fixed-size codec.
|
|
22
20
|
* @param fixedBytes - The fixed number of bytes to read/write.
|
|
23
|
-
* @param description - A custom description for the codec.
|
|
24
21
|
*/
|
|
25
|
-
export declare function fixCodec<
|
|
22
|
+
export declare function fixCodec<TFrom, TTo extends TFrom, TSize extends number>(codec: Codec<TFrom, TTo>, fixedBytes: TSize): FixedSizeCodec<TFrom, TTo, TSize>;
|
|
26
23
|
//# sourceMappingURL=fix-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix-codec.d.ts","sourceRoot":"","sources":["../../src/fix-codec.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,EAGL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGnB,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,EAClD,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EACvB,UAAU,EAAE,KAAK,GAClB,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAchC;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,KAAK,SAAS,MAAM,EAChD,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,UAAU,EAAE,KAAK,GAClB,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,CAkB9B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EAAE,KAAK,SAAS,MAAM,EACnE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EACxB,UAAU,EAAE,KAAK,GAClB,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAEnC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './assertions';
|
|
2
|
-
export * from './bytes';
|
|
3
|
-
export * from './codec';
|
|
4
|
-
export * from './combine-codec';
|
|
5
|
-
export * from './fix-codec';
|
|
6
|
-
export * from './map-codec';
|
|
7
|
-
export * from './reverse-codec';
|
|
1
|
+
export * from './assertions.js';
|
|
2
|
+
export * from './bytes.js';
|
|
3
|
+
export * from './codec.js';
|
|
4
|
+
export * from './combine-codec.js';
|
|
5
|
+
export * from './fix-codec.js';
|
|
6
|
+
export * from './map-codec.js';
|
|
7
|
+
export * from './reverse-codec.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import { Codec, Decoder, Encoder } from './codec';
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from './codec.js';
|
|
2
2
|
/**
|
|
3
3
|
* Converts an encoder A to a encoder B by mapping their values.
|
|
4
4
|
*/
|
|
5
|
-
export declare function mapEncoder<
|
|
5
|
+
export declare function mapEncoder<TOldFrom, TNewFrom, TSize extends number>(encoder: FixedSizeEncoder<TOldFrom, TSize>, unmap: (value: TNewFrom) => TOldFrom): FixedSizeEncoder<TNewFrom, TSize>;
|
|
6
|
+
export declare function mapEncoder<TOldFrom, TNewFrom>(encoder: VariableSizeEncoder<TOldFrom>, unmap: (value: TNewFrom) => TOldFrom): VariableSizeEncoder<TNewFrom>;
|
|
7
|
+
export declare function mapEncoder<TOldFrom, TNewFrom>(encoder: Encoder<TOldFrom>, unmap: (value: TNewFrom) => TOldFrom): Encoder<TNewFrom>;
|
|
6
8
|
/**
|
|
7
9
|
* Converts an decoder A to a decoder B by mapping their values.
|
|
8
10
|
*/
|
|
9
|
-
export declare function mapDecoder<
|
|
11
|
+
export declare function mapDecoder<TOldTo, TNewTo, TSize extends number>(decoder: FixedSizeDecoder<TOldTo, TSize>, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): FixedSizeDecoder<TNewTo, TSize>;
|
|
12
|
+
export declare function mapDecoder<TOldTo, TNewTo>(decoder: VariableSizeDecoder<TOldTo>, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): VariableSizeDecoder<TNewTo>;
|
|
13
|
+
export declare function mapDecoder<TOldTo, TNewTo>(decoder: Decoder<TOldTo>, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): Decoder<TNewTo>;
|
|
10
14
|
/**
|
|
11
15
|
* Converts a codec A to a codec B by mapping their values.
|
|
12
16
|
*/
|
|
13
|
-
export declare function mapCodec<
|
|
14
|
-
export declare function mapCodec<
|
|
17
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom, TSize extends number>(codec: FixedSizeCodec<TOldFrom, TTo, TSize>, unmap: (value: TNewFrom) => TOldFrom): FixedSizeCodec<TNewFrom, TTo, TSize>;
|
|
18
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom>(codec: VariableSizeCodec<TOldFrom, TTo>, unmap: (value: TNewFrom) => TOldFrom): VariableSizeCodec<TNewFrom, TTo>;
|
|
19
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom>(codec: Codec<TOldFrom, TTo>, unmap: (value: TNewFrom) => TOldFrom): Codec<TNewFrom, TTo>;
|
|
20
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom, TSize extends number>(codec: FixedSizeCodec<TOldFrom, TOldTo, TSize>, unmap: (value: TNewFrom) => TOldFrom, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): FixedSizeCodec<TNewFrom, TNewTo, TSize>;
|
|
21
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom>(codec: VariableSizeCodec<TOldFrom, TOldTo>, unmap: (value: TNewFrom) => TOldFrom, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): VariableSizeCodec<TNewFrom, TNewTo>;
|
|
22
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom>(codec: Codec<TOldFrom, TOldTo>, unmap: (value: TNewFrom) => TOldFrom, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): Codec<TNewFrom, TNewTo>;
|
|
15
23
|
//# sourceMappingURL=map-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-codec.d.ts","sourceRoot":"","sources":["../../src/map-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAIL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAA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EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,QAAQ,EACpC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAClE,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAC3C,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,QAAQ,EAAE,MAAM,SAAS,QAAQ,EACzF,KAAK,EAAE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,EAC1C,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,QAAQ,EACpC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAClE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACvC,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,QAAQ,EAAE,MAAM,SAAS,QAAQ,EACzF,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,EAC9B,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,QAAQ,EACpC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAClE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from './codec.js';
|
|
2
2
|
/**
|
|
3
3
|
* Reverses the bytes of a fixed-size encoder.
|
|
4
4
|
*/
|
|
5
|
-
export declare function reverseEncoder<
|
|
5
|
+
export declare function reverseEncoder<TFrom, TSize extends number>(encoder: FixedSizeEncoder<TFrom, TSize>): FixedSizeEncoder<TFrom, TSize>;
|
|
6
6
|
/**
|
|
7
7
|
* Reverses the bytes of a fixed-size decoder.
|
|
8
8
|
*/
|
|
9
|
-
export declare function reverseDecoder<
|
|
9
|
+
export declare function reverseDecoder<TTo, TSize extends number>(decoder: FixedSizeDecoder<TTo, TSize>): FixedSizeDecoder<TTo, TSize>;
|
|
10
10
|
/**
|
|
11
11
|
* Reverses the bytes of a fixed-size codec.
|
|
12
12
|
*/
|
|
13
|
-
export declare function reverseCodec<
|
|
13
|
+
export declare function reverseCodec<TFrom, TTo extends TFrom, TSize extends number>(codec: FixedSizeCodec<TFrom, TTo, TSize>): FixedSizeCodec<TFrom, TTo, TSize>;
|
|
14
14
|
//# sourceMappingURL=reverse-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reverse-codec.d.ts","sourceRoot":"","sources":["../../src/reverse-codec.ts"],"names":[],"mappings":"AAOA,OAAO,EAIH,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACnB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,EACtD,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,GACxC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAmBhC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,KAAK,SAAS,MAAM,EACpD,OAAO,EAAE,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,GACtC,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,CAsB9B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EAAE,KAAK,SAAS,MAAM,EACvE,KAAK,EAAE,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GACzC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAEnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/codecs-core",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.0af01ac",
|
|
4
4
|
"description": "Core types and helpers for encoding and decoding byte arrays on Solana",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -48,27 +48,8 @@
|
|
|
48
48
|
"engine": {
|
|
49
49
|
"node": ">=17.4"
|
|
50
50
|
},
|
|
51
|
-
"
|
|
52
|
-
"@solana/
|
|
53
|
-
"@swc/jest": "^0.2.29",
|
|
54
|
-
"@types/jest": "^29.5.6",
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
56
|
-
"@typescript-eslint/parser": "^6.3.0",
|
|
57
|
-
"agadoo": "^3.0.0",
|
|
58
|
-
"eslint": "^8.45.0",
|
|
59
|
-
"eslint-plugin-jest": "^27.4.2",
|
|
60
|
-
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
61
|
-
"jest": "^29.7.0",
|
|
62
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
63
|
-
"jest-runner-eslint": "^2.1.2",
|
|
64
|
-
"jest-runner-prettier": "^1.0.0",
|
|
65
|
-
"prettier": "^2.8",
|
|
66
|
-
"tsup": "7.2.0",
|
|
67
|
-
"typescript": "^5.2.2",
|
|
68
|
-
"version-from-git": "^1.1.1",
|
|
69
|
-
"build-scripts": "0.0.0",
|
|
70
|
-
"tsconfig": "0.0.0",
|
|
71
|
-
"test-config": "0.0.0"
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@solana/errors": "2.0.0-experimental.0af01ac"
|
|
72
53
|
},
|
|
73
54
|
"bundlewatch": {
|
|
74
55
|
"defaultCompression": "gzip",
|
|
@@ -79,18 +60,19 @@
|
|
|
79
60
|
]
|
|
80
61
|
},
|
|
81
62
|
"scripts": {
|
|
82
|
-
"compile:js": "tsup --config build-scripts/tsup.config.
|
|
83
|
-
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
84
|
-
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
85
|
-
"publish-
|
|
63
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
64
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
|
|
65
|
+
"dev": "jest -c node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
66
|
+
"publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag experimental --access public --no-git-checks",
|
|
67
|
+
"publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
|
|
86
68
|
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
87
|
-
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
88
|
-
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
69
|
+
"test:lint": "jest -c node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
70
|
+
"test:prettier": "jest -c node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
89
71
|
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
90
72
|
"test:treeshakability:native": "agadoo dist/index.native.js",
|
|
91
73
|
"test:treeshakability:node": "agadoo dist/index.node.js",
|
|
92
74
|
"test:typecheck": "tsc --noEmit",
|
|
93
|
-
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
94
|
-
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
75
|
+
"test:unit:browser": "jest -c node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
76
|
+
"test:unit:node": "jest -c node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
95
77
|
}
|
|
96
78
|
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
// src/assertions.ts
|
|
6
|
-
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
|
|
7
|
-
if (bytes.length - offset <= 0) {
|
|
8
|
-
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
|
|
12
|
-
const bytesLength = bytes.length - offset;
|
|
13
|
-
if (bytesLength < expected) {
|
|
14
|
-
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function assertFixedSizeCodec(data, message) {
|
|
18
|
-
if (data.fixedSize === null) {
|
|
19
|
-
throw new Error(message ?? "Expected a fixed-size codec, got a variable-size one.");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/bytes.ts
|
|
24
|
-
var mergeBytes = (byteArrays) => {
|
|
25
|
-
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
26
|
-
if (nonEmptyByteArrays.length === 0) {
|
|
27
|
-
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
28
|
-
}
|
|
29
|
-
if (nonEmptyByteArrays.length === 1) {
|
|
30
|
-
return nonEmptyByteArrays[0];
|
|
31
|
-
}
|
|
32
|
-
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
33
|
-
const result = new Uint8Array(totalLength);
|
|
34
|
-
let offset = 0;
|
|
35
|
-
nonEmptyByteArrays.forEach((arr) => {
|
|
36
|
-
result.set(arr, offset);
|
|
37
|
-
offset += arr.length;
|
|
38
|
-
});
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
var padBytes = (bytes, length) => {
|
|
42
|
-
if (bytes.length >= length)
|
|
43
|
-
return bytes;
|
|
44
|
-
const paddedBytes = new Uint8Array(length).fill(0);
|
|
45
|
-
paddedBytes.set(bytes);
|
|
46
|
-
return paddedBytes;
|
|
47
|
-
};
|
|
48
|
-
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
49
|
-
|
|
50
|
-
// src/combine-codec.ts
|
|
51
|
-
function combineCodec(encoder, decoder, description) {
|
|
52
|
-
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
if (encoder.maxSize !== decoder.maxSize) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (description === void 0 && encoder.description !== decoder.description) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
decode: decoder.decode,
|
|
69
|
-
description: description ?? encoder.description,
|
|
70
|
-
encode: encoder.encode,
|
|
71
|
-
fixedSize: encoder.fixedSize,
|
|
72
|
-
maxSize: encoder.maxSize
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// src/fix-codec.ts
|
|
77
|
-
function fixCodecHelper(data, fixedBytes, description) {
|
|
78
|
-
return {
|
|
79
|
-
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
80
|
-
fixedSize: fixedBytes,
|
|
81
|
-
maxSize: fixedBytes
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function fixEncoder(encoder, fixedBytes, description) {
|
|
85
|
-
return {
|
|
86
|
-
...fixCodecHelper(encoder, fixedBytes, description),
|
|
87
|
-
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function fixDecoder(decoder, fixedBytes, description) {
|
|
91
|
-
return {
|
|
92
|
-
...fixCodecHelper(decoder, fixedBytes, description),
|
|
93
|
-
decode: (bytes, offset = 0) => {
|
|
94
|
-
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
95
|
-
if (offset > 0 || bytes.length > fixedBytes) {
|
|
96
|
-
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
97
|
-
}
|
|
98
|
-
if (decoder.fixedSize !== null) {
|
|
99
|
-
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
100
|
-
}
|
|
101
|
-
const [value] = decoder.decode(bytes, 0);
|
|
102
|
-
return [value, offset + fixedBytes];
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function fixCodec(codec, fixedBytes, description) {
|
|
107
|
-
return combineCodec(fixEncoder(codec, fixedBytes, description), fixDecoder(codec, fixedBytes, description));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// src/map-codec.ts
|
|
111
|
-
function mapEncoder(encoder, unmap) {
|
|
112
|
-
return {
|
|
113
|
-
description: encoder.description,
|
|
114
|
-
encode: (value) => encoder.encode(unmap(value)),
|
|
115
|
-
fixedSize: encoder.fixedSize,
|
|
116
|
-
maxSize: encoder.maxSize
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function mapDecoder(decoder, map) {
|
|
120
|
-
return {
|
|
121
|
-
decode: (bytes, offset = 0) => {
|
|
122
|
-
const [value, length] = decoder.decode(bytes, offset);
|
|
123
|
-
return [map(value, bytes, offset), length];
|
|
124
|
-
},
|
|
125
|
-
description: decoder.description,
|
|
126
|
-
fixedSize: decoder.fixedSize,
|
|
127
|
-
maxSize: decoder.maxSize
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function mapCodec(codec, unmap, map) {
|
|
131
|
-
return {
|
|
132
|
-
decode: map ? mapDecoder(codec, map).decode : codec.decode,
|
|
133
|
-
description: codec.description,
|
|
134
|
-
encode: mapEncoder(codec, unmap).encode,
|
|
135
|
-
fixedSize: codec.fixedSize,
|
|
136
|
-
maxSize: codec.maxSize
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// src/reverse-codec.ts
|
|
141
|
-
function reverseEncoder(encoder) {
|
|
142
|
-
assertFixedSizeCodec(encoder, "Cannot reverse a codec of variable size.");
|
|
143
|
-
return {
|
|
144
|
-
...encoder,
|
|
145
|
-
encode: (value) => encoder.encode(value).reverse()
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function reverseDecoder(decoder) {
|
|
149
|
-
assertFixedSizeCodec(decoder, "Cannot reverse a codec of variable size.");
|
|
150
|
-
return {
|
|
151
|
-
...decoder,
|
|
152
|
-
decode: (bytes, offset = 0) => {
|
|
153
|
-
const reverseEnd = offset + decoder.fixedSize;
|
|
154
|
-
if (offset === 0 && bytes.length === reverseEnd) {
|
|
155
|
-
return decoder.decode(bytes.reverse(), offset);
|
|
156
|
-
}
|
|
157
|
-
const newBytes = mergeBytes([
|
|
158
|
-
...offset === 0 ? [] : [bytes.slice(0, offset)],
|
|
159
|
-
bytes.slice(offset, reverseEnd).reverse(),
|
|
160
|
-
...bytes.length === reverseEnd ? [] : [bytes.slice(reverseEnd)]
|
|
161
|
-
]);
|
|
162
|
-
return decoder.decode(newBytes, offset);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
function reverseCodec(codec) {
|
|
167
|
-
return combineCodec(reverseEncoder(codec), reverseDecoder(codec));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
exports.assertByteArrayHasEnoughBytesForCodec = assertByteArrayHasEnoughBytesForCodec;
|
|
171
|
-
exports.assertByteArrayIsNotEmptyForCodec = assertByteArrayIsNotEmptyForCodec;
|
|
172
|
-
exports.assertFixedSizeCodec = assertFixedSizeCodec;
|
|
173
|
-
exports.combineCodec = combineCodec;
|
|
174
|
-
exports.fixBytes = fixBytes;
|
|
175
|
-
exports.fixCodec = fixCodec;
|
|
176
|
-
exports.fixDecoder = fixDecoder;
|
|
177
|
-
exports.fixEncoder = fixEncoder;
|
|
178
|
-
exports.mapCodec = mapCodec;
|
|
179
|
-
exports.mapDecoder = mapDecoder;
|
|
180
|
-
exports.mapEncoder = mapEncoder;
|
|
181
|
-
exports.mergeBytes = mergeBytes;
|
|
182
|
-
exports.padBytes = padBytes;
|
|
183
|
-
exports.reverseCodec = reverseCodec;
|
|
184
|
-
exports.reverseDecoder = reverseDecoder;
|
|
185
|
-
exports.reverseEncoder = reverseEncoder;
|
|
186
|
-
|
|
187
|
-
return exports;
|
|
188
|
-
|
|
189
|
-
})({});
|
|
190
|
-
//# sourceMappingURL=out.js.map
|
|
191
|
-
//# sourceMappingURL=index.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assertions.ts","../src/bytes.ts","../src/combine-codec.ts","../src/fix-codec.ts","../src/map-codec.ts","../src/reverse-codec.ts"],"names":[],"mappings":";AAKO,SAAS,kCAAkC,kBAA0B,OAAmB,SAAS,GAAG;AACvG,MAAI,MAAM,SAAS,UAAU,GAAG;AAE5B,UAAM,IAAI,MAAM,UAAU,gBAAgB,oCAAoC;AAAA,EAClF;AACJ;AAKO,SAAS,sCACZ,kBACA,UACA,OACA,SAAS,GACX;AACE,QAAM,cAAc,MAAM,SAAS;AACnC,MAAI,cAAc,UAAU;AAExB,UAAM,IAAI,MAAM,UAAU,gBAAgB,cAAc,QAAQ,eAAe,WAAW,GAAG;AAAA,EACjG;AACJ;AAKO,SAAS,qBACZ,MACA,SACqC;AACrC,MAAI,KAAK,cAAc,MAAM;AAEzB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,UAAU,EAAE,QAAQ;AAAA,QACxC,GAAI,MAAM,WAAW,aAAa,CAAC,IAAI,CAAC,MAAM,MAAM,UAAU,CAAC;AAAA,MACnE,CAAC;AACD,aAAO,QAAQ,OAAO,UAAU,MAAM;AAAA,IAC1C;AAAA,EACJ;AACJ;AAKO,SAAS,aAAiC,OAAiC;AAC9E,SAAO,aAAa,eAAe,KAAK,GAAG,eAAe,KAAK,CAAC;AACpE","sourcesContent":["import { CodecData } from './codec';\n\n/**\n * Asserts that a given byte array is not empty.\n */\nexport function assertByteArrayIsNotEmptyForCodec(codecDescription: string, bytes: Uint8Array, offset = 0) {\n if (bytes.length - offset <= 0) {\n // TODO: Coded error.\n throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);\n }\n}\n\n/**\n * Asserts that a given byte array has enough bytes to decode.\n */\nexport function assertByteArrayHasEnoughBytesForCodec(\n codecDescription: string,\n expected: number,\n bytes: Uint8Array,\n offset = 0\n) {\n const bytesLength = bytes.length - offset;\n if (bytesLength < expected) {\n // TODO: Coded error.\n throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);\n }\n}\n\n/**\n * Asserts that a given codec is fixed-size codec.\n */\nexport function assertFixedSizeCodec(\n data: Pick<CodecData, 'fixedSize'>,\n message?: string\n): asserts data is { fixedSize: number } {\n if (data.fixedSize === null) {\n // TODO: Coded error.\n throw new Error(message ?? 'Expected a fixed-size codec, got a variable-size one.');\n }\n}\n","/**\n * Concatenates an array of `Uint8Array`s into a single `Uint8Array`.\n * Reuses the original byte array when applicable.\n */\nexport const mergeBytes = (byteArrays: Uint8Array[]): Uint8Array => {\n const nonEmptyByteArrays = byteArrays.filter(arr => arr.length);\n if (nonEmptyByteArrays.length === 0) {\n return byteArrays.length ? byteArrays[0] : new Uint8Array();\n }\n\n if (nonEmptyByteArrays.length === 1) {\n return nonEmptyByteArrays[0];\n }\n\n const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n nonEmptyByteArrays.forEach(arr => {\n result.set(arr, offset);\n offset += arr.length;\n });\n return result;\n};\n\n/**\n * Pads a `Uint8Array` with zeroes to the specified length.\n * If the array is longer than the specified length, it is returned as-is.\n */\nexport const padBytes = (bytes: Uint8Array, length: number): Uint8Array => {\n if (bytes.length >= length) return bytes;\n const paddedBytes = new Uint8Array(length).fill(0);\n paddedBytes.set(bytes);\n return paddedBytes;\n};\n\n/**\n * Fixes a `Uint8Array` to the specified length.\n * If the array is longer than the specified length, it is truncated.\n * If the array is shorter than the specified length, it is padded with zeroes.\n */\nexport const fixBytes = (bytes: Uint8Array, length: number): Uint8Array =>\n padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);\n","import { Codec, Decoder, Encoder } from './codec';\n\n/**\n * Combines an encoder and a decoder into a codec.\n * The encoder and decoder must have the same fixed size, max size and description.\n * If a description is provided, it will override the encoder and decoder descriptions.\n */\nexport function combineCodec<From, To extends From = From>(\n encoder: Encoder<From>,\n decoder: Decoder<To>,\n description?: string\n): Codec<From, To> {\n if (encoder.fixedSize !== decoder.fixedSize) {\n // TODO: Coded error.\n throw new Error(\n `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`\n );\n }\n\n if (encoder.maxSize !== decoder.maxSize) {\n // TODO: Coded error.\n throw new Error(\n `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`\n );\n }\n\n if (description === undefined && encoder.description !== decoder.description) {\n // TODO: Coded error.\n throw new Error(\n `Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. ` +\n `Pass a custom description as a third argument if you want to override the description and bypass this error.`\n );\n }\n\n return {\n decode: decoder.decode,\n description: description ?? encoder.description,\n encode: encoder.encode,\n fixedSize: encoder.fixedSize,\n maxSize: encoder.maxSize,\n };\n}\n","import { assertByteArrayHasEnoughBytesForCodec } from './assertions';\nimport { fixBytes } from './bytes';\nimport { Codec, CodecData, Decoder, Encoder } from './codec';\nimport { combineCodec } from './combine-codec';\n\nfunction fixCodecHelper(data: CodecData, fixedBytes: number, description?: string): CodecData {\n return {\n description: description ?? `fixed(${fixedBytes}, ${data.description})`,\n fixedSize: fixedBytes,\n maxSize: fixedBytes,\n };\n}\n\n/**\n * Creates a fixed-size encoder from a given encoder.\n *\n * @param encoder - The encoder to wrap into a fixed-size encoder.\n * @param fixedBytes - The fixed number of bytes to write.\n * @param description - A custom description for the encoder.\n */\nexport function fixEncoder<T>(encoder: Encoder<T>, fixedBytes: number, description?: string): Encoder<T> {\n return {\n ...fixCodecHelper(encoder, fixedBytes, description),\n encode: (value: T) => fixBytes(encoder.encode(value), fixedBytes),\n };\n}\n\n/**\n * Creates a fixed-size decoder from a given decoder.\n *\n * @param decoder - The decoder to wrap into a fixed-size decoder.\n * @param fixedBytes - The fixed number of bytes to read.\n * @param description - A custom description for the decoder.\n */\nexport function fixDecoder<T>(decoder: Decoder<T>, fixedBytes: number, description?: string): Decoder<T> {\n return {\n ...fixCodecHelper(decoder, fixedBytes, description),\n decode: (bytes: Uint8Array, offset = 0) => {\n assertByteArrayHasEnoughBytesForCodec('fixCodec', fixedBytes, bytes, offset);\n // Slice the byte array to the fixed size if necessary.\n if (offset > 0 || bytes.length > fixedBytes) {\n bytes = bytes.slice(offset, offset + fixedBytes);\n }\n // If the nested decoder is fixed-size, pad and truncate the byte array accordingly.\n if (decoder.fixedSize !== null) {\n bytes = fixBytes(bytes, decoder.fixedSize);\n }\n // Decode the value using the nested decoder.\n const [value] = decoder.decode(bytes, 0);\n return [value, offset + fixedBytes];\n },\n };\n}\n\n/**\n * Creates a fixed-size codec from a given codec.\n *\n * @param codec - The codec to wrap into a fixed-size codec.\n * @param fixedBytes - The fixed number of bytes to read/write.\n * @param description - A custom description for the codec.\n */\nexport function fixCodec<T, U extends T = T>(\n codec: Codec<T, U>,\n fixedBytes: number,\n description?: string\n): Codec<T, U> {\n return combineCodec(fixEncoder(codec, fixedBytes, description), fixDecoder(codec, fixedBytes, description));\n}\n","import { Codec, Decoder, Encoder } from './codec';\n\n/**\n * Converts an encoder A to a encoder B by mapping their values.\n */\nexport function mapEncoder<T, U>(encoder: Encoder<T>, unmap: (value: U) => T): Encoder<U> {\n return {\n description: encoder.description,\n encode: (value: U) => encoder.encode(unmap(value)),\n fixedSize: encoder.fixedSize,\n maxSize: encoder.maxSize,\n };\n}\n\n/**\n * Converts an decoder A to a decoder B by mapping their values.\n */\nexport function mapDecoder<T, U>(\n decoder: Decoder<T>,\n map: (value: T, bytes: Uint8Array, offset: number) => U\n): Decoder<U> {\n return {\n decode: (bytes: Uint8Array, offset = 0) => {\n const [value, length] = decoder.decode(bytes, offset);\n return [map(value, bytes, offset), length];\n },\n description: decoder.description,\n fixedSize: decoder.fixedSize,\n maxSize: decoder.maxSize,\n };\n}\n\n/**\n * Converts a codec A to a codec B by mapping their values.\n */\nexport function mapCodec<NewFrom, OldFrom, To extends NewFrom & OldFrom>(\n codec: Codec<OldFrom, To>,\n unmap: (value: NewFrom) => OldFrom\n): Codec<NewFrom, To>;\nexport function mapCodec<NewFrom, OldFrom, NewTo extends NewFrom = NewFrom, OldTo extends OldFrom = OldFrom>(\n codec: Codec<OldFrom, OldTo>,\n unmap: (value: NewFrom) => OldFrom,\n map: (value: OldTo, bytes: Uint8Array, offset: number) => NewTo\n): Codec<NewFrom, NewTo>;\nexport function mapCodec<NewFrom, OldFrom, NewTo extends NewFrom = NewFrom, OldTo extends OldFrom = OldFrom>(\n codec: Codec<OldFrom, OldTo>,\n unmap: (value: NewFrom) => OldFrom,\n map?: (value: OldTo, bytes: Uint8Array, offset: number) => NewTo\n): Codec<NewFrom, NewTo> {\n return {\n decode: map ? mapDecoder(codec, map).decode : (codec.decode as unknown as Decoder<NewTo>['decode']),\n description: codec.description,\n encode: mapEncoder(codec, unmap).encode,\n fixedSize: codec.fixedSize,\n maxSize: codec.maxSize,\n };\n}\n","import { assertFixedSizeCodec } from './assertions';\nimport { mergeBytes } from './bytes';\nimport { Codec, Decoder, Encoder } from './codec';\nimport { combineCodec } from './combine-codec';\n\n/**\n * Reverses the bytes of a fixed-size encoder.\n */\nexport function reverseEncoder<T>(encoder: Encoder<T>): Encoder<T> {\n assertFixedSizeCodec(encoder, 'Cannot reverse a codec of variable size.');\n return {\n ...encoder,\n encode: (value: T) => encoder.encode(value).reverse(),\n };\n}\n\n/**\n * Reverses the bytes of a fixed-size decoder.\n */\nexport function reverseDecoder<T>(decoder: Decoder<T>): Decoder<T> {\n assertFixedSizeCodec(decoder, 'Cannot reverse a codec of variable size.');\n return {\n ...decoder,\n decode: (bytes: Uint8Array, offset = 0) => {\n const reverseEnd = offset + decoder.fixedSize;\n if (offset === 0 && bytes.length === reverseEnd) {\n return decoder.decode(bytes.reverse(), offset);\n }\n const newBytes = mergeBytes([\n ...(offset === 0 ? [] : [bytes.slice(0, offset)]),\n bytes.slice(offset, reverseEnd).reverse(),\n ...(bytes.length === reverseEnd ? [] : [bytes.slice(reverseEnd)]),\n ]);\n return decoder.decode(newBytes, offset);\n },\n };\n}\n\n/**\n * Reverses the bytes of a fixed-size codec.\n */\nexport function reverseCodec<T, U extends T = T>(codec: Codec<T, U>): Codec<T, U> {\n return combineCodec(reverseEncoder(codec), reverseDecoder(codec));\n}\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
function E(e,r,o=0){if(r.length-o<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function s(e,r,o,n=0){let t=o.length-n;if(t<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${t}.`)}function a(e,r){if(e.fixedSize===null)throw new Error(r??"Expected a fixed-size codec, got a variable-size one.")}var u=e=>{let r=e.filter(i=>i.length);if(r.length===0)return e.length?e[0]:new Uint8Array;if(r.length===1)return r[0];let o=r.reduce((i,p)=>i+p.length,0),n=new Uint8Array(o),t=0;return r.forEach(i=>{n.set(i,t),t+=i.length;}),n},f=(e,r)=>{if(e.length>=r)return e;let o=new Uint8Array(r).fill(0);return o.set(e),o},m=(e,r)=>f(e.length<=r?e:e.slice(0,r),r);function c(e,r,o){if(e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);if(o===void 0&&e.description!==r.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${r.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:r.decode,description:o??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function x(e,r,o){return {description:o??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r}}function l(e,r,o){return {...x(e,r,o),encode:n=>m(e.encode(n),r)}}function T(e,r,o){return {...x(e,r,o),decode:(n,t=0)=>{s("fixCodec",r,n,t),(t>0||n.length>r)&&(n=n.slice(t,t+r)),e.fixedSize!==null&&(n=m(n,e.fixedSize));let[i]=e.decode(n,0);return [i,t+r]}}}function $(e,r,o){return c(l(e,r,o),T(e,r,o))}function z(e,r){return {description:e.description,encode:o=>e.encode(r(o)),fixedSize:e.fixedSize,maxSize:e.maxSize}}function w(e,r){return {decode:(o,n=0)=>{let[t,i]=e.decode(o,n);return [r(t,o,n),i]},description:e.description,fixedSize:e.fixedSize,maxSize:e.maxSize}}function _(e,r,o){return {decode:o?w(e,o).decode:e.decode,description:e.description,encode:z(e,r).encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function C(e){return a(e,"Cannot reverse a codec of variable size."),{...e,encode:r=>e.encode(r).reverse()}}function F(e){return a(e,"Cannot reverse a codec of variable size."),{...e,decode:(r,o=0)=>{let n=o+e.fixedSize;if(o===0&&r.length===n)return e.decode(r.reverse(),o);let t=u([...o===0?[]:[r.slice(0,o)],r.slice(o,n).reverse(),...r.length===n?[]:[r.slice(n)]]);return e.decode(t,o)}}}function I(e){return c(C(e),F(e))}
|
|
6
|
-
|
|
7
|
-
exports.assertByteArrayHasEnoughBytesForCodec = s;
|
|
8
|
-
exports.assertByteArrayIsNotEmptyForCodec = E;
|
|
9
|
-
exports.assertFixedSizeCodec = a;
|
|
10
|
-
exports.combineCodec = c;
|
|
11
|
-
exports.fixBytes = m;
|
|
12
|
-
exports.fixCodec = $;
|
|
13
|
-
exports.fixDecoder = T;
|
|
14
|
-
exports.fixEncoder = l;
|
|
15
|
-
exports.mapCodec = _;
|
|
16
|
-
exports.mapDecoder = w;
|
|
17
|
-
exports.mapEncoder = z;
|
|
18
|
-
exports.mergeBytes = u;
|
|
19
|
-
exports.padBytes = f;
|
|
20
|
-
exports.reverseCodec = I;
|
|
21
|
-
exports.reverseDecoder = F;
|
|
22
|
-
exports.reverseEncoder = C;
|
|
23
|
-
|
|
24
|
-
return exports;
|
|
25
|
-
|
|
26
|
-
})({});
|