@solana/codecs-data-structures 2.0.0-experimental.e662875 → 2.0.0-experimental.e72afd8
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/dist/index.browser.cjs +94 -94
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +94 -96
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +145 -121
- 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 -96
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +40 -40
- package/dist/types/array.d.ts +9 -9
- package/dist/types/array.d.ts.map +1 -1
- package/dist/types/bit-array.d.ts +9 -9
- package/dist/types/bit-array.d.ts.map +1 -1
- package/dist/types/boolean.d.ts +9 -9
- package/dist/types/boolean.d.ts.map +1 -1
- package/dist/types/bytes.d.ts +9 -9
- package/dist/types/bytes.d.ts.map +1 -1
- package/dist/types/data-enum.d.ts +9 -9
- package/dist/types/data-enum.d.ts.map +1 -1
- package/dist/types/map.d.ts +9 -9
- package/dist/types/map.d.ts.map +1 -1
- package/dist/types/nullable.d.ts +9 -9
- package/dist/types/nullable.d.ts.map +1 -1
- package/dist/types/scalar-enum.d.ts +9 -9
- package/dist/types/scalar-enum.d.ts.map +1 -1
- package/dist/types/set.d.ts +9 -9
- package/dist/types/set.d.ts.map +1 -1
- package/dist/types/struct.d.ts +9 -9
- package/dist/types/struct.d.ts.map +1 -1
- package/dist/types/tuple.d.ts +9 -9
- package/dist/types/tuple.d.ts.map +1 -1
- package/dist/types/unit.d.ts +9 -9
- package/dist/types/unit.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.browser.cjs
CHANGED
|
@@ -72,10 +72,10 @@ function arrayCodecHelper(item, size, description) {
|
|
|
72
72
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
function getArrayEncoder(item,
|
|
76
|
-
const size =
|
|
75
|
+
function getArrayEncoder(item, config = {}) {
|
|
76
|
+
const size = config.size ?? codecsNumbers.getU32Encoder();
|
|
77
77
|
return {
|
|
78
|
-
...arrayCodecHelper(item, size,
|
|
78
|
+
...arrayCodecHelper(item, size, config.description),
|
|
79
79
|
encode: (value) => {
|
|
80
80
|
if (typeof size === "number") {
|
|
81
81
|
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
@@ -84,10 +84,10 @@ function getArrayEncoder(item, options = {}) {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function getArrayDecoder(item,
|
|
88
|
-
const size =
|
|
87
|
+
function getArrayDecoder(item, config = {}) {
|
|
88
|
+
const size = config.size ?? codecsNumbers.getU32Decoder();
|
|
89
89
|
return {
|
|
90
|
-
...arrayCodecHelper(item, size,
|
|
90
|
+
...arrayCodecHelper(item, size, config.description),
|
|
91
91
|
decode: (bytes, offset = 0) => {
|
|
92
92
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
93
93
|
return [[], offset];
|
|
@@ -104,15 +104,15 @@ function getArrayDecoder(item, options = {}) {
|
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
|
-
function getArrayCodec(item,
|
|
108
|
-
return codecsCore.combineCodec(getArrayEncoder(item,
|
|
107
|
+
function getArrayCodec(item, config = {}) {
|
|
108
|
+
return codecsCore.combineCodec(getArrayEncoder(item, config), getArrayDecoder(item, config));
|
|
109
109
|
}
|
|
110
|
-
var getBitArrayEncoder = (size,
|
|
111
|
-
const
|
|
112
|
-
const backward =
|
|
110
|
+
var getBitArrayEncoder = (size, config = {}) => {
|
|
111
|
+
const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
|
|
112
|
+
const backward = parsedConfig.backward ?? false;
|
|
113
113
|
const backwardSuffix = backward ? "; backward" : "";
|
|
114
114
|
return {
|
|
115
|
-
description:
|
|
115
|
+
description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
|
|
116
116
|
encode(value) {
|
|
117
117
|
const bytes = [];
|
|
118
118
|
for (let i = 0; i < size; i += 1) {
|
|
@@ -133,9 +133,9 @@ var getBitArrayEncoder = (size, options = {}) => {
|
|
|
133
133
|
maxSize: size
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
|
-
var getBitArrayDecoder = (size,
|
|
137
|
-
const
|
|
138
|
-
const backward =
|
|
136
|
+
var getBitArrayDecoder = (size, config = {}) => {
|
|
137
|
+
const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
|
|
138
|
+
const backward = parsedConfig.backward ?? false;
|
|
139
139
|
const backwardSuffix = backward ? "; backward" : "";
|
|
140
140
|
return {
|
|
141
141
|
decode(bytes, offset = 0) {
|
|
@@ -156,24 +156,24 @@ var getBitArrayDecoder = (size, options = {}) => {
|
|
|
156
156
|
});
|
|
157
157
|
return [booleans, offset + size];
|
|
158
158
|
},
|
|
159
|
-
description:
|
|
159
|
+
description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
|
|
160
160
|
fixedSize: size,
|
|
161
161
|
maxSize: size
|
|
162
162
|
};
|
|
163
163
|
};
|
|
164
|
-
var getBitArrayCodec = (size,
|
|
165
|
-
function getBooleanEncoder(
|
|
166
|
-
const size =
|
|
164
|
+
var getBitArrayCodec = (size, config = {}) => codecsCore.combineCodec(getBitArrayEncoder(size, config), getBitArrayDecoder(size, config));
|
|
165
|
+
function getBooleanEncoder(config = {}) {
|
|
166
|
+
const size = config.size ?? codecsNumbers.getU8Encoder();
|
|
167
167
|
codecsCore.assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
|
|
168
168
|
return {
|
|
169
|
-
description:
|
|
169
|
+
description: config.description ?? `bool(${size.description})`,
|
|
170
170
|
encode: (value) => size.encode(value ? 1 : 0),
|
|
171
171
|
fixedSize: size.fixedSize,
|
|
172
172
|
maxSize: size.fixedSize
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
|
-
function getBooleanDecoder(
|
|
176
|
-
const size =
|
|
175
|
+
function getBooleanDecoder(config = {}) {
|
|
176
|
+
const size = config.size ?? codecsNumbers.getU8Decoder();
|
|
177
177
|
codecsCore.assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
|
|
178
178
|
return {
|
|
179
179
|
decode: (bytes, offset = 0) => {
|
|
@@ -181,18 +181,18 @@ function getBooleanDecoder(options = {}) {
|
|
|
181
181
|
const [value, vOffset] = size.decode(bytes, offset);
|
|
182
182
|
return [value === 1, vOffset];
|
|
183
183
|
},
|
|
184
|
-
description:
|
|
184
|
+
description: config.description ?? `bool(${size.description})`,
|
|
185
185
|
fixedSize: size.fixedSize,
|
|
186
186
|
maxSize: size.fixedSize
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
-
function getBooleanCodec(
|
|
190
|
-
return codecsCore.combineCodec(getBooleanEncoder(
|
|
189
|
+
function getBooleanCodec(config = {}) {
|
|
190
|
+
return codecsCore.combineCodec(getBooleanEncoder(config), getBooleanDecoder(config));
|
|
191
191
|
}
|
|
192
|
-
function getBytesEncoder(
|
|
193
|
-
const size =
|
|
192
|
+
function getBytesEncoder(config = {}) {
|
|
193
|
+
const size = config.size ?? "variable";
|
|
194
194
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
195
|
-
const description =
|
|
195
|
+
const description = config.description ?? `bytes(${sizeDescription})`;
|
|
196
196
|
const byteEncoder = {
|
|
197
197
|
description,
|
|
198
198
|
encode: (value) => value,
|
|
@@ -214,10 +214,10 @@ function getBytesEncoder(options = {}) {
|
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
}
|
|
217
|
-
function getBytesDecoder(
|
|
218
|
-
const size =
|
|
217
|
+
function getBytesDecoder(config = {}) {
|
|
218
|
+
const size = config.size ?? "variable";
|
|
219
219
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
220
|
-
const description =
|
|
220
|
+
const description = config.description ?? `bytes(${sizeDescription})`;
|
|
221
221
|
const byteDecoder = {
|
|
222
222
|
decode: (bytes, offset = 0) => {
|
|
223
223
|
const slice = bytes.slice(offset);
|
|
@@ -248,8 +248,8 @@ function getBytesDecoder(options = {}) {
|
|
|
248
248
|
}
|
|
249
249
|
};
|
|
250
250
|
}
|
|
251
|
-
function getBytesCodec(
|
|
252
|
-
return codecsCore.combineCodec(getBytesEncoder(
|
|
251
|
+
function getBytesCodec(config = {}) {
|
|
252
|
+
return codecsCore.combineCodec(getBytesEncoder(config), getBytesDecoder(config));
|
|
253
253
|
}
|
|
254
254
|
function dataEnumCodecHelper(variants, prefix, description) {
|
|
255
255
|
const fieldDescriptions = variants.map(([name, codec]) => `${String(name)}${codec ? `: ${codec.description}` : ""}`).join(", ");
|
|
@@ -262,10 +262,10 @@ function dataEnumCodecHelper(variants, prefix, description) {
|
|
|
262
262
|
maxSize: variants.length === 0 ? prefix.maxSize : sumCodecSizes([prefix.maxSize, maxVariantSize])
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
function getDataEnumEncoder(variants,
|
|
266
|
-
const prefix =
|
|
265
|
+
function getDataEnumEncoder(variants, config = {}) {
|
|
266
|
+
const prefix = config.size ?? codecsNumbers.getU8Encoder();
|
|
267
267
|
return {
|
|
268
|
-
...dataEnumCodecHelper(variants, prefix,
|
|
268
|
+
...dataEnumCodecHelper(variants, prefix, config.description),
|
|
269
269
|
encode: (variant) => {
|
|
270
270
|
const discriminator = variants.findIndex(([key]) => variant.__kind === key);
|
|
271
271
|
if (discriminator < 0) {
|
|
@@ -280,10 +280,10 @@ function getDataEnumEncoder(variants, options = {}) {
|
|
|
280
280
|
}
|
|
281
281
|
};
|
|
282
282
|
}
|
|
283
|
-
function getDataEnumDecoder(variants,
|
|
284
|
-
const prefix =
|
|
283
|
+
function getDataEnumDecoder(variants, config = {}) {
|
|
284
|
+
const prefix = config.size ?? codecsNumbers.getU8Decoder();
|
|
285
285
|
return {
|
|
286
|
-
...dataEnumCodecHelper(variants, prefix,
|
|
286
|
+
...dataEnumCodecHelper(variants, prefix, config.description),
|
|
287
287
|
decode: (bytes, offset = 0) => {
|
|
288
288
|
codecsCore.assertByteArrayIsNotEmptyForCodec("dataEnum", bytes, offset);
|
|
289
289
|
const [discriminator, dOffset] = prefix.decode(bytes, offset);
|
|
@@ -300,8 +300,8 @@ function getDataEnumDecoder(variants, options = {}) {
|
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
302
|
}
|
|
303
|
-
function getDataEnumCodec(variants,
|
|
304
|
-
return codecsCore.combineCodec(getDataEnumEncoder(variants,
|
|
303
|
+
function getDataEnumCodec(variants, config = {}) {
|
|
304
|
+
return codecsCore.combineCodec(getDataEnumEncoder(variants, config), getDataEnumDecoder(variants, config));
|
|
305
305
|
}
|
|
306
306
|
function mapCodecHelper(key, value, size, description) {
|
|
307
307
|
if (size === "remainder" && (key.fixedSize === null || value.fixedSize === null)) {
|
|
@@ -313,10 +313,10 @@ function mapCodecHelper(key, value, size, description) {
|
|
|
313
313
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [key.maxSize, value.maxSize])
|
|
314
314
|
};
|
|
315
315
|
}
|
|
316
|
-
function getMapEncoder(key, value,
|
|
317
|
-
const size =
|
|
316
|
+
function getMapEncoder(key, value, config = {}) {
|
|
317
|
+
const size = config.size ?? codecsNumbers.getU32Encoder();
|
|
318
318
|
return {
|
|
319
|
-
...mapCodecHelper(key, value, size,
|
|
319
|
+
...mapCodecHelper(key, value, size, config.description),
|
|
320
320
|
encode: (map) => {
|
|
321
321
|
if (typeof size === "number") {
|
|
322
322
|
assertValidNumberOfItemsForCodec("map", size, map.size);
|
|
@@ -326,10 +326,10 @@ function getMapEncoder(key, value, options = {}) {
|
|
|
326
326
|
}
|
|
327
327
|
};
|
|
328
328
|
}
|
|
329
|
-
function getMapDecoder(key, value,
|
|
330
|
-
const size =
|
|
329
|
+
function getMapDecoder(key, value, config = {}) {
|
|
330
|
+
const size = config.size ?? codecsNumbers.getU32Decoder();
|
|
331
331
|
return {
|
|
332
|
-
...mapCodecHelper(key, value, size,
|
|
332
|
+
...mapCodecHelper(key, value, size, config.description),
|
|
333
333
|
decode: (bytes, offset = 0) => {
|
|
334
334
|
const map = /* @__PURE__ */ new Map();
|
|
335
335
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
@@ -353,8 +353,8 @@ function getMapDecoder(key, value, options = {}) {
|
|
|
353
353
|
}
|
|
354
354
|
};
|
|
355
355
|
}
|
|
356
|
-
function getMapCodec(key, value,
|
|
357
|
-
return codecsCore.combineCodec(getMapEncoder(key, value,
|
|
356
|
+
function getMapCodec(key, value, config = {}) {
|
|
357
|
+
return codecsCore.combineCodec(getMapEncoder(key, value, config), getMapDecoder(key, value, config));
|
|
358
358
|
}
|
|
359
359
|
function nullableCodecHelper(item, prefix, fixed, description) {
|
|
360
360
|
let descriptionSuffix = `; ${prefix.description}`;
|
|
@@ -371,11 +371,11 @@ function nullableCodecHelper(item, prefix, fixed, description) {
|
|
|
371
371
|
maxSize: sumCodecSizes([prefix.maxSize, item.maxSize])
|
|
372
372
|
};
|
|
373
373
|
}
|
|
374
|
-
function getNullableEncoder(item,
|
|
375
|
-
const prefix =
|
|
376
|
-
const fixed =
|
|
374
|
+
function getNullableEncoder(item, config = {}) {
|
|
375
|
+
const prefix = config.prefix ?? codecsNumbers.getU8Encoder();
|
|
376
|
+
const fixed = config.fixed ?? false;
|
|
377
377
|
return {
|
|
378
|
-
...nullableCodecHelper(item, prefix, fixed,
|
|
378
|
+
...nullableCodecHelper(item, prefix, fixed, config.description),
|
|
379
379
|
encode: (option) => {
|
|
380
380
|
const prefixByte = prefix.encode(Number(option !== null));
|
|
381
381
|
let itemBytes = option !== null ? item.encode(option) : new Uint8Array();
|
|
@@ -384,11 +384,11 @@ function getNullableEncoder(item, options = {}) {
|
|
|
384
384
|
}
|
|
385
385
|
};
|
|
386
386
|
}
|
|
387
|
-
function getNullableDecoder(item,
|
|
388
|
-
const prefix =
|
|
389
|
-
const fixed =
|
|
387
|
+
function getNullableDecoder(item, config = {}) {
|
|
388
|
+
const prefix = config.prefix ?? codecsNumbers.getU8Decoder();
|
|
389
|
+
const fixed = config.fixed ?? false;
|
|
390
390
|
return {
|
|
391
|
-
...nullableCodecHelper(item, prefix, fixed,
|
|
391
|
+
...nullableCodecHelper(item, prefix, fixed, config.description),
|
|
392
392
|
decode: (bytes, offset = 0) => {
|
|
393
393
|
if (bytes.length - offset <= 0) {
|
|
394
394
|
return [null, offset];
|
|
@@ -405,8 +405,8 @@ function getNullableDecoder(item, options = {}) {
|
|
|
405
405
|
}
|
|
406
406
|
};
|
|
407
407
|
}
|
|
408
|
-
function getNullableCodec(item,
|
|
409
|
-
return codecsCore.combineCodec(getNullableEncoder(item,
|
|
408
|
+
function getNullableCodec(item, config = {}) {
|
|
409
|
+
return codecsCore.combineCodec(getNullableEncoder(item, config), getNullableDecoder(item, config));
|
|
410
410
|
}
|
|
411
411
|
function scalarEnumCoderHelper(constructor, prefix, description) {
|
|
412
412
|
const enumKeys = Object.keys(constructor);
|
|
@@ -428,9 +428,9 @@ function scalarEnumCoderHelper(constructor, prefix, description) {
|
|
|
428
428
|
stringValues
|
|
429
429
|
};
|
|
430
430
|
}
|
|
431
|
-
function getScalarEnumEncoder(constructor,
|
|
432
|
-
const prefix =
|
|
433
|
-
const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix,
|
|
431
|
+
function getScalarEnumEncoder(constructor, config = {}) {
|
|
432
|
+
const prefix = config.size ?? codecsNumbers.getU8Encoder();
|
|
433
|
+
const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix, config.description);
|
|
434
434
|
return {
|
|
435
435
|
description,
|
|
436
436
|
encode: (value) => {
|
|
@@ -452,12 +452,12 @@ function getScalarEnumEncoder(constructor, options = {}) {
|
|
|
452
452
|
maxSize
|
|
453
453
|
};
|
|
454
454
|
}
|
|
455
|
-
function getScalarEnumDecoder(constructor,
|
|
456
|
-
const prefix =
|
|
455
|
+
function getScalarEnumDecoder(constructor, config = {}) {
|
|
456
|
+
const prefix = config.size ?? codecsNumbers.getU8Decoder();
|
|
457
457
|
const { description, fixedSize, maxSize, minRange, maxRange, isNumericEnum, enumValues } = scalarEnumCoderHelper(
|
|
458
458
|
constructor,
|
|
459
459
|
prefix,
|
|
460
|
-
|
|
460
|
+
config.description
|
|
461
461
|
);
|
|
462
462
|
return {
|
|
463
463
|
decode: (bytes, offset = 0) => {
|
|
@@ -477,8 +477,8 @@ function getScalarEnumDecoder(constructor, options = {}) {
|
|
|
477
477
|
maxSize
|
|
478
478
|
};
|
|
479
479
|
}
|
|
480
|
-
function getScalarEnumCodec(constructor,
|
|
481
|
-
return codecsCore.combineCodec(getScalarEnumEncoder(constructor,
|
|
480
|
+
function getScalarEnumCodec(constructor, config = {}) {
|
|
481
|
+
return codecsCore.combineCodec(getScalarEnumEncoder(constructor, config), getScalarEnumDecoder(constructor, config));
|
|
482
482
|
}
|
|
483
483
|
function setCodecHelper(item, size, description) {
|
|
484
484
|
if (size === "remainder" && item.fixedSize === null) {
|
|
@@ -490,10 +490,10 @@ function setCodecHelper(item, size, description) {
|
|
|
490
490
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
491
491
|
};
|
|
492
492
|
}
|
|
493
|
-
function getSetEncoder(item,
|
|
494
|
-
const size =
|
|
493
|
+
function getSetEncoder(item, config = {}) {
|
|
494
|
+
const size = config.size ?? codecsNumbers.getU32Encoder();
|
|
495
495
|
return {
|
|
496
|
-
...setCodecHelper(item, size,
|
|
496
|
+
...setCodecHelper(item, size, config.description),
|
|
497
497
|
encode: (set) => {
|
|
498
498
|
if (typeof size === "number" && set.size !== size) {
|
|
499
499
|
assertValidNumberOfItemsForCodec("set", size, set.size);
|
|
@@ -503,10 +503,10 @@ function getSetEncoder(item, options = {}) {
|
|
|
503
503
|
}
|
|
504
504
|
};
|
|
505
505
|
}
|
|
506
|
-
function getSetDecoder(item,
|
|
507
|
-
const size =
|
|
506
|
+
function getSetDecoder(item, config = {}) {
|
|
507
|
+
const size = config.size ?? codecsNumbers.getU32Decoder();
|
|
508
508
|
return {
|
|
509
|
-
...setCodecHelper(item, size,
|
|
509
|
+
...setCodecHelper(item, size, config.description),
|
|
510
510
|
decode: (bytes, offset = 0) => {
|
|
511
511
|
const set = /* @__PURE__ */ new Set();
|
|
512
512
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
@@ -523,8 +523,8 @@ function getSetDecoder(item, options = {}) {
|
|
|
523
523
|
}
|
|
524
524
|
};
|
|
525
525
|
}
|
|
526
|
-
function getSetCodec(item,
|
|
527
|
-
return codecsCore.combineCodec(getSetEncoder(item,
|
|
526
|
+
function getSetCodec(item, config = {}) {
|
|
527
|
+
return codecsCore.combineCodec(getSetEncoder(item, config), getSetDecoder(item, config));
|
|
528
528
|
}
|
|
529
529
|
function structCodecHelper(fields, description) {
|
|
530
530
|
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
@@ -534,18 +534,18 @@ function structCodecHelper(fields, description) {
|
|
|
534
534
|
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
535
535
|
};
|
|
536
536
|
}
|
|
537
|
-
function getStructEncoder(fields,
|
|
537
|
+
function getStructEncoder(fields, config = {}) {
|
|
538
538
|
return {
|
|
539
|
-
...structCodecHelper(fields,
|
|
539
|
+
...structCodecHelper(fields, config.description),
|
|
540
540
|
encode: (struct) => {
|
|
541
541
|
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
542
542
|
return codecsCore.mergeBytes(fieldBytes);
|
|
543
543
|
}
|
|
544
544
|
};
|
|
545
545
|
}
|
|
546
|
-
function getStructDecoder(fields,
|
|
546
|
+
function getStructDecoder(fields, config = {}) {
|
|
547
547
|
return {
|
|
548
|
-
...structCodecHelper(fields,
|
|
548
|
+
...structCodecHelper(fields, config.description),
|
|
549
549
|
decode: (bytes, offset = 0) => {
|
|
550
550
|
const struct = {};
|
|
551
551
|
fields.forEach(([key, codec]) => {
|
|
@@ -557,8 +557,8 @@ function getStructDecoder(fields, options = {}) {
|
|
|
557
557
|
}
|
|
558
558
|
};
|
|
559
559
|
}
|
|
560
|
-
function getStructCodec(fields,
|
|
561
|
-
return codecsCore.combineCodec(getStructEncoder(fields,
|
|
560
|
+
function getStructCodec(fields, config = {}) {
|
|
561
|
+
return codecsCore.combineCodec(getStructEncoder(fields, config), getStructDecoder(fields, config));
|
|
562
562
|
}
|
|
563
563
|
function tupleCodecHelper(items, description) {
|
|
564
564
|
const itemDescriptions = items.map((item) => item.description).join(", ");
|
|
@@ -568,18 +568,18 @@ function tupleCodecHelper(items, description) {
|
|
|
568
568
|
maxSize: sumCodecSizes(items.map((item) => item.maxSize))
|
|
569
569
|
};
|
|
570
570
|
}
|
|
571
|
-
function getTupleEncoder(items,
|
|
571
|
+
function getTupleEncoder(items, config = {}) {
|
|
572
572
|
return {
|
|
573
|
-
...tupleCodecHelper(items,
|
|
573
|
+
...tupleCodecHelper(items, config.description),
|
|
574
574
|
encode: (value) => {
|
|
575
575
|
assertValidNumberOfItemsForCodec("tuple", items.length, value.length);
|
|
576
576
|
return codecsCore.mergeBytes(items.map((item, index) => item.encode(value[index])));
|
|
577
577
|
}
|
|
578
578
|
};
|
|
579
579
|
}
|
|
580
|
-
function getTupleDecoder(items,
|
|
580
|
+
function getTupleDecoder(items, config = {}) {
|
|
581
581
|
return {
|
|
582
|
-
...tupleCodecHelper(items,
|
|
582
|
+
...tupleCodecHelper(items, config.description),
|
|
583
583
|
decode: (bytes, offset = 0) => {
|
|
584
584
|
const values = [];
|
|
585
585
|
items.forEach((codec) => {
|
|
@@ -591,30 +591,30 @@ function getTupleDecoder(items, options = {}) {
|
|
|
591
591
|
}
|
|
592
592
|
};
|
|
593
593
|
}
|
|
594
|
-
function getTupleCodec(items,
|
|
594
|
+
function getTupleCodec(items, config = {}) {
|
|
595
595
|
return codecsCore.combineCodec(
|
|
596
|
-
getTupleEncoder(items,
|
|
597
|
-
getTupleDecoder(items,
|
|
596
|
+
getTupleEncoder(items, config),
|
|
597
|
+
getTupleDecoder(items, config)
|
|
598
598
|
);
|
|
599
599
|
}
|
|
600
|
-
function getUnitEncoder(
|
|
600
|
+
function getUnitEncoder(config = {}) {
|
|
601
601
|
return {
|
|
602
|
-
description:
|
|
602
|
+
description: config.description ?? "unit",
|
|
603
603
|
encode: () => new Uint8Array(),
|
|
604
604
|
fixedSize: 0,
|
|
605
605
|
maxSize: 0
|
|
606
606
|
};
|
|
607
607
|
}
|
|
608
|
-
function getUnitDecoder(
|
|
608
|
+
function getUnitDecoder(config = {}) {
|
|
609
609
|
return {
|
|
610
610
|
decode: (_bytes, offset = 0) => [void 0, offset],
|
|
611
|
-
description:
|
|
611
|
+
description: config.description ?? "unit",
|
|
612
612
|
fixedSize: 0,
|
|
613
613
|
maxSize: 0
|
|
614
614
|
};
|
|
615
615
|
}
|
|
616
|
-
function getUnitCodec(
|
|
617
|
-
return codecsCore.combineCodec(getUnitEncoder(
|
|
616
|
+
function getUnitCodec(config = {}) {
|
|
617
|
+
return codecsCore.combineCodec(getUnitEncoder(config), getUnitDecoder(config));
|
|
618
618
|
}
|
|
619
619
|
|
|
620
620
|
exports.assertValidNumberOfItemsForCodec = assertValidNumberOfItemsForCodec;
|