@solana/codecs-data-structures 2.0.0-experimental.eb5fd16 → 2.0.0-experimental.eeb355e
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/LICENSE +1 -1
- package/dist/index.browser.cjs +94 -96
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +94 -94
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +104 -104
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +94 -94
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +94 -96
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +94 -94
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +21 -21
- package/dist/types/array.d.ts +9 -9
- package/dist/types/bit-array.d.ts +9 -9
- package/dist/types/boolean.d.ts +9 -9
- package/dist/types/bytes.d.ts +9 -9
- package/dist/types/data-enum.d.ts +9 -9
- package/dist/types/map.d.ts +9 -9
- package/dist/types/nullable.d.ts +9 -9
- package/dist/types/scalar-enum.d.ts +9 -9
- package/dist/types/set.d.ts +9 -9
- package/dist/types/struct.d.ts +9 -9
- package/dist/types/tuple.d.ts +9 -9
- package/dist/types/unit.d.ts +9 -9
- package/package.json +10 -10
|
@@ -110,11 +110,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
110
110
|
let littleEndian;
|
|
111
111
|
let defaultDescription = input.name;
|
|
112
112
|
if (input.size > 1) {
|
|
113
|
-
littleEndian = !("endian" in input.
|
|
113
|
+
littleEndian = !("endian" in input.config) || input.config.endian === 0;
|
|
114
114
|
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
115
115
|
}
|
|
116
116
|
return {
|
|
117
|
-
description: input.
|
|
117
|
+
description: input.config.description ?? defaultDescription,
|
|
118
118
|
fixedSize: input.size,
|
|
119
119
|
littleEndian,
|
|
120
120
|
maxSize: input.size
|
|
@@ -155,30 +155,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
155
155
|
const bytesLength = length ?? bytes.byteLength;
|
|
156
156
|
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
157
157
|
}
|
|
158
|
-
var getU32Encoder = (
|
|
158
|
+
var getU32Encoder = (config = {}) => numberEncoderFactory({
|
|
159
|
+
config,
|
|
159
160
|
name: "u32",
|
|
160
|
-
options,
|
|
161
161
|
range: [0, Number("0xffffffff")],
|
|
162
162
|
set: (view, value, le) => view.setUint32(0, value, le),
|
|
163
163
|
size: 4
|
|
164
164
|
});
|
|
165
|
-
var getU32Decoder = (
|
|
165
|
+
var getU32Decoder = (config = {}) => numberDecoderFactory({
|
|
166
|
+
config,
|
|
166
167
|
get: (view, le) => view.getUint32(0, le),
|
|
167
168
|
name: "u32",
|
|
168
|
-
options,
|
|
169
169
|
size: 4
|
|
170
170
|
});
|
|
171
|
-
var getU8Encoder = (
|
|
171
|
+
var getU8Encoder = (config = {}) => numberEncoderFactory({
|
|
172
|
+
config,
|
|
172
173
|
name: "u8",
|
|
173
|
-
options,
|
|
174
174
|
range: [0, Number("0xff")],
|
|
175
175
|
set: (view, value) => view.setUint8(0, value),
|
|
176
176
|
size: 1
|
|
177
177
|
});
|
|
178
|
-
var getU8Decoder = (
|
|
178
|
+
var getU8Decoder = (config = {}) => numberDecoderFactory({
|
|
179
|
+
config,
|
|
179
180
|
get: (view) => view.getUint8(0),
|
|
180
181
|
name: "u8",
|
|
181
|
-
options,
|
|
182
182
|
size: 1
|
|
183
183
|
});
|
|
184
184
|
|
|
@@ -249,10 +249,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
249
249
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
-
function getArrayEncoder(item,
|
|
253
|
-
const size =
|
|
252
|
+
function getArrayEncoder(item, config = {}) {
|
|
253
|
+
const size = config.size ?? getU32Encoder();
|
|
254
254
|
return {
|
|
255
|
-
...arrayCodecHelper(item, size,
|
|
255
|
+
...arrayCodecHelper(item, size, config.description),
|
|
256
256
|
encode: (value) => {
|
|
257
257
|
if (typeof size === "number") {
|
|
258
258
|
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
@@ -261,10 +261,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
261
261
|
}
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
|
-
function getArrayDecoder(item,
|
|
265
|
-
const size =
|
|
264
|
+
function getArrayDecoder(item, config = {}) {
|
|
265
|
+
const size = config.size ?? getU32Decoder();
|
|
266
266
|
return {
|
|
267
|
-
...arrayCodecHelper(item, size,
|
|
267
|
+
...arrayCodecHelper(item, size, config.description),
|
|
268
268
|
decode: (bytes, offset = 0) => {
|
|
269
269
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
270
270
|
return [[], offset];
|
|
@@ -281,17 +281,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
281
281
|
}
|
|
282
282
|
};
|
|
283
283
|
}
|
|
284
|
-
function getArrayCodec(item,
|
|
285
|
-
return combineCodec(getArrayEncoder(item,
|
|
284
|
+
function getArrayCodec(item, config = {}) {
|
|
285
|
+
return combineCodec(getArrayEncoder(item, config), getArrayDecoder(item, config));
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
// src/bit-array.ts
|
|
289
|
-
var getBitArrayEncoder = (size,
|
|
290
|
-
const
|
|
291
|
-
const backward =
|
|
289
|
+
var getBitArrayEncoder = (size, config = {}) => {
|
|
290
|
+
const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
|
|
291
|
+
const backward = parsedConfig.backward ?? false;
|
|
292
292
|
const backwardSuffix = backward ? "; backward" : "";
|
|
293
293
|
return {
|
|
294
|
-
description:
|
|
294
|
+
description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
|
|
295
295
|
encode(value) {
|
|
296
296
|
const bytes = [];
|
|
297
297
|
for (let i = 0; i < size; i += 1) {
|
|
@@ -312,9 +312,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
312
312
|
maxSize: size
|
|
313
313
|
};
|
|
314
314
|
};
|
|
315
|
-
var getBitArrayDecoder = (size,
|
|
316
|
-
const
|
|
317
|
-
const backward =
|
|
315
|
+
var getBitArrayDecoder = (size, config = {}) => {
|
|
316
|
+
const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
|
|
317
|
+
const backward = parsedConfig.backward ?? false;
|
|
318
318
|
const backwardSuffix = backward ? "; backward" : "";
|
|
319
319
|
return {
|
|
320
320
|
decode(bytes, offset = 0) {
|
|
@@ -335,26 +335,26 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
335
335
|
});
|
|
336
336
|
return [booleans, offset + size];
|
|
337
337
|
},
|
|
338
|
-
description:
|
|
338
|
+
description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
|
|
339
339
|
fixedSize: size,
|
|
340
340
|
maxSize: size
|
|
341
341
|
};
|
|
342
342
|
};
|
|
343
|
-
var getBitArrayCodec = (size,
|
|
343
|
+
var getBitArrayCodec = (size, config = {}) => combineCodec(getBitArrayEncoder(size, config), getBitArrayDecoder(size, config));
|
|
344
344
|
|
|
345
345
|
// src/boolean.ts
|
|
346
|
-
function getBooleanEncoder(
|
|
347
|
-
const size =
|
|
346
|
+
function getBooleanEncoder(config = {}) {
|
|
347
|
+
const size = config.size ?? getU8Encoder();
|
|
348
348
|
assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
|
|
349
349
|
return {
|
|
350
|
-
description:
|
|
350
|
+
description: config.description ?? `bool(${size.description})`,
|
|
351
351
|
encode: (value) => size.encode(value ? 1 : 0),
|
|
352
352
|
fixedSize: size.fixedSize,
|
|
353
353
|
maxSize: size.fixedSize
|
|
354
354
|
};
|
|
355
355
|
}
|
|
356
|
-
function getBooleanDecoder(
|
|
357
|
-
const size =
|
|
356
|
+
function getBooleanDecoder(config = {}) {
|
|
357
|
+
const size = config.size ?? getU8Decoder();
|
|
358
358
|
assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
|
|
359
359
|
return {
|
|
360
360
|
decode: (bytes, offset = 0) => {
|
|
@@ -362,20 +362,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
362
362
|
const [value, vOffset] = size.decode(bytes, offset);
|
|
363
363
|
return [value === 1, vOffset];
|
|
364
364
|
},
|
|
365
|
-
description:
|
|
365
|
+
description: config.description ?? `bool(${size.description})`,
|
|
366
366
|
fixedSize: size.fixedSize,
|
|
367
367
|
maxSize: size.fixedSize
|
|
368
368
|
};
|
|
369
369
|
}
|
|
370
|
-
function getBooleanCodec(
|
|
371
|
-
return combineCodec(getBooleanEncoder(
|
|
370
|
+
function getBooleanCodec(config = {}) {
|
|
371
|
+
return combineCodec(getBooleanEncoder(config), getBooleanDecoder(config));
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
// src/bytes.ts
|
|
375
|
-
function getBytesEncoder(
|
|
376
|
-
const size =
|
|
375
|
+
function getBytesEncoder(config = {}) {
|
|
376
|
+
const size = config.size ?? "variable";
|
|
377
377
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
378
|
-
const description =
|
|
378
|
+
const description = config.description ?? `bytes(${sizeDescription})`;
|
|
379
379
|
const byteEncoder = {
|
|
380
380
|
description,
|
|
381
381
|
encode: (value) => value,
|
|
@@ -397,10 +397,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
397
397
|
}
|
|
398
398
|
};
|
|
399
399
|
}
|
|
400
|
-
function getBytesDecoder(
|
|
401
|
-
const size =
|
|
400
|
+
function getBytesDecoder(config = {}) {
|
|
401
|
+
const size = config.size ?? "variable";
|
|
402
402
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
403
|
-
const description =
|
|
403
|
+
const description = config.description ?? `bytes(${sizeDescription})`;
|
|
404
404
|
const byteDecoder = {
|
|
405
405
|
decode: (bytes, offset = 0) => {
|
|
406
406
|
const slice = bytes.slice(offset);
|
|
@@ -431,8 +431,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
431
431
|
}
|
|
432
432
|
};
|
|
433
433
|
}
|
|
434
|
-
function getBytesCodec(
|
|
435
|
-
return combineCodec(getBytesEncoder(
|
|
434
|
+
function getBytesCodec(config = {}) {
|
|
435
|
+
return combineCodec(getBytesEncoder(config), getBytesDecoder(config));
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
// src/data-enum.ts
|
|
@@ -447,10 +447,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
447
447
|
maxSize: variants.length === 0 ? prefix.maxSize : sumCodecSizes([prefix.maxSize, maxVariantSize])
|
|
448
448
|
};
|
|
449
449
|
}
|
|
450
|
-
function getDataEnumEncoder(variants,
|
|
451
|
-
const prefix =
|
|
450
|
+
function getDataEnumEncoder(variants, config = {}) {
|
|
451
|
+
const prefix = config.size ?? getU8Encoder();
|
|
452
452
|
return {
|
|
453
|
-
...dataEnumCodecHelper(variants, prefix,
|
|
453
|
+
...dataEnumCodecHelper(variants, prefix, config.description),
|
|
454
454
|
encode: (variant) => {
|
|
455
455
|
const discriminator = variants.findIndex(([key]) => variant.__kind === key);
|
|
456
456
|
if (discriminator < 0) {
|
|
@@ -465,10 +465,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
465
465
|
}
|
|
466
466
|
};
|
|
467
467
|
}
|
|
468
|
-
function getDataEnumDecoder(variants,
|
|
469
|
-
const prefix =
|
|
468
|
+
function getDataEnumDecoder(variants, config = {}) {
|
|
469
|
+
const prefix = config.size ?? getU8Decoder();
|
|
470
470
|
return {
|
|
471
|
-
...dataEnumCodecHelper(variants, prefix,
|
|
471
|
+
...dataEnumCodecHelper(variants, prefix, config.description),
|
|
472
472
|
decode: (bytes, offset = 0) => {
|
|
473
473
|
assertByteArrayIsNotEmptyForCodec("dataEnum", bytes, offset);
|
|
474
474
|
const [discriminator, dOffset] = prefix.decode(bytes, offset);
|
|
@@ -485,8 +485,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
485
485
|
}
|
|
486
486
|
};
|
|
487
487
|
}
|
|
488
|
-
function getDataEnumCodec(variants,
|
|
489
|
-
return combineCodec(getDataEnumEncoder(variants,
|
|
488
|
+
function getDataEnumCodec(variants, config = {}) {
|
|
489
|
+
return combineCodec(getDataEnumEncoder(variants, config), getDataEnumDecoder(variants, config));
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
// src/map.ts
|
|
@@ -500,10 +500,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
500
500
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [key.maxSize, value.maxSize])
|
|
501
501
|
};
|
|
502
502
|
}
|
|
503
|
-
function getMapEncoder(key, value,
|
|
504
|
-
const size =
|
|
503
|
+
function getMapEncoder(key, value, config = {}) {
|
|
504
|
+
const size = config.size ?? getU32Encoder();
|
|
505
505
|
return {
|
|
506
|
-
...mapCodecHelper(key, value, size,
|
|
506
|
+
...mapCodecHelper(key, value, size, config.description),
|
|
507
507
|
encode: (map) => {
|
|
508
508
|
if (typeof size === "number") {
|
|
509
509
|
assertValidNumberOfItemsForCodec("map", size, map.size);
|
|
@@ -513,10 +513,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
513
513
|
}
|
|
514
514
|
};
|
|
515
515
|
}
|
|
516
|
-
function getMapDecoder(key, value,
|
|
517
|
-
const size =
|
|
516
|
+
function getMapDecoder(key, value, config = {}) {
|
|
517
|
+
const size = config.size ?? getU32Decoder();
|
|
518
518
|
return {
|
|
519
|
-
...mapCodecHelper(key, value, size,
|
|
519
|
+
...mapCodecHelper(key, value, size, config.description),
|
|
520
520
|
decode: (bytes, offset = 0) => {
|
|
521
521
|
const map = /* @__PURE__ */ new Map();
|
|
522
522
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
@@ -540,8 +540,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
540
540
|
}
|
|
541
541
|
};
|
|
542
542
|
}
|
|
543
|
-
function getMapCodec(key, value,
|
|
544
|
-
return combineCodec(getMapEncoder(key, value,
|
|
543
|
+
function getMapCodec(key, value, config = {}) {
|
|
544
|
+
return combineCodec(getMapEncoder(key, value, config), getMapDecoder(key, value, config));
|
|
545
545
|
}
|
|
546
546
|
|
|
547
547
|
// src/nullable.ts
|
|
@@ -560,11 +560,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
560
560
|
maxSize: sumCodecSizes([prefix.maxSize, item.maxSize])
|
|
561
561
|
};
|
|
562
562
|
}
|
|
563
|
-
function getNullableEncoder(item,
|
|
564
|
-
const prefix =
|
|
565
|
-
const fixed =
|
|
563
|
+
function getNullableEncoder(item, config = {}) {
|
|
564
|
+
const prefix = config.prefix ?? getU8Encoder();
|
|
565
|
+
const fixed = config.fixed ?? false;
|
|
566
566
|
return {
|
|
567
|
-
...nullableCodecHelper(item, prefix, fixed,
|
|
567
|
+
...nullableCodecHelper(item, prefix, fixed, config.description),
|
|
568
568
|
encode: (option) => {
|
|
569
569
|
const prefixByte = prefix.encode(Number(option !== null));
|
|
570
570
|
let itemBytes = option !== null ? item.encode(option) : new Uint8Array();
|
|
@@ -573,11 +573,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
573
573
|
}
|
|
574
574
|
};
|
|
575
575
|
}
|
|
576
|
-
function getNullableDecoder(item,
|
|
577
|
-
const prefix =
|
|
578
|
-
const fixed =
|
|
576
|
+
function getNullableDecoder(item, config = {}) {
|
|
577
|
+
const prefix = config.prefix ?? getU8Decoder();
|
|
578
|
+
const fixed = config.fixed ?? false;
|
|
579
579
|
return {
|
|
580
|
-
...nullableCodecHelper(item, prefix, fixed,
|
|
580
|
+
...nullableCodecHelper(item, prefix, fixed, config.description),
|
|
581
581
|
decode: (bytes, offset = 0) => {
|
|
582
582
|
if (bytes.length - offset <= 0) {
|
|
583
583
|
return [null, offset];
|
|
@@ -594,8 +594,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
594
594
|
}
|
|
595
595
|
};
|
|
596
596
|
}
|
|
597
|
-
function getNullableCodec(item,
|
|
598
|
-
return combineCodec(getNullableEncoder(item,
|
|
597
|
+
function getNullableCodec(item, config = {}) {
|
|
598
|
+
return combineCodec(getNullableEncoder(item, config), getNullableDecoder(item, config));
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
// src/scalar-enum.ts
|
|
@@ -619,9 +619,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
619
619
|
stringValues
|
|
620
620
|
};
|
|
621
621
|
}
|
|
622
|
-
function getScalarEnumEncoder(constructor,
|
|
623
|
-
const prefix =
|
|
624
|
-
const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix,
|
|
622
|
+
function getScalarEnumEncoder(constructor, config = {}) {
|
|
623
|
+
const prefix = config.size ?? getU8Encoder();
|
|
624
|
+
const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix, config.description);
|
|
625
625
|
return {
|
|
626
626
|
description,
|
|
627
627
|
encode: (value) => {
|
|
@@ -643,12 +643,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
643
643
|
maxSize
|
|
644
644
|
};
|
|
645
645
|
}
|
|
646
|
-
function getScalarEnumDecoder(constructor,
|
|
647
|
-
const prefix =
|
|
646
|
+
function getScalarEnumDecoder(constructor, config = {}) {
|
|
647
|
+
const prefix = config.size ?? getU8Decoder();
|
|
648
648
|
const { description, fixedSize, maxSize, minRange, maxRange, isNumericEnum, enumValues } = scalarEnumCoderHelper(
|
|
649
649
|
constructor,
|
|
650
650
|
prefix,
|
|
651
|
-
|
|
651
|
+
config.description
|
|
652
652
|
);
|
|
653
653
|
return {
|
|
654
654
|
decode: (bytes, offset = 0) => {
|
|
@@ -668,8 +668,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
668
668
|
maxSize
|
|
669
669
|
};
|
|
670
670
|
}
|
|
671
|
-
function getScalarEnumCodec(constructor,
|
|
672
|
-
return combineCodec(getScalarEnumEncoder(constructor,
|
|
671
|
+
function getScalarEnumCodec(constructor, config = {}) {
|
|
672
|
+
return combineCodec(getScalarEnumEncoder(constructor, config), getScalarEnumDecoder(constructor, config));
|
|
673
673
|
}
|
|
674
674
|
|
|
675
675
|
// src/set.ts
|
|
@@ -683,10 +683,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
683
683
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
684
684
|
};
|
|
685
685
|
}
|
|
686
|
-
function getSetEncoder(item,
|
|
687
|
-
const size =
|
|
686
|
+
function getSetEncoder(item, config = {}) {
|
|
687
|
+
const size = config.size ?? getU32Encoder();
|
|
688
688
|
return {
|
|
689
|
-
...setCodecHelper(item, size,
|
|
689
|
+
...setCodecHelper(item, size, config.description),
|
|
690
690
|
encode: (set) => {
|
|
691
691
|
if (typeof size === "number" && set.size !== size) {
|
|
692
692
|
assertValidNumberOfItemsForCodec("set", size, set.size);
|
|
@@ -696,10 +696,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
696
696
|
}
|
|
697
697
|
};
|
|
698
698
|
}
|
|
699
|
-
function getSetDecoder(item,
|
|
700
|
-
const size =
|
|
699
|
+
function getSetDecoder(item, config = {}) {
|
|
700
|
+
const size = config.size ?? getU32Decoder();
|
|
701
701
|
return {
|
|
702
|
-
...setCodecHelper(item, size,
|
|
702
|
+
...setCodecHelper(item, size, config.description),
|
|
703
703
|
decode: (bytes, offset = 0) => {
|
|
704
704
|
const set = /* @__PURE__ */ new Set();
|
|
705
705
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
@@ -716,8 +716,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
716
716
|
}
|
|
717
717
|
};
|
|
718
718
|
}
|
|
719
|
-
function getSetCodec(item,
|
|
720
|
-
return combineCodec(getSetEncoder(item,
|
|
719
|
+
function getSetCodec(item, config = {}) {
|
|
720
|
+
return combineCodec(getSetEncoder(item, config), getSetDecoder(item, config));
|
|
721
721
|
}
|
|
722
722
|
|
|
723
723
|
// src/struct.ts
|
|
@@ -729,18 +729,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
729
729
|
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
730
730
|
};
|
|
731
731
|
}
|
|
732
|
-
function getStructEncoder(fields,
|
|
732
|
+
function getStructEncoder(fields, config = {}) {
|
|
733
733
|
return {
|
|
734
|
-
...structCodecHelper(fields,
|
|
734
|
+
...structCodecHelper(fields, config.description),
|
|
735
735
|
encode: (struct) => {
|
|
736
736
|
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
737
737
|
return mergeBytes(fieldBytes);
|
|
738
738
|
}
|
|
739
739
|
};
|
|
740
740
|
}
|
|
741
|
-
function getStructDecoder(fields,
|
|
741
|
+
function getStructDecoder(fields, config = {}) {
|
|
742
742
|
return {
|
|
743
|
-
...structCodecHelper(fields,
|
|
743
|
+
...structCodecHelper(fields, config.description),
|
|
744
744
|
decode: (bytes, offset = 0) => {
|
|
745
745
|
const struct = {};
|
|
746
746
|
fields.forEach(([key, codec]) => {
|
|
@@ -752,8 +752,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
752
752
|
}
|
|
753
753
|
};
|
|
754
754
|
}
|
|
755
|
-
function getStructCodec(fields,
|
|
756
|
-
return combineCodec(getStructEncoder(fields,
|
|
755
|
+
function getStructCodec(fields, config = {}) {
|
|
756
|
+
return combineCodec(getStructEncoder(fields, config), getStructDecoder(fields, config));
|
|
757
757
|
}
|
|
758
758
|
|
|
759
759
|
// src/tuple.ts
|
|
@@ -765,18 +765,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
765
765
|
maxSize: sumCodecSizes(items.map((item) => item.maxSize))
|
|
766
766
|
};
|
|
767
767
|
}
|
|
768
|
-
function getTupleEncoder(items,
|
|
768
|
+
function getTupleEncoder(items, config = {}) {
|
|
769
769
|
return {
|
|
770
|
-
...tupleCodecHelper(items,
|
|
770
|
+
...tupleCodecHelper(items, config.description),
|
|
771
771
|
encode: (value) => {
|
|
772
772
|
assertValidNumberOfItemsForCodec("tuple", items.length, value.length);
|
|
773
773
|
return mergeBytes(items.map((item, index) => item.encode(value[index])));
|
|
774
774
|
}
|
|
775
775
|
};
|
|
776
776
|
}
|
|
777
|
-
function getTupleDecoder(items,
|
|
777
|
+
function getTupleDecoder(items, config = {}) {
|
|
778
778
|
return {
|
|
779
|
-
...tupleCodecHelper(items,
|
|
779
|
+
...tupleCodecHelper(items, config.description),
|
|
780
780
|
decode: (bytes, offset = 0) => {
|
|
781
781
|
const values = [];
|
|
782
782
|
items.forEach((codec) => {
|
|
@@ -788,32 +788,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
788
788
|
}
|
|
789
789
|
};
|
|
790
790
|
}
|
|
791
|
-
function getTupleCodec(items,
|
|
791
|
+
function getTupleCodec(items, config = {}) {
|
|
792
792
|
return combineCodec(
|
|
793
|
-
getTupleEncoder(items,
|
|
794
|
-
getTupleDecoder(items,
|
|
793
|
+
getTupleEncoder(items, config),
|
|
794
|
+
getTupleDecoder(items, config)
|
|
795
795
|
);
|
|
796
796
|
}
|
|
797
797
|
|
|
798
798
|
// src/unit.ts
|
|
799
|
-
function getUnitEncoder(
|
|
799
|
+
function getUnitEncoder(config = {}) {
|
|
800
800
|
return {
|
|
801
|
-
description:
|
|
801
|
+
description: config.description ?? "unit",
|
|
802
802
|
encode: () => new Uint8Array(),
|
|
803
803
|
fixedSize: 0,
|
|
804
804
|
maxSize: 0
|
|
805
805
|
};
|
|
806
806
|
}
|
|
807
|
-
function getUnitDecoder(
|
|
807
|
+
function getUnitDecoder(config = {}) {
|
|
808
808
|
return {
|
|
809
809
|
decode: (_bytes, offset = 0) => [void 0, offset],
|
|
810
|
-
description:
|
|
810
|
+
description: config.description ?? "unit",
|
|
811
811
|
fixedSize: 0,
|
|
812
812
|
maxSize: 0
|
|
813
813
|
};
|
|
814
814
|
}
|
|
815
|
-
function getUnitCodec(
|
|
816
|
-
return combineCodec(getUnitEncoder(
|
|
815
|
+
function getUnitCodec(config = {}) {
|
|
816
|
+
return combineCodec(getUnitEncoder(config), getUnitDecoder(config));
|
|
817
817
|
}
|
|
818
818
|
|
|
819
819
|
exports.assertValidNumberOfItemsForCodec = assertValidNumberOfItemsForCodec;
|