@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
package/dist/index.native.js
CHANGED
|
@@ -70,10 +70,10 @@ function arrayCodecHelper(item, size, description) {
|
|
|
70
70
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
-
function getArrayEncoder(item,
|
|
74
|
-
const size =
|
|
73
|
+
function getArrayEncoder(item, config = {}) {
|
|
74
|
+
const size = config.size ?? getU32Encoder();
|
|
75
75
|
return {
|
|
76
|
-
...arrayCodecHelper(item, size,
|
|
76
|
+
...arrayCodecHelper(item, size, config.description),
|
|
77
77
|
encode: (value) => {
|
|
78
78
|
if (typeof size === "number") {
|
|
79
79
|
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
@@ -82,10 +82,10 @@ function getArrayEncoder(item, options = {}) {
|
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
function getArrayDecoder(item,
|
|
86
|
-
const size =
|
|
85
|
+
function getArrayDecoder(item, config = {}) {
|
|
86
|
+
const size = config.size ?? getU32Decoder();
|
|
87
87
|
return {
|
|
88
|
-
...arrayCodecHelper(item, size,
|
|
88
|
+
...arrayCodecHelper(item, size, config.description),
|
|
89
89
|
decode: (bytes, offset = 0) => {
|
|
90
90
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
91
91
|
return [[], offset];
|
|
@@ -102,15 +102,15 @@ function getArrayDecoder(item, options = {}) {
|
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
function getArrayCodec(item,
|
|
106
|
-
return combineCodec(getArrayEncoder(item,
|
|
105
|
+
function getArrayCodec(item, config = {}) {
|
|
106
|
+
return combineCodec(getArrayEncoder(item, config), getArrayDecoder(item, config));
|
|
107
107
|
}
|
|
108
|
-
var getBitArrayEncoder = (size,
|
|
109
|
-
const
|
|
110
|
-
const backward =
|
|
108
|
+
var getBitArrayEncoder = (size, config = {}) => {
|
|
109
|
+
const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
|
|
110
|
+
const backward = parsedConfig.backward ?? false;
|
|
111
111
|
const backwardSuffix = backward ? "; backward" : "";
|
|
112
112
|
return {
|
|
113
|
-
description:
|
|
113
|
+
description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
|
|
114
114
|
encode(value) {
|
|
115
115
|
const bytes = [];
|
|
116
116
|
for (let i = 0; i < size; i += 1) {
|
|
@@ -131,9 +131,9 @@ var getBitArrayEncoder = (size, options = {}) => {
|
|
|
131
131
|
maxSize: size
|
|
132
132
|
};
|
|
133
133
|
};
|
|
134
|
-
var getBitArrayDecoder = (size,
|
|
135
|
-
const
|
|
136
|
-
const backward =
|
|
134
|
+
var getBitArrayDecoder = (size, config = {}) => {
|
|
135
|
+
const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
|
|
136
|
+
const backward = parsedConfig.backward ?? false;
|
|
137
137
|
const backwardSuffix = backward ? "; backward" : "";
|
|
138
138
|
return {
|
|
139
139
|
decode(bytes, offset = 0) {
|
|
@@ -154,24 +154,24 @@ var getBitArrayDecoder = (size, options = {}) => {
|
|
|
154
154
|
});
|
|
155
155
|
return [booleans, offset + size];
|
|
156
156
|
},
|
|
157
|
-
description:
|
|
157
|
+
description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
|
|
158
158
|
fixedSize: size,
|
|
159
159
|
maxSize: size
|
|
160
160
|
};
|
|
161
161
|
};
|
|
162
|
-
var getBitArrayCodec = (size,
|
|
163
|
-
function getBooleanEncoder(
|
|
164
|
-
const size =
|
|
162
|
+
var getBitArrayCodec = (size, config = {}) => combineCodec(getBitArrayEncoder(size, config), getBitArrayDecoder(size, config));
|
|
163
|
+
function getBooleanEncoder(config = {}) {
|
|
164
|
+
const size = config.size ?? getU8Encoder();
|
|
165
165
|
assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
|
|
166
166
|
return {
|
|
167
|
-
description:
|
|
167
|
+
description: config.description ?? `bool(${size.description})`,
|
|
168
168
|
encode: (value) => size.encode(value ? 1 : 0),
|
|
169
169
|
fixedSize: size.fixedSize,
|
|
170
170
|
maxSize: size.fixedSize
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
-
function getBooleanDecoder(
|
|
174
|
-
const size =
|
|
173
|
+
function getBooleanDecoder(config = {}) {
|
|
174
|
+
const size = config.size ?? getU8Decoder();
|
|
175
175
|
assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
|
|
176
176
|
return {
|
|
177
177
|
decode: (bytes, offset = 0) => {
|
|
@@ -179,18 +179,18 @@ function getBooleanDecoder(options = {}) {
|
|
|
179
179
|
const [value, vOffset] = size.decode(bytes, offset);
|
|
180
180
|
return [value === 1, vOffset];
|
|
181
181
|
},
|
|
182
|
-
description:
|
|
182
|
+
description: config.description ?? `bool(${size.description})`,
|
|
183
183
|
fixedSize: size.fixedSize,
|
|
184
184
|
maxSize: size.fixedSize
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
|
-
function getBooleanCodec(
|
|
188
|
-
return combineCodec(getBooleanEncoder(
|
|
187
|
+
function getBooleanCodec(config = {}) {
|
|
188
|
+
return combineCodec(getBooleanEncoder(config), getBooleanDecoder(config));
|
|
189
189
|
}
|
|
190
|
-
function getBytesEncoder(
|
|
191
|
-
const size =
|
|
190
|
+
function getBytesEncoder(config = {}) {
|
|
191
|
+
const size = config.size ?? "variable";
|
|
192
192
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
193
|
-
const description =
|
|
193
|
+
const description = config.description ?? `bytes(${sizeDescription})`;
|
|
194
194
|
const byteEncoder = {
|
|
195
195
|
description,
|
|
196
196
|
encode: (value) => value,
|
|
@@ -212,10 +212,10 @@ function getBytesEncoder(options = {}) {
|
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
|
-
function getBytesDecoder(
|
|
216
|
-
const size =
|
|
215
|
+
function getBytesDecoder(config = {}) {
|
|
216
|
+
const size = config.size ?? "variable";
|
|
217
217
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
218
|
-
const description =
|
|
218
|
+
const description = config.description ?? `bytes(${sizeDescription})`;
|
|
219
219
|
const byteDecoder = {
|
|
220
220
|
decode: (bytes, offset = 0) => {
|
|
221
221
|
const slice = bytes.slice(offset);
|
|
@@ -246,8 +246,8 @@ function getBytesDecoder(options = {}) {
|
|
|
246
246
|
}
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
|
-
function getBytesCodec(
|
|
250
|
-
return combineCodec(getBytesEncoder(
|
|
249
|
+
function getBytesCodec(config = {}) {
|
|
250
|
+
return combineCodec(getBytesEncoder(config), getBytesDecoder(config));
|
|
251
251
|
}
|
|
252
252
|
function dataEnumCodecHelper(variants, prefix, description) {
|
|
253
253
|
const fieldDescriptions = variants.map(([name, codec]) => `${String(name)}${codec ? `: ${codec.description}` : ""}`).join(", ");
|
|
@@ -260,10 +260,10 @@ function dataEnumCodecHelper(variants, prefix, description) {
|
|
|
260
260
|
maxSize: variants.length === 0 ? prefix.maxSize : sumCodecSizes([prefix.maxSize, maxVariantSize])
|
|
261
261
|
};
|
|
262
262
|
}
|
|
263
|
-
function getDataEnumEncoder(variants,
|
|
264
|
-
const prefix =
|
|
263
|
+
function getDataEnumEncoder(variants, config = {}) {
|
|
264
|
+
const prefix = config.size ?? getU8Encoder();
|
|
265
265
|
return {
|
|
266
|
-
...dataEnumCodecHelper(variants, prefix,
|
|
266
|
+
...dataEnumCodecHelper(variants, prefix, config.description),
|
|
267
267
|
encode: (variant) => {
|
|
268
268
|
const discriminator = variants.findIndex(([key]) => variant.__kind === key);
|
|
269
269
|
if (discriminator < 0) {
|
|
@@ -278,10 +278,10 @@ function getDataEnumEncoder(variants, options = {}) {
|
|
|
278
278
|
}
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
|
-
function getDataEnumDecoder(variants,
|
|
282
|
-
const prefix =
|
|
281
|
+
function getDataEnumDecoder(variants, config = {}) {
|
|
282
|
+
const prefix = config.size ?? getU8Decoder();
|
|
283
283
|
return {
|
|
284
|
-
...dataEnumCodecHelper(variants, prefix,
|
|
284
|
+
...dataEnumCodecHelper(variants, prefix, config.description),
|
|
285
285
|
decode: (bytes, offset = 0) => {
|
|
286
286
|
assertByteArrayIsNotEmptyForCodec("dataEnum", bytes, offset);
|
|
287
287
|
const [discriminator, dOffset] = prefix.decode(bytes, offset);
|
|
@@ -298,8 +298,8 @@ function getDataEnumDecoder(variants, options = {}) {
|
|
|
298
298
|
}
|
|
299
299
|
};
|
|
300
300
|
}
|
|
301
|
-
function getDataEnumCodec(variants,
|
|
302
|
-
return combineCodec(getDataEnumEncoder(variants,
|
|
301
|
+
function getDataEnumCodec(variants, config = {}) {
|
|
302
|
+
return combineCodec(getDataEnumEncoder(variants, config), getDataEnumDecoder(variants, config));
|
|
303
303
|
}
|
|
304
304
|
function mapCodecHelper(key, value, size, description) {
|
|
305
305
|
if (size === "remainder" && (key.fixedSize === null || value.fixedSize === null)) {
|
|
@@ -311,10 +311,10 @@ function mapCodecHelper(key, value, size, description) {
|
|
|
311
311
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [key.maxSize, value.maxSize])
|
|
312
312
|
};
|
|
313
313
|
}
|
|
314
|
-
function getMapEncoder(key, value,
|
|
315
|
-
const size =
|
|
314
|
+
function getMapEncoder(key, value, config = {}) {
|
|
315
|
+
const size = config.size ?? getU32Encoder();
|
|
316
316
|
return {
|
|
317
|
-
...mapCodecHelper(key, value, size,
|
|
317
|
+
...mapCodecHelper(key, value, size, config.description),
|
|
318
318
|
encode: (map) => {
|
|
319
319
|
if (typeof size === "number") {
|
|
320
320
|
assertValidNumberOfItemsForCodec("map", size, map.size);
|
|
@@ -324,10 +324,10 @@ function getMapEncoder(key, value, options = {}) {
|
|
|
324
324
|
}
|
|
325
325
|
};
|
|
326
326
|
}
|
|
327
|
-
function getMapDecoder(key, value,
|
|
328
|
-
const size =
|
|
327
|
+
function getMapDecoder(key, value, config = {}) {
|
|
328
|
+
const size = config.size ?? getU32Decoder();
|
|
329
329
|
return {
|
|
330
|
-
...mapCodecHelper(key, value, size,
|
|
330
|
+
...mapCodecHelper(key, value, size, config.description),
|
|
331
331
|
decode: (bytes, offset = 0) => {
|
|
332
332
|
const map = /* @__PURE__ */ new Map();
|
|
333
333
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
@@ -351,8 +351,8 @@ function getMapDecoder(key, value, options = {}) {
|
|
|
351
351
|
}
|
|
352
352
|
};
|
|
353
353
|
}
|
|
354
|
-
function getMapCodec(key, value,
|
|
355
|
-
return combineCodec(getMapEncoder(key, value,
|
|
354
|
+
function getMapCodec(key, value, config = {}) {
|
|
355
|
+
return combineCodec(getMapEncoder(key, value, config), getMapDecoder(key, value, config));
|
|
356
356
|
}
|
|
357
357
|
function nullableCodecHelper(item, prefix, fixed, description) {
|
|
358
358
|
let descriptionSuffix = `; ${prefix.description}`;
|
|
@@ -369,11 +369,11 @@ function nullableCodecHelper(item, prefix, fixed, description) {
|
|
|
369
369
|
maxSize: sumCodecSizes([prefix.maxSize, item.maxSize])
|
|
370
370
|
};
|
|
371
371
|
}
|
|
372
|
-
function getNullableEncoder(item,
|
|
373
|
-
const prefix =
|
|
374
|
-
const fixed =
|
|
372
|
+
function getNullableEncoder(item, config = {}) {
|
|
373
|
+
const prefix = config.prefix ?? getU8Encoder();
|
|
374
|
+
const fixed = config.fixed ?? false;
|
|
375
375
|
return {
|
|
376
|
-
...nullableCodecHelper(item, prefix, fixed,
|
|
376
|
+
...nullableCodecHelper(item, prefix, fixed, config.description),
|
|
377
377
|
encode: (option) => {
|
|
378
378
|
const prefixByte = prefix.encode(Number(option !== null));
|
|
379
379
|
let itemBytes = option !== null ? item.encode(option) : new Uint8Array();
|
|
@@ -382,11 +382,11 @@ function getNullableEncoder(item, options = {}) {
|
|
|
382
382
|
}
|
|
383
383
|
};
|
|
384
384
|
}
|
|
385
|
-
function getNullableDecoder(item,
|
|
386
|
-
const prefix =
|
|
387
|
-
const fixed =
|
|
385
|
+
function getNullableDecoder(item, config = {}) {
|
|
386
|
+
const prefix = config.prefix ?? getU8Decoder();
|
|
387
|
+
const fixed = config.fixed ?? false;
|
|
388
388
|
return {
|
|
389
|
-
...nullableCodecHelper(item, prefix, fixed,
|
|
389
|
+
...nullableCodecHelper(item, prefix, fixed, config.description),
|
|
390
390
|
decode: (bytes, offset = 0) => {
|
|
391
391
|
if (bytes.length - offset <= 0) {
|
|
392
392
|
return [null, offset];
|
|
@@ -403,8 +403,8 @@ function getNullableDecoder(item, options = {}) {
|
|
|
403
403
|
}
|
|
404
404
|
};
|
|
405
405
|
}
|
|
406
|
-
function getNullableCodec(item,
|
|
407
|
-
return combineCodec(getNullableEncoder(item,
|
|
406
|
+
function getNullableCodec(item, config = {}) {
|
|
407
|
+
return combineCodec(getNullableEncoder(item, config), getNullableDecoder(item, config));
|
|
408
408
|
}
|
|
409
409
|
function scalarEnumCoderHelper(constructor, prefix, description) {
|
|
410
410
|
const enumKeys = Object.keys(constructor);
|
|
@@ -426,9 +426,9 @@ function scalarEnumCoderHelper(constructor, prefix, description) {
|
|
|
426
426
|
stringValues
|
|
427
427
|
};
|
|
428
428
|
}
|
|
429
|
-
function getScalarEnumEncoder(constructor,
|
|
430
|
-
const prefix =
|
|
431
|
-
const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix,
|
|
429
|
+
function getScalarEnumEncoder(constructor, config = {}) {
|
|
430
|
+
const prefix = config.size ?? getU8Encoder();
|
|
431
|
+
const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix, config.description);
|
|
432
432
|
return {
|
|
433
433
|
description,
|
|
434
434
|
encode: (value) => {
|
|
@@ -450,12 +450,12 @@ function getScalarEnumEncoder(constructor, options = {}) {
|
|
|
450
450
|
maxSize
|
|
451
451
|
};
|
|
452
452
|
}
|
|
453
|
-
function getScalarEnumDecoder(constructor,
|
|
454
|
-
const prefix =
|
|
453
|
+
function getScalarEnumDecoder(constructor, config = {}) {
|
|
454
|
+
const prefix = config.size ?? getU8Decoder();
|
|
455
455
|
const { description, fixedSize, maxSize, minRange, maxRange, isNumericEnum, enumValues } = scalarEnumCoderHelper(
|
|
456
456
|
constructor,
|
|
457
457
|
prefix,
|
|
458
|
-
|
|
458
|
+
config.description
|
|
459
459
|
);
|
|
460
460
|
return {
|
|
461
461
|
decode: (bytes, offset = 0) => {
|
|
@@ -475,8 +475,8 @@ function getScalarEnumDecoder(constructor, options = {}) {
|
|
|
475
475
|
maxSize
|
|
476
476
|
};
|
|
477
477
|
}
|
|
478
|
-
function getScalarEnumCodec(constructor,
|
|
479
|
-
return combineCodec(getScalarEnumEncoder(constructor,
|
|
478
|
+
function getScalarEnumCodec(constructor, config = {}) {
|
|
479
|
+
return combineCodec(getScalarEnumEncoder(constructor, config), getScalarEnumDecoder(constructor, config));
|
|
480
480
|
}
|
|
481
481
|
function setCodecHelper(item, size, description) {
|
|
482
482
|
if (size === "remainder" && item.fixedSize === null) {
|
|
@@ -488,10 +488,10 @@ function setCodecHelper(item, size, description) {
|
|
|
488
488
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
489
489
|
};
|
|
490
490
|
}
|
|
491
|
-
function getSetEncoder(item,
|
|
492
|
-
const size =
|
|
491
|
+
function getSetEncoder(item, config = {}) {
|
|
492
|
+
const size = config.size ?? getU32Encoder();
|
|
493
493
|
return {
|
|
494
|
-
...setCodecHelper(item, size,
|
|
494
|
+
...setCodecHelper(item, size, config.description),
|
|
495
495
|
encode: (set) => {
|
|
496
496
|
if (typeof size === "number" && set.size !== size) {
|
|
497
497
|
assertValidNumberOfItemsForCodec("set", size, set.size);
|
|
@@ -501,10 +501,10 @@ function getSetEncoder(item, options = {}) {
|
|
|
501
501
|
}
|
|
502
502
|
};
|
|
503
503
|
}
|
|
504
|
-
function getSetDecoder(item,
|
|
505
|
-
const size =
|
|
504
|
+
function getSetDecoder(item, config = {}) {
|
|
505
|
+
const size = config.size ?? getU32Decoder();
|
|
506
506
|
return {
|
|
507
|
-
...setCodecHelper(item, size,
|
|
507
|
+
...setCodecHelper(item, size, config.description),
|
|
508
508
|
decode: (bytes, offset = 0) => {
|
|
509
509
|
const set = /* @__PURE__ */ new Set();
|
|
510
510
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
@@ -521,8 +521,8 @@ function getSetDecoder(item, options = {}) {
|
|
|
521
521
|
}
|
|
522
522
|
};
|
|
523
523
|
}
|
|
524
|
-
function getSetCodec(item,
|
|
525
|
-
return combineCodec(getSetEncoder(item,
|
|
524
|
+
function getSetCodec(item, config = {}) {
|
|
525
|
+
return combineCodec(getSetEncoder(item, config), getSetDecoder(item, config));
|
|
526
526
|
}
|
|
527
527
|
function structCodecHelper(fields, description) {
|
|
528
528
|
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
@@ -532,18 +532,18 @@ function structCodecHelper(fields, description) {
|
|
|
532
532
|
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
533
533
|
};
|
|
534
534
|
}
|
|
535
|
-
function getStructEncoder(fields,
|
|
535
|
+
function getStructEncoder(fields, config = {}) {
|
|
536
536
|
return {
|
|
537
|
-
...structCodecHelper(fields,
|
|
537
|
+
...structCodecHelper(fields, config.description),
|
|
538
538
|
encode: (struct) => {
|
|
539
539
|
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
540
540
|
return mergeBytes(fieldBytes);
|
|
541
541
|
}
|
|
542
542
|
};
|
|
543
543
|
}
|
|
544
|
-
function getStructDecoder(fields,
|
|
544
|
+
function getStructDecoder(fields, config = {}) {
|
|
545
545
|
return {
|
|
546
|
-
...structCodecHelper(fields,
|
|
546
|
+
...structCodecHelper(fields, config.description),
|
|
547
547
|
decode: (bytes, offset = 0) => {
|
|
548
548
|
const struct = {};
|
|
549
549
|
fields.forEach(([key, codec]) => {
|
|
@@ -555,8 +555,8 @@ function getStructDecoder(fields, options = {}) {
|
|
|
555
555
|
}
|
|
556
556
|
};
|
|
557
557
|
}
|
|
558
|
-
function getStructCodec(fields,
|
|
559
|
-
return combineCodec(getStructEncoder(fields,
|
|
558
|
+
function getStructCodec(fields, config = {}) {
|
|
559
|
+
return combineCodec(getStructEncoder(fields, config), getStructDecoder(fields, config));
|
|
560
560
|
}
|
|
561
561
|
function tupleCodecHelper(items, description) {
|
|
562
562
|
const itemDescriptions = items.map((item) => item.description).join(", ");
|
|
@@ -566,18 +566,18 @@ function tupleCodecHelper(items, description) {
|
|
|
566
566
|
maxSize: sumCodecSizes(items.map((item) => item.maxSize))
|
|
567
567
|
};
|
|
568
568
|
}
|
|
569
|
-
function getTupleEncoder(items,
|
|
569
|
+
function getTupleEncoder(items, config = {}) {
|
|
570
570
|
return {
|
|
571
|
-
...tupleCodecHelper(items,
|
|
571
|
+
...tupleCodecHelper(items, config.description),
|
|
572
572
|
encode: (value) => {
|
|
573
573
|
assertValidNumberOfItemsForCodec("tuple", items.length, value.length);
|
|
574
574
|
return mergeBytes(items.map((item, index) => item.encode(value[index])));
|
|
575
575
|
}
|
|
576
576
|
};
|
|
577
577
|
}
|
|
578
|
-
function getTupleDecoder(items,
|
|
578
|
+
function getTupleDecoder(items, config = {}) {
|
|
579
579
|
return {
|
|
580
|
-
...tupleCodecHelper(items,
|
|
580
|
+
...tupleCodecHelper(items, config.description),
|
|
581
581
|
decode: (bytes, offset = 0) => {
|
|
582
582
|
const values = [];
|
|
583
583
|
items.forEach((codec) => {
|
|
@@ -589,30 +589,30 @@ function getTupleDecoder(items, options = {}) {
|
|
|
589
589
|
}
|
|
590
590
|
};
|
|
591
591
|
}
|
|
592
|
-
function getTupleCodec(items,
|
|
592
|
+
function getTupleCodec(items, config = {}) {
|
|
593
593
|
return combineCodec(
|
|
594
|
-
getTupleEncoder(items,
|
|
595
|
-
getTupleDecoder(items,
|
|
594
|
+
getTupleEncoder(items, config),
|
|
595
|
+
getTupleDecoder(items, config)
|
|
596
596
|
);
|
|
597
597
|
}
|
|
598
|
-
function getUnitEncoder(
|
|
598
|
+
function getUnitEncoder(config = {}) {
|
|
599
599
|
return {
|
|
600
|
-
description:
|
|
600
|
+
description: config.description ?? "unit",
|
|
601
601
|
encode: () => new Uint8Array(),
|
|
602
602
|
fixedSize: 0,
|
|
603
603
|
maxSize: 0
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
|
-
function getUnitDecoder(
|
|
606
|
+
function getUnitDecoder(config = {}) {
|
|
607
607
|
return {
|
|
608
608
|
decode: (_bytes, offset = 0) => [void 0, offset],
|
|
609
|
-
description:
|
|
609
|
+
description: config.description ?? "unit",
|
|
610
610
|
fixedSize: 0,
|
|
611
611
|
maxSize: 0
|
|
612
612
|
};
|
|
613
613
|
}
|
|
614
|
-
function getUnitCodec(
|
|
615
|
-
return combineCodec(getUnitEncoder(
|
|
614
|
+
function getUnitCodec(config = {}) {
|
|
615
|
+
return combineCodec(getUnitEncoder(config), getUnitDecoder(config));
|
|
616
616
|
}
|
|
617
617
|
|
|
618
618
|
export { assertValidNumberOfItemsForCodec, decodeArrayLikeCodecSize, getArrayCodec, getArrayDecoder, getArrayEncoder, getArrayLikeCodecSizeDescription, getArrayLikeCodecSizeFromChildren, getArrayLikeCodecSizePrefix, getBitArrayCodec, getBitArrayDecoder, getBitArrayEncoder, getBooleanCodec, getBooleanDecoder, getBooleanEncoder, getBytesCodec, getBytesDecoder, getBytesEncoder, getDataEnumCodec, getDataEnumDecoder, getDataEnumEncoder, getMapCodec, getMapDecoder, getMapEncoder, getNullableCodec, getNullableDecoder, getNullableEncoder, getScalarEnumCodec, getScalarEnumDecoder, getScalarEnumEncoder, getSetCodec, getSetDecoder, getSetEncoder, getStructCodec, getStructDecoder, getStructEncoder, getTupleCodec, getTupleDecoder, getTupleEncoder, getUnitCodec, getUnitDecoder, getUnitEncoder };
|