@solana/codecs-core 2.0.0-canary-20240731173615

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.
Files changed (41) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +665 -0
  3. package/dist/index.browser.cjs +504 -0
  4. package/dist/index.browser.cjs.map +1 -0
  5. package/dist/index.browser.mjs +460 -0
  6. package/dist/index.browser.mjs.map +1 -0
  7. package/dist/index.native.mjs +460 -0
  8. package/dist/index.native.mjs.map +1 -0
  9. package/dist/index.node.cjs +504 -0
  10. package/dist/index.node.cjs.map +1 -0
  11. package/dist/index.node.mjs +460 -0
  12. package/dist/index.node.mjs.map +1 -0
  13. package/dist/types/add-codec-sentinel.d.ts +27 -0
  14. package/dist/types/add-codec-sentinel.d.ts.map +1 -0
  15. package/dist/types/add-codec-size-prefix.d.ts +24 -0
  16. package/dist/types/add-codec-size-prefix.d.ts.map +1 -0
  17. package/dist/types/assertions.d.ts +17 -0
  18. package/dist/types/assertions.d.ts.map +1 -0
  19. package/dist/types/bytes.d.ts +23 -0
  20. package/dist/types/bytes.d.ts.map +1 -0
  21. package/dist/types/codec.d.ts +123 -0
  22. package/dist/types/codec.d.ts.map +1 -0
  23. package/dist/types/combine-codec.d.ts +10 -0
  24. package/dist/types/combine-codec.d.ts.map +1 -0
  25. package/dist/types/fix-codec-size.d.ts +23 -0
  26. package/dist/types/fix-codec-size.d.ts.map +1 -0
  27. package/dist/types/index.d.ts +14 -0
  28. package/dist/types/index.d.ts.map +1 -0
  29. package/dist/types/offset-codec.d.ts +38 -0
  30. package/dist/types/offset-codec.d.ts.map +1 -0
  31. package/dist/types/pad-codec.d.ts +30 -0
  32. package/dist/types/pad-codec.d.ts.map +1 -0
  33. package/dist/types/readonly-uint8array.d.ts +6 -0
  34. package/dist/types/readonly-uint8array.d.ts.map +1 -0
  35. package/dist/types/resize-codec.d.ts +21 -0
  36. package/dist/types/resize-codec.d.ts.map +1 -0
  37. package/dist/types/reverse-codec.d.ts +14 -0
  38. package/dist/types/reverse-codec.d.ts.map +1 -0
  39. package/dist/types/transform-codec.d.ts +24 -0
  40. package/dist/types/transform-codec.d.ts.map +1 -0
  41. package/package.json +82 -0
@@ -0,0 +1,504 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@solana/errors');
4
+
5
+ // src/add-codec-sentinel.ts
6
+
7
+ // src/bytes.ts
8
+ var mergeBytes = (byteArrays) => {
9
+ const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
10
+ if (nonEmptyByteArrays.length === 0) {
11
+ return byteArrays.length ? byteArrays[0] : new Uint8Array();
12
+ }
13
+ if (nonEmptyByteArrays.length === 1) {
14
+ return nonEmptyByteArrays[0];
15
+ }
16
+ const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
17
+ const result = new Uint8Array(totalLength);
18
+ let offset = 0;
19
+ nonEmptyByteArrays.forEach((arr) => {
20
+ result.set(arr, offset);
21
+ offset += arr.length;
22
+ });
23
+ return result;
24
+ };
25
+ var padBytes = (bytes, length) => {
26
+ if (bytes.length >= length) return bytes;
27
+ const paddedBytes = new Uint8Array(length).fill(0);
28
+ paddedBytes.set(bytes);
29
+ return paddedBytes;
30
+ };
31
+ var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
32
+ function containsBytes(data, bytes, offset) {
33
+ const slice = offset === 0 && data.length === bytes.length ? data : data.slice(offset, offset + bytes.length);
34
+ if (slice.length !== bytes.length) return false;
35
+ return bytes.every((b, i) => b === slice[i]);
36
+ }
37
+ function getEncodedSize(value, encoder) {
38
+ return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
39
+ }
40
+ function createEncoder(encoder) {
41
+ return Object.freeze({
42
+ ...encoder,
43
+ encode: (value) => {
44
+ const bytes = new Uint8Array(getEncodedSize(value, encoder));
45
+ encoder.write(value, bytes, 0);
46
+ return bytes;
47
+ }
48
+ });
49
+ }
50
+ function createDecoder(decoder) {
51
+ return Object.freeze({
52
+ ...decoder,
53
+ decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
54
+ });
55
+ }
56
+ function createCodec(codec) {
57
+ return Object.freeze({
58
+ ...codec,
59
+ decode: (bytes, offset = 0) => codec.read(bytes, offset)[0],
60
+ encode: (value) => {
61
+ const bytes = new Uint8Array(getEncodedSize(value, codec));
62
+ codec.write(value, bytes, 0);
63
+ return bytes;
64
+ }
65
+ });
66
+ }
67
+ function isFixedSize(codec) {
68
+ return "fixedSize" in codec && typeof codec.fixedSize === "number";
69
+ }
70
+ function assertIsFixedSize(codec) {
71
+ if (!isFixedSize(codec)) {
72
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__EXPECTED_FIXED_LENGTH);
73
+ }
74
+ }
75
+ function isVariableSize(codec) {
76
+ return !isFixedSize(codec);
77
+ }
78
+ function assertIsVariableSize(codec) {
79
+ if (!isVariableSize(codec)) {
80
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__EXPECTED_VARIABLE_LENGTH);
81
+ }
82
+ }
83
+ function combineCodec(encoder, decoder) {
84
+ if (isFixedSize(encoder) !== isFixedSize(decoder)) {
85
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH);
86
+ }
87
+ if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
88
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH, {
89
+ decoderFixedSize: decoder.fixedSize,
90
+ encoderFixedSize: encoder.fixedSize
91
+ });
92
+ }
93
+ if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
94
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH, {
95
+ decoderMaxSize: decoder.maxSize,
96
+ encoderMaxSize: encoder.maxSize
97
+ });
98
+ }
99
+ return {
100
+ ...decoder,
101
+ ...encoder,
102
+ decode: decoder.decode,
103
+ encode: encoder.encode,
104
+ read: decoder.read,
105
+ write: encoder.write
106
+ };
107
+ }
108
+
109
+ // src/add-codec-sentinel.ts
110
+ function addEncoderSentinel(encoder, sentinel) {
111
+ const write = (value, bytes, offset) => {
112
+ const encoderBytes = encoder.encode(value);
113
+ if (findSentinelIndex(encoderBytes, sentinel) >= 0) {
114
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__ENCODED_BYTES_MUST_NOT_INCLUDE_SENTINEL, {
115
+ encodedBytes: encoderBytes,
116
+ hexEncodedBytes: hexBytes(encoderBytes),
117
+ hexSentinel: hexBytes(sentinel),
118
+ sentinel
119
+ });
120
+ }
121
+ bytes.set(encoderBytes, offset);
122
+ offset += encoderBytes.length;
123
+ bytes.set(sentinel, offset);
124
+ offset += sentinel.length;
125
+ return offset;
126
+ };
127
+ if (isFixedSize(encoder)) {
128
+ return createEncoder({ ...encoder, fixedSize: encoder.fixedSize + sentinel.length, write });
129
+ }
130
+ return createEncoder({
131
+ ...encoder,
132
+ ...encoder.maxSize != null ? { maxSize: encoder.maxSize + sentinel.length } : {},
133
+ getSizeFromValue: (value) => encoder.getSizeFromValue(value) + sentinel.length,
134
+ write
135
+ });
136
+ }
137
+ function addDecoderSentinel(decoder, sentinel) {
138
+ const read = (bytes, offset) => {
139
+ const candidateBytes = offset === 0 ? bytes : bytes.slice(offset);
140
+ const sentinelIndex = findSentinelIndex(candidateBytes, sentinel);
141
+ if (sentinelIndex === -1) {
142
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__SENTINEL_MISSING_IN_DECODED_BYTES, {
143
+ decodedBytes: candidateBytes,
144
+ hexDecodedBytes: hexBytes(candidateBytes),
145
+ hexSentinel: hexBytes(sentinel),
146
+ sentinel
147
+ });
148
+ }
149
+ const preSentinelBytes = candidateBytes.slice(0, sentinelIndex);
150
+ return [decoder.decode(preSentinelBytes), offset + preSentinelBytes.length + sentinel.length];
151
+ };
152
+ if (isFixedSize(decoder)) {
153
+ return createDecoder({ ...decoder, fixedSize: decoder.fixedSize + sentinel.length, read });
154
+ }
155
+ return createDecoder({
156
+ ...decoder,
157
+ ...decoder.maxSize != null ? { maxSize: decoder.maxSize + sentinel.length } : {},
158
+ read
159
+ });
160
+ }
161
+ function addCodecSentinel(codec, sentinel) {
162
+ return combineCodec(addEncoderSentinel(codec, sentinel), addDecoderSentinel(codec, sentinel));
163
+ }
164
+ function findSentinelIndex(bytes, sentinel) {
165
+ return bytes.findIndex((byte, index, arr) => {
166
+ if (sentinel.length === 1) return byte === sentinel[0];
167
+ return containsBytes(arr, sentinel, index);
168
+ });
169
+ }
170
+ function hexBytes(bytes) {
171
+ return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
172
+ }
173
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
174
+ if (bytes.length - offset <= 0) {
175
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY, {
176
+ codecDescription
177
+ });
178
+ }
179
+ }
180
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
181
+ const bytesLength = bytes.length - offset;
182
+ if (bytesLength < expected) {
183
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH, {
184
+ bytesLength,
185
+ codecDescription,
186
+ expected
187
+ });
188
+ }
189
+ }
190
+ function assertByteArrayOffsetIsNotOutOfRange(codecDescription, offset, bytesLength) {
191
+ if (offset < 0 || offset > bytesLength) {
192
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__OFFSET_OUT_OF_RANGE, {
193
+ bytesLength,
194
+ codecDescription,
195
+ offset
196
+ });
197
+ }
198
+ }
199
+
200
+ // src/add-codec-size-prefix.ts
201
+ function addEncoderSizePrefix(encoder, prefix) {
202
+ const write = (value, bytes, offset) => {
203
+ const encoderBytes = encoder.encode(value);
204
+ offset = prefix.write(encoderBytes.length, bytes, offset);
205
+ bytes.set(encoderBytes, offset);
206
+ return offset + encoderBytes.length;
207
+ };
208
+ if (isFixedSize(prefix) && isFixedSize(encoder)) {
209
+ return createEncoder({ ...encoder, fixedSize: prefix.fixedSize + encoder.fixedSize, write });
210
+ }
211
+ const prefixMaxSize = isFixedSize(prefix) ? prefix.fixedSize : prefix.maxSize ?? null;
212
+ const encoderMaxSize = isFixedSize(encoder) ? encoder.fixedSize : encoder.maxSize ?? null;
213
+ const maxSize = prefixMaxSize !== null && encoderMaxSize !== null ? prefixMaxSize + encoderMaxSize : null;
214
+ return createEncoder({
215
+ ...encoder,
216
+ ...maxSize !== null ? { maxSize } : {},
217
+ getSizeFromValue: (value) => {
218
+ const encoderSize = getEncodedSize(value, encoder);
219
+ return getEncodedSize(encoderSize, prefix) + encoderSize;
220
+ },
221
+ write
222
+ });
223
+ }
224
+ function addDecoderSizePrefix(decoder, prefix) {
225
+ const read = (bytes, offset) => {
226
+ const [bigintSize, decoderOffset] = prefix.read(bytes, offset);
227
+ const size = Number(bigintSize);
228
+ offset = decoderOffset;
229
+ if (offset > 0 || bytes.length > size) {
230
+ bytes = bytes.slice(offset, offset + size);
231
+ }
232
+ assertByteArrayHasEnoughBytesForCodec("addDecoderSizePrefix", size, bytes);
233
+ return [decoder.decode(bytes), offset + size];
234
+ };
235
+ if (isFixedSize(prefix) && isFixedSize(decoder)) {
236
+ return createDecoder({ ...decoder, fixedSize: prefix.fixedSize + decoder.fixedSize, read });
237
+ }
238
+ const prefixMaxSize = isFixedSize(prefix) ? prefix.fixedSize : prefix.maxSize ?? null;
239
+ const decoderMaxSize = isFixedSize(decoder) ? decoder.fixedSize : decoder.maxSize ?? null;
240
+ const maxSize = prefixMaxSize !== null && decoderMaxSize !== null ? prefixMaxSize + decoderMaxSize : null;
241
+ return createDecoder({ ...decoder, ...maxSize !== null ? { maxSize } : {}, read });
242
+ }
243
+ function addCodecSizePrefix(codec, prefix) {
244
+ return combineCodec(addEncoderSizePrefix(codec, prefix), addDecoderSizePrefix(codec, prefix));
245
+ }
246
+
247
+ // src/fix-codec-size.ts
248
+ function fixEncoderSize(encoder, fixedBytes) {
249
+ return createEncoder({
250
+ fixedSize: fixedBytes,
251
+ write: (value, bytes, offset) => {
252
+ const variableByteArray = encoder.encode(value);
253
+ const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
254
+ bytes.set(fixedByteArray, offset);
255
+ return offset + fixedBytes;
256
+ }
257
+ });
258
+ }
259
+ function fixDecoderSize(decoder, fixedBytes) {
260
+ return createDecoder({
261
+ fixedSize: fixedBytes,
262
+ read: (bytes, offset) => {
263
+ assertByteArrayHasEnoughBytesForCodec("fixCodecSize", fixedBytes, bytes, offset);
264
+ if (offset > 0 || bytes.length > fixedBytes) {
265
+ bytes = bytes.slice(offset, offset + fixedBytes);
266
+ }
267
+ if (isFixedSize(decoder)) {
268
+ bytes = fixBytes(bytes, decoder.fixedSize);
269
+ }
270
+ const [value] = decoder.read(bytes, 0);
271
+ return [value, offset + fixedBytes];
272
+ }
273
+ });
274
+ }
275
+ function fixCodecSize(codec, fixedBytes) {
276
+ return combineCodec(fixEncoderSize(codec, fixedBytes), fixDecoderSize(codec, fixedBytes));
277
+ }
278
+
279
+ // src/offset-codec.ts
280
+ function offsetEncoder(encoder, config) {
281
+ return createEncoder({
282
+ ...encoder,
283
+ write: (value, bytes, preOffset) => {
284
+ const wrapBytes = (offset) => modulo(offset, bytes.length);
285
+ const newPreOffset = config.preOffset ? config.preOffset({ bytes, preOffset, wrapBytes }) : preOffset;
286
+ assertByteArrayOffsetIsNotOutOfRange("offsetEncoder", newPreOffset, bytes.length);
287
+ const postOffset = encoder.write(value, bytes, newPreOffset);
288
+ const newPostOffset = config.postOffset ? config.postOffset({ bytes, newPreOffset, postOffset, preOffset, wrapBytes }) : postOffset;
289
+ assertByteArrayOffsetIsNotOutOfRange("offsetEncoder", newPostOffset, bytes.length);
290
+ return newPostOffset;
291
+ }
292
+ });
293
+ }
294
+ function offsetDecoder(decoder, config) {
295
+ return createDecoder({
296
+ ...decoder,
297
+ read: (bytes, preOffset) => {
298
+ const wrapBytes = (offset) => modulo(offset, bytes.length);
299
+ const newPreOffset = config.preOffset ? config.preOffset({ bytes, preOffset, wrapBytes }) : preOffset;
300
+ assertByteArrayOffsetIsNotOutOfRange("offsetDecoder", newPreOffset, bytes.length);
301
+ const [value, postOffset] = decoder.read(bytes, newPreOffset);
302
+ const newPostOffset = config.postOffset ? config.postOffset({ bytes, newPreOffset, postOffset, preOffset, wrapBytes }) : postOffset;
303
+ assertByteArrayOffsetIsNotOutOfRange("offsetDecoder", newPostOffset, bytes.length);
304
+ return [value, newPostOffset];
305
+ }
306
+ });
307
+ }
308
+ function offsetCodec(codec, config) {
309
+ return combineCodec(offsetEncoder(codec, config), offsetDecoder(codec, config));
310
+ }
311
+ function modulo(dividend, divisor) {
312
+ if (divisor === 0) return 0;
313
+ return (dividend % divisor + divisor) % divisor;
314
+ }
315
+ function resizeEncoder(encoder, resize) {
316
+ if (isFixedSize(encoder)) {
317
+ const fixedSize = resize(encoder.fixedSize);
318
+ if (fixedSize < 0) {
319
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__EXPECTED_POSITIVE_BYTE_LENGTH, {
320
+ bytesLength: fixedSize,
321
+ codecDescription: "resizeEncoder"
322
+ });
323
+ }
324
+ return createEncoder({ ...encoder, fixedSize });
325
+ }
326
+ return createEncoder({
327
+ ...encoder,
328
+ getSizeFromValue: (value) => {
329
+ const newSize = resize(encoder.getSizeFromValue(value));
330
+ if (newSize < 0) {
331
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__EXPECTED_POSITIVE_BYTE_LENGTH, {
332
+ bytesLength: newSize,
333
+ codecDescription: "resizeEncoder"
334
+ });
335
+ }
336
+ return newSize;
337
+ }
338
+ });
339
+ }
340
+ function resizeDecoder(decoder, resize) {
341
+ if (isFixedSize(decoder)) {
342
+ const fixedSize = resize(decoder.fixedSize);
343
+ if (fixedSize < 0) {
344
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__EXPECTED_POSITIVE_BYTE_LENGTH, {
345
+ bytesLength: fixedSize,
346
+ codecDescription: "resizeDecoder"
347
+ });
348
+ }
349
+ return createDecoder({ ...decoder, fixedSize });
350
+ }
351
+ return decoder;
352
+ }
353
+ function resizeCodec(codec, resize) {
354
+ return combineCodec(resizeEncoder(codec, resize), resizeDecoder(codec, resize));
355
+ }
356
+
357
+ // src/pad-codec.ts
358
+ function padLeftEncoder(encoder, offset) {
359
+ return offsetEncoder(
360
+ resizeEncoder(encoder, (size) => size + offset),
361
+ { preOffset: ({ preOffset }) => preOffset + offset }
362
+ );
363
+ }
364
+ function padRightEncoder(encoder, offset) {
365
+ return offsetEncoder(
366
+ resizeEncoder(encoder, (size) => size + offset),
367
+ { postOffset: ({ postOffset }) => postOffset + offset }
368
+ );
369
+ }
370
+ function padLeftDecoder(decoder, offset) {
371
+ return offsetDecoder(
372
+ resizeDecoder(decoder, (size) => size + offset),
373
+ { preOffset: ({ preOffset }) => preOffset + offset }
374
+ );
375
+ }
376
+ function padRightDecoder(decoder, offset) {
377
+ return offsetDecoder(
378
+ resizeDecoder(decoder, (size) => size + offset),
379
+ { postOffset: ({ postOffset }) => postOffset + offset }
380
+ );
381
+ }
382
+ function padLeftCodec(codec, offset) {
383
+ return combineCodec(padLeftEncoder(codec, offset), padLeftDecoder(codec, offset));
384
+ }
385
+ function padRightCodec(codec, offset) {
386
+ return combineCodec(padRightEncoder(codec, offset), padRightDecoder(codec, offset));
387
+ }
388
+
389
+ // src/reverse-codec.ts
390
+ function copySourceToTargetInReverse(source, target_WILL_MUTATE, sourceOffset, sourceLength, targetOffset = 0) {
391
+ while (sourceOffset < --sourceLength) {
392
+ const leftValue = source[sourceOffset];
393
+ target_WILL_MUTATE[sourceOffset + targetOffset] = source[sourceLength];
394
+ target_WILL_MUTATE[sourceLength + targetOffset] = leftValue;
395
+ sourceOffset++;
396
+ }
397
+ if (sourceOffset === sourceLength) {
398
+ target_WILL_MUTATE[sourceOffset + targetOffset] = source[sourceOffset];
399
+ }
400
+ }
401
+ function reverseEncoder(encoder) {
402
+ assertIsFixedSize(encoder);
403
+ return createEncoder({
404
+ ...encoder,
405
+ write: (value, bytes, offset) => {
406
+ const newOffset = encoder.write(value, bytes, offset);
407
+ copySourceToTargetInReverse(
408
+ bytes,
409
+ bytes,
410
+ offset,
411
+ offset + encoder.fixedSize
412
+ );
413
+ return newOffset;
414
+ }
415
+ });
416
+ }
417
+ function reverseDecoder(decoder) {
418
+ assertIsFixedSize(decoder);
419
+ return createDecoder({
420
+ ...decoder,
421
+ read: (bytes, offset) => {
422
+ const reversedBytes = bytes.slice();
423
+ copySourceToTargetInReverse(
424
+ bytes,
425
+ reversedBytes,
426
+ offset,
427
+ offset + decoder.fixedSize
428
+ );
429
+ return decoder.read(reversedBytes, offset);
430
+ }
431
+ });
432
+ }
433
+ function reverseCodec(codec) {
434
+ return combineCodec(reverseEncoder(codec), reverseDecoder(codec));
435
+ }
436
+
437
+ // src/transform-codec.ts
438
+ function transformEncoder(encoder, unmap) {
439
+ return createEncoder({
440
+ ...isVariableSize(encoder) ? { ...encoder, getSizeFromValue: (value) => encoder.getSizeFromValue(unmap(value)) } : encoder,
441
+ write: (value, bytes, offset) => encoder.write(unmap(value), bytes, offset)
442
+ });
443
+ }
444
+ function transformDecoder(decoder, map) {
445
+ return createDecoder({
446
+ ...decoder,
447
+ read: (bytes, offset) => {
448
+ const [value, newOffset] = decoder.read(bytes, offset);
449
+ return [map(value, bytes, offset), newOffset];
450
+ }
451
+ });
452
+ }
453
+ function transformCodec(codec, unmap, map) {
454
+ return createCodec({
455
+ ...transformEncoder(codec, unmap),
456
+ read: map ? transformDecoder(codec, map).read : codec.read
457
+ });
458
+ }
459
+
460
+ exports.addCodecSentinel = addCodecSentinel;
461
+ exports.addCodecSizePrefix = addCodecSizePrefix;
462
+ exports.addDecoderSentinel = addDecoderSentinel;
463
+ exports.addDecoderSizePrefix = addDecoderSizePrefix;
464
+ exports.addEncoderSentinel = addEncoderSentinel;
465
+ exports.addEncoderSizePrefix = addEncoderSizePrefix;
466
+ exports.assertByteArrayHasEnoughBytesForCodec = assertByteArrayHasEnoughBytesForCodec;
467
+ exports.assertByteArrayIsNotEmptyForCodec = assertByteArrayIsNotEmptyForCodec;
468
+ exports.assertByteArrayOffsetIsNotOutOfRange = assertByteArrayOffsetIsNotOutOfRange;
469
+ exports.assertIsFixedSize = assertIsFixedSize;
470
+ exports.assertIsVariableSize = assertIsVariableSize;
471
+ exports.combineCodec = combineCodec;
472
+ exports.containsBytes = containsBytes;
473
+ exports.createCodec = createCodec;
474
+ exports.createDecoder = createDecoder;
475
+ exports.createEncoder = createEncoder;
476
+ exports.fixBytes = fixBytes;
477
+ exports.fixCodecSize = fixCodecSize;
478
+ exports.fixDecoderSize = fixDecoderSize;
479
+ exports.fixEncoderSize = fixEncoderSize;
480
+ exports.getEncodedSize = getEncodedSize;
481
+ exports.isFixedSize = isFixedSize;
482
+ exports.isVariableSize = isVariableSize;
483
+ exports.mergeBytes = mergeBytes;
484
+ exports.offsetCodec = offsetCodec;
485
+ exports.offsetDecoder = offsetDecoder;
486
+ exports.offsetEncoder = offsetEncoder;
487
+ exports.padBytes = padBytes;
488
+ exports.padLeftCodec = padLeftCodec;
489
+ exports.padLeftDecoder = padLeftDecoder;
490
+ exports.padLeftEncoder = padLeftEncoder;
491
+ exports.padRightCodec = padRightCodec;
492
+ exports.padRightDecoder = padRightDecoder;
493
+ exports.padRightEncoder = padRightEncoder;
494
+ exports.resizeCodec = resizeCodec;
495
+ exports.resizeDecoder = resizeDecoder;
496
+ exports.resizeEncoder = resizeEncoder;
497
+ exports.reverseCodec = reverseCodec;
498
+ exports.reverseDecoder = reverseDecoder;
499
+ exports.reverseEncoder = reverseEncoder;
500
+ exports.transformCodec = transformCodec;
501
+ exports.transformDecoder = transformDecoder;
502
+ exports.transformEncoder = transformEncoder;
503
+ //# sourceMappingURL=index.browser.cjs.map
504
+ //# sourceMappingURL=index.browser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bytes.ts","../src/codec.ts","../src/combine-codec.ts","../src/add-codec-sentinel.ts","../src/assertions.ts","../src/add-codec-size-prefix.ts","../src/fix-codec-size.ts","../src/offset-codec.ts","../src/resize-codec.ts","../src/pad-codec.ts","../src/reverse-codec.ts","../src/transform-codec.ts"],"names":["SolanaError","SOLANA_ERROR__CODECS__EXPECTED_FIXED_LENGTH","SOLANA_ERROR__CODECS__EXPECTED_VARIABLE_LENGTH","SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH","SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH","SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH","SOLANA_ERROR__CODECS__ENCODED_BYTES_MUST_NOT_INCLUDE_SENTINEL","SOLANA_ERROR__CODECS__SENTINEL_MISSING_IN_DECODED_BYTES","SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY","SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH","SOLANA_ERROR__CODECS__OFFSET_OUT_OF_RANGE","SOLANA_ERROR__CODECS__EXPECTED_POSITIVE_BYTE_LENGTH"],"mappings":";;;;;;;AAMa,IAAA,UAAA,GAAa,CAAC,UAAyC,KAAA;AAChE,EAAA,MAAM,kBAAqB,GAAA,UAAA,CAAW,MAAO,CAAA,CAAA,GAAA,KAAO,IAAI,MAAM,CAAA,CAAA;AAC9D,EAAI,IAAA,kBAAA,CAAmB,WAAW,CAAG,EAAA;AACjC,IAAA,OAAO,WAAW,MAAS,GAAA,UAAA,CAAW,CAAC,CAAA,GAAI,IAAI,UAAW,EAAA,CAAA;AAAA,GAC9D;AAEA,EAAI,IAAA,kBAAA,CAAmB,WAAW,CAAG,EAAA;AACjC,IAAA,O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A,KAAA,EAAO,MAAM,CAAA;AAAA,GACvF,CAAA,CAAA;AACL,CAAA;AAiBO,SAAS,gBAAA,CACZ,SACA,GACe,EAAA;AACf,EAAA,OAAO,aAAc,CAAA;AAAA,IACjB,GAAG,OAAA;AAAA,IACH,IAAA,EAAM,CAAC,KAAA,EAAwC,MAAW,KAAA;AACtD,MAAA,MAAM,CAAC,KAAO,EAAA,SAAS,IAAI,OAAQ,CAAA,IAAA,CAAK,OAAO,MAAM,CAAA,CAAA;AACrD,MAAA,OAAO,CAAC,GAAI,CAAA,KAAA,EAAO,KAAO,EAAA,MAAM,GAAG,SAAS,CAAA,CAAA;AAAA,KAChD;AAAA,GACH,CAAA,CAAA;AACL,CAAA;AAsCO,SAAS,cAAA,CACZ,KACA,EAAA,KAAA,EACA,GACuB,EAAA;AACvB,EAAA,OAAO,WAAY,CAAA;AAAA,IACf,GAAG,gBAAiB,CAAA,KAAA,EAAO,KAAK,CAAA;AAAA,IAChC,MAAM,GAAM,GAAA,gBAAA,CAAiB,OAAO,GAAG,CAAA,CAAE,OAAQ,KAAM,CAAA,IAAA;AAAA,GAC1D,CAAA,CAAA;AACL","file":"index.browser.cjs","sourcesContent":["import { ReadonlyUint8Array } from './readonly-uint8array';\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: ReadonlyUint8Array | Uint8Array, length: number): ReadonlyUint8Array | 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: ReadonlyUint8Array | Uint8Array, length: number): ReadonlyUint8Array | Uint8Array =>\n padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);\n\n/**\n * Returns true if and only if the provided `data` byte array contains\n * the provided `bytes` byte array at the specified `offset`.\n */\nexport function containsBytes(\n data: ReadonlyUint8Array | Uint8Array,\n bytes: ReadonlyUint8Array | Uint8Array,\n offset: number,\n): boolean {\n const slice = offset === 0 && data.length === bytes.length ? data : data.slice(offset, offset + bytes.length);\n if (slice.length !== bytes.length) return false;\n return bytes.every((b, i) => b === slice[i]);\n}\n","import {\n SOLANA_ERROR__CODECS__EXPECTED_FIXED_LENGTH,\n SOLANA_ERROR__CODECS__EXPECTED_VARIABLE_LENGTH,\n SolanaError,\n} from '@solana/errors';\n\nimport { ReadonlyUint8Array } from './readonly-uint8array';\n\n/**\n * Defines an offset in bytes.\n */\nexport type Offset = number;\n\ntype BaseEncoder<TFrom> = {\n /** Encode the provided value and return the encoded bytes directly. */\n readonly encode: (value: TFrom) => ReadonlyUint8Array;\n /**\n * Writes the encoded value into the provided byte array at the given offset.\n * Returns the offset of the next byte after the encoded value.\n */\n readonly write: (value: TFrom, bytes: Uint8Array, offset: Offset) => Offset;\n};\n\nexport type FixedSizeEncoder<TFrom, TSize extends number = number> = BaseEncoder<TFrom> & {\n /** The fixed size of the encoded value in bytes. */\n readonly fixedSize: TSize;\n};\n\nexport type VariableSizeEncoder<TFrom> = BaseEncoder<TFrom> & {\n /** The total size of the encoded value in bytes. */\n readonly getSizeFromValue: (value: TFrom) => number;\n /** The maximum size an encoded value can be in bytes, if applicable. */\n readonly maxSize?: number;\n};\n\n/**\n * An object that can encode a value to a `Uint8Array`.\n */\nexport type Encoder<TFrom> = FixedSizeEncoder<TFrom> | VariableSizeEncoder<TFrom>;\n\ntype BaseDecoder<TTo> = {\n /** Decodes the provided byte array at the given offset (or zero) and returns the value directly. */\n readonly decode: (bytes: ReadonlyUint8Array | Uint8Array, offset?: Offset) => TTo;\n /**\n * Reads the encoded value from the provided byte array at the given offset.\n * Returns the decoded value and the offset of the next byte after the encoded value.\n */\n readonly read: (bytes: ReadonlyUint8Array | Uint8Array, offset: Offset) => [TTo, Offset];\n};\n\nexport type FixedSizeDecoder<TTo, TSize extends number = number> = BaseDecoder<TTo> & {\n /** The fixed size of the encoded value in bytes. */\n readonly fixedSize: TSize;\n};\n\nexport type VariableSizeDecoder<TTo> = BaseDecoder<TTo> & {\n /** The maximum size an encoded value can be in bytes, if applicable. */\n readonly maxSize?: number;\n};\n\n/**\n * An object that can decode a value from a `Uint8Array`.\n */\nexport type Decoder<TTo> = FixedSizeDecoder<TTo> | VariableSizeDecoder<TTo>;\n\nexport type FixedSizeCodec<TFrom, TTo extends TFrom = TFrom, TSize extends number = number> = FixedSizeDecoder<\n TTo,\n TSize\n> &\n FixedSizeEncoder<TFrom, TSize>;\n\nexport type VariableSizeCodec<TFrom, TTo extends TFrom = TFrom> = VariableSizeDecoder<TTo> & VariableSizeEncoder<TFrom>;\n\n/**\n * An object that can encode and decode a value to and from a `Uint8Array`.\n * It supports encoding looser types than it decodes for convenience.\n * For example, a `bigint` encoder will always decode to a `bigint`\n * but can be used to encode a `number`.\n *\n * @typeParam TFrom - The type of the value to encode.\n * @typeParam TTo - The type of the decoded value. Defaults to `TFrom`.\n */\nexport type Codec<TFrom, TTo extends TFrom = TFrom> = FixedSizeCodec<TFrom, TTo> | VariableSizeCodec<TFrom, TTo>;\n\n/**\n * Get the encoded size of a given value in bytes.\n */\nexport function getEncodedSize<TFrom>(\n value: TFrom,\n encoder: { fixedSize: number } | { getSizeFromValue: (value: TFrom) => number },\n): number {\n return 'fixedSize' in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);\n}\n\n/** Fills the missing `encode` function using the existing `write` function. */\nexport function createEncoder<TFrom, TSize extends number>(\n encoder: Omit<FixedSizeEncoder<TFrom, TSize>, 'encode'>,\n): FixedSizeEncoder<TFrom, TSize>;\nexport function createEncoder<TFrom>(encoder: Omit<VariableSizeEncoder<TFrom>, 'encode'>): VariableSizeEncoder<TFrom>;\nexport function createEncoder<TFrom>(\n encoder: Omit<FixedSizeEncoder<TFrom>, 'encode'> | Omit<VariableSizeEncoder<TFrom>, 'encode'>,\n): Encoder<TFrom>;\nexport function createEncoder<TFrom>(\n encoder: Omit<FixedSizeEncoder<TFrom>, 'encode'> | Omit<VariableSizeEncoder<TFrom>, 'encode'>,\n): Encoder<TFrom> {\n return Object.freeze({\n ...encoder,\n encode: value => {\n const bytes = new Uint8Array(getEncodedSize(value, encoder));\n encoder.write(value, bytes, 0);\n return bytes;\n },\n });\n}\n\n/** Fills the missing `decode` function using the existing `read` function. */\nexport function createDecoder<TTo, TSize extends number>(\n decoder: Omit<FixedSizeDecoder<TTo, TSize>, 'decode'>,\n): FixedSizeDecoder<TTo, TSize>;\nexport function createDecoder<TTo>(decoder: Omit<VariableSizeDecoder<TTo>, 'decode'>): VariableSizeDecoder<TTo>;\nexport function createDecoder<TTo>(\n decoder: Omit<FixedSizeDecoder<TTo>, 'decode'> | Omit<VariableSizeDecoder<TTo>, 'decode'>,\n): Decoder<TTo>;\nexport function createDecoder<TTo>(\n decoder: Omit<FixedSizeDecoder<TTo>, 'decode'> | Omit<VariableSizeDecoder<TTo>, 'decode'>,\n): Decoder<TTo> {\n return Object.freeze({\n ...decoder,\n decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0],\n });\n}\n\n/** Fills the missing `encode` and `decode` function using the existing `write` and `read` functions. */\nexport function createCodec<TFrom, TTo extends TFrom = TFrom, TSize extends number = number>(\n codec: Omit<FixedSizeCodec<TFrom, TTo, TSize>, 'decode' | 'encode'>,\n): FixedSizeCodec<TFrom, TTo, TSize>;\nexport function createCodec<TFrom, TTo extends TFrom = TFrom>(\n codec: Omit<VariableSizeCodec<TFrom, TTo>, 'decode' | 'encode'>,\n): VariableSizeCodec<TFrom, TTo>;\nexport function createCodec<TFrom, TTo extends TFrom = TFrom>(\n codec:\n | Omit<FixedSizeCodec<TFrom, TTo>, 'decode' | 'encode'>\n | Omit<VariableSizeCodec<TFrom, TTo>, 'decode' | 'encode'>,\n): Codec<TFrom, TTo>;\nexport function createCodec<TFrom, TTo extends TFrom = TFrom>(\n codec:\n | Omit<FixedSizeCodec<TFrom, TTo>, 'decode' | 'encode'>\n | Omit<VariableSizeCodec<TFrom, TTo>, 'decode' | 'encode'>,\n): Codec<TFrom, TTo> {\n return Object.freeze({\n ...codec,\n decode: (bytes, offset = 0) => codec.read(bytes, offset)[0],\n encode: value => {\n const bytes = new Uint8Array(getEncodedSize(value, codec));\n codec.write(value, bytes, 0);\n return bytes;\n },\n });\n}\n\nexport function isFixedSize<TFrom, TSize extends number>(\n encoder: FixedSizeEncoder<TFrom, TSize> | VariableSizeEncoder<TFrom>,\n): encoder is FixedSizeEncoder<TFrom, TSize>;\nexport function isFixedSize<TTo, TSize extends number>(\n decoder: FixedSizeDecoder<TTo, TSize> | VariableSizeDecoder<TTo>,\n): decoder is FixedSizeDecoder<TTo, TSize>;\nexport function isFixedSize<TFrom, TTo extends TFrom, TSize extends number>(\n codec: FixedSizeCodec<TFrom, TTo, TSize> | VariableSizeCodec<TFrom, TTo>,\n): codec is FixedSizeCodec<TFrom, TTo, TSize>;\nexport function isFixedSize<TSize extends number>(\n codec: { fixedSize: TSize } | { maxSize?: number },\n): codec is { fixedSize: TSize };\nexport function isFixedSize(codec: { fixedSize: number } | { maxSize?: number }): codec is { fixedSize: number } {\n return 'fixedSize' in codec && typeof codec.fixedSize === 'number';\n}\n\nexport function assertIsFixedSize<TFrom, TSize extends number>(\n encoder: FixedSizeEncoder<TFrom, TSize> | VariableSizeEncoder<TFrom>,\n): asserts encoder is FixedSizeEncoder<TFrom, TSize>;\nexport function assertIsFixedSize<TTo, TSize extends number>(\n decoder: FixedSizeDecoder<TTo, TSize> | VariableSizeDecoder<TTo>,\n): asserts decoder is FixedSizeDecoder<TTo, TSize>;\nexport function assertIsFixedSize<TFrom, TTo extends TFrom, TSize extends number>(\n codec: FixedSizeCodec<TFrom, TTo, TSize> | VariableSizeCodec<TFrom, TTo>,\n): asserts codec is FixedSizeCodec<TFrom, TTo, TSize>;\nexport function assertIsFixedSize<TSize extends number>(\n codec: { fixedSize: TSize } | { maxSize?: number },\n): asserts codec is { fixedSize: TSize };\nexport function assertIsFixedSize(\n codec: { fixedSize: number } | { maxSize?: number },\n): asserts codec is { fixedSize: number } {\n if (!isFixedSize(codec)) {\n throw new SolanaError(SOLANA_ERROR__CODECS__EXPECTED_FIXED_LENGTH);\n }\n}\n\nexport function isVariableSize<TFrom>(encoder: Encoder<TFrom>): encoder is VariableSizeEncoder<TFrom>;\nexport function isVariableSize<TTo>(decoder: Decoder<TTo>): decoder is VariableSizeDecoder<TTo>;\nexport function isVariableSize<TFrom, TTo extends TFrom>(\n codec: Codec<TFrom, TTo>,\n): codec is VariableSizeCodec<TFrom, TTo>;\nexport function isVariableSize(codec: { fixedSize: number } | { maxSize?: number }): codec is { maxSize?: number };\nexport function isVariableSize(codec: { fixedSize: number } | { maxSize?: number }): codec is { maxSize?: number } {\n return !isFixedSize(codec);\n}\n\nexport function assertIsVariableSize<T>(encoder: Encoder<T>): asserts encoder is VariableSizeEncoder<T>;\nexport function assertIsVariableSize<T>(decoder: Decoder<T>): asserts decoder is VariableSizeDecoder<T>;\nexport function assertIsVariableSize<TFrom, TTo extends TFrom>(\n codec: Codec<TFrom, TTo>,\n): asserts codec is VariableSizeCodec<TFrom, TTo>;\nexport function assertIsVariableSize(\n codec: { fixedSize: number } | { maxSize?: number },\n): asserts codec is { maxSize?: number };\nexport function assertIsVariableSize(\n codec: { fixedSize: number } | { maxSize?: number },\n): asserts codec is { maxSize?: number } {\n if (!isVariableSize(codec)) {\n throw new SolanaError(SOLANA_ERROR__CODECS__EXPECTED_VARIABLE_LENGTH);\n }\n}\n","import {\n SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH,\n SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH,\n SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH,\n SolanaError,\n} from '@solana/errors';\n\nimport {\n Codec,\n Decoder,\n Encoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n isFixedSize,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} 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<TFrom, TTo extends TFrom, TSize extends number>(\n encoder: FixedSizeEncoder<TFrom, TSize>,\n decoder: FixedSizeDecoder<TTo, TSize>,\n): FixedSizeCodec<TFrom, TTo, TSize>;\nexport function combineCodec<TFrom, TTo extends TFrom>(\n encoder: VariableSizeEncoder<TFrom>,\n decoder: VariableSizeDecoder<TTo>,\n): VariableSizeCodec<TFrom, TTo>;\nexport function combineCodec<TFrom, TTo extends TFrom>(\n encoder: Encoder<TFrom>,\n decoder: Decoder<TTo>,\n): Codec<TFrom, TTo>;\nexport function combineCodec<TFrom, TTo extends TFrom>(\n encoder: Encoder<TFrom>,\n decoder: Decoder<TTo>,\n): Codec<TFrom, TTo> {\n if (isFixedSize(encoder) !== isFixedSize(decoder)) {\n throw new SolanaError(SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH);\n }\n\n if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {\n throw new SolanaError(SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH, {\n decoderFixedSize: decoder.fixedSize,\n encoderFixedSize: encoder.fixedSize,\n });\n }\n\n if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {\n throw new SolanaError(SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH, {\n decoderMaxSize: decoder.maxSize,\n encoderMaxSize: encoder.maxSize,\n });\n }\n\n return {\n ...decoder,\n ...encoder,\n decode: decoder.decode,\n encode: encoder.encode,\n read: decoder.read,\n write: encoder.write,\n };\n}\n","import {\n SOLANA_ERROR__CODECS__ENCODED_BYTES_MUST_NOT_INCLUDE_SENTINEL,\n SOLANA_ERROR__CODECS__SENTINEL_MISSING_IN_DECODED_BYTES,\n SolanaError,\n} from '@solana/errors';\n\nimport { containsBytes } from './bytes';\nimport {\n Codec,\n createDecoder,\n createEncoder,\n Decoder,\n Encoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n isFixedSize,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from './codec';\nimport { combineCodec } from './combine-codec';\nimport { ReadonlyUint8Array } from './readonly-uint8array';\n\n/**\n * Creates an encoder that writes a `Uint8Array` sentinel after the encoded value.\n * This is useful to delimit the encoded value when being read by a decoder.\n *\n * Note that, if the sentinel is found in the encoded value, an error is thrown.\n */\nexport function addEncoderSentinel<TFrom>(\n encoder: FixedSizeEncoder<TFrom>,\n sentinel: ReadonlyUint8Array,\n): FixedSizeEncoder<TFrom>;\nexport function addEncoderSentinel<TFrom>(\n encoder: Encoder<TFrom>,\n sentinel: ReadonlyUint8Array,\n): VariableSizeEncoder<TFrom>;\nexport function addEncoderSentinel<TFrom>(encoder: Encoder<TFrom>, sentinel: ReadonlyUint8Array): Encoder<TFrom> {\n const write = ((value, bytes, offset) => {\n // Here we exceptionally use the `encode` function instead of the `write`\n // function to contain the content of the encoder within its own bounds\n // and to avoid writing the sentinel as part of the encoded value.\n const encoderBytes = encoder.encode(value);\n if (findSentinelIndex(encoderBytes, sentinel) >= 0) {\n throw new SolanaError(SOLANA_ERROR__CODECS__ENCODED_BYTES_MUST_NOT_INCLUDE_SENTINEL, {\n encodedBytes: encoderBytes,\n hexEncodedBytes: hexBytes(encoderBytes),\n hexSentinel: hexBytes(sentinel),\n sentinel,\n });\n }\n bytes.set(encoderBytes, offset);\n offset += encoderBytes.length;\n bytes.set(sentinel, offset);\n offset += sentinel.length;\n return offset;\n }) as Encoder<TFrom>['write'];\n\n if (isFixedSize(encoder)) {\n return createEncoder({ ...encoder, fixedSize: encoder.fixedSize + sentinel.length, write });\n }\n\n return createEncoder({\n ...encoder,\n ...(encoder.maxSize != null ? { maxSize: encoder.maxSize + sentinel.length } : {}),\n getSizeFromValue: value => encoder.getSizeFromValue(value) + sentinel.length,\n write,\n });\n}\n\n/**\n * Creates a decoder that continues reading until a `Uint8Array` sentinel is found.\n *\n * If the sentinel is not found in the byte array to decode, an error is thrown.\n */\nexport function addDecoderSentinel<TTo>(\n decoder: FixedSizeDecoder<TTo>,\n sentinel: ReadonlyUint8Array,\n): FixedSizeDecoder<TTo>;\nexport function addDecoderSentinel<TTo>(decoder: Decoder<TTo>, sentinel: ReadonlyUint8Array): VariableSizeDecoder<TTo>;\nexport function addDecoderSentinel<TTo>(decoder: Decoder<TTo>, sentinel: ReadonlyUint8Array): Decoder<TTo> {\n const read = ((bytes, offset) => {\n const candidateBytes = offset === 0 ? bytes : bytes.slice(offset);\n const sentinelIndex = findSentinelIndex(candidateBytes, sentinel);\n if (sentinelIndex === -1) {\n throw new SolanaError(SOLANA_ERROR__CODECS__SENTINEL_MISSING_IN_DECODED_BYTES, {\n decodedBytes: candidateBytes,\n hexDecodedBytes: hexBytes(candidateBytes),\n hexSentinel: hexBytes(sentinel),\n sentinel,\n });\n }\n const preSentinelBytes = candidateBytes.slice(0, sentinelIndex);\n // Here we exceptionally use the `decode` function instead of the `read`\n // function to contain the content of the decoder within its own bounds\n // and ensure that the sentinel is not part of the decoded value.\n return [decoder.decode(preSentinelBytes), offset + preSentinelBytes.length + sentinel.length];\n }) as Decoder<TTo>['read'];\n\n if (isFixedSize(decoder)) {\n return createDecoder({ ...decoder, fixedSize: decoder.fixedSize + sentinel.length, read });\n }\n\n return createDecoder({\n ...decoder,\n ...(decoder.maxSize != null ? { maxSize: decoder.maxSize + sentinel.length } : {}),\n read,\n });\n}\n\n/**\n * Creates a Codec that writes a `Uint8Array` sentinel after the encoded\n * value and, when decoding, continues reading until the sentinel is found.\n *\n * Note that, if the sentinel is found in the encoded value\n * or not found in the byte array to decode, an error is thrown.\n */\nexport function addCodecSentinel<TFrom, TTo extends TFrom>(\n codec: FixedSizeCodec<TFrom, TTo>,\n sentinel: ReadonlyUint8Array,\n): FixedSizeCodec<TFrom, TTo>;\nexport function addCodecSentinel<TFrom, TTo extends TFrom>(\n codec: Codec<TFrom, TTo>,\n sentinel: ReadonlyUint8Array,\n): VariableSizeCodec<TFrom, TTo>;\nexport function addCodecSentinel<TFrom, TTo extends TFrom>(\n codec: Codec<TFrom, TTo>,\n sentinel: ReadonlyUint8Array,\n): Codec<TFrom, TTo> {\n return combineCodec(addEncoderSentinel(codec, sentinel), addDecoderSentinel(codec, sentinel));\n}\n\nfunction findSentinelIndex(bytes: ReadonlyUint8Array, sentinel: ReadonlyUint8Array) {\n return bytes.findIndex((byte, index, arr) => {\n if (sentinel.length === 1) return byte === sentinel[0];\n return containsBytes(arr, sentinel, index);\n });\n}\n\nfunction hexBytes(bytes: ReadonlyUint8Array): string {\n return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n}\n","import {\n SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY,\n SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH,\n SOLANA_ERROR__CODECS__OFFSET_OUT_OF_RANGE,\n SolanaError,\n} from '@solana/errors';\n\nimport { ReadonlyUint8Array } from './readonly-uint8array';\n\n/**\n * Asserts that a given byte array is not empty.\n */\nexport function assertByteArrayIsNotEmptyForCodec(\n codecDescription: string,\n bytes: ReadonlyUint8Array | Uint8Array,\n offset = 0,\n) {\n if (bytes.length - offset <= 0) {\n throw new SolanaError(SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY, {\n codecDescription,\n });\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: ReadonlyUint8Array | Uint8Array,\n offset = 0,\n) {\n const bytesLength = bytes.length - offset;\n if (bytesLength < expected) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH, {\n bytesLength,\n codecDescription,\n expected,\n });\n }\n}\n\n/**\n * Asserts that a given offset is within the byte array bounds.\n * This range is between 0 and the byte array length and is inclusive.\n * An offset equals to the byte array length is considered a valid offset\n * as it allows the post-offset of codecs to signal the end of the byte array.\n */\nexport function assertByteArrayOffsetIsNotOutOfRange(codecDescription: string, offset: number, bytesLength: number) {\n if (offset < 0 || offset > bytesLength) {\n throw new SolanaError(SOLANA_ERROR__CODECS__OFFSET_OUT_OF_RANGE, {\n bytesLength,\n codecDescription,\n offset,\n });\n }\n}\n","import { assertByteArrayHasEnoughBytesForCodec } from './assertions';\nimport {\n Codec,\n createDecoder,\n createEncoder,\n Decoder,\n Encoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n getEncodedSize,\n isFixedSize,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from './codec';\nimport { combineCodec } from './combine-codec';\n\ntype NumberEncoder = Encoder<bigint | number> | Encoder<number>;\ntype FixedSizeNumberEncoder<TSize extends number = number> =\n | FixedSizeEncoder<bigint | number, TSize>\n | FixedSizeEncoder<number, TSize>;\ntype NumberDecoder = Decoder<bigint> | Decoder<number>;\ntype FixedSizeNumberDecoder<TSize extends number = number> =\n | FixedSizeDecoder<bigint, TSize>\n | FixedSizeDecoder<number, TSize>;\ntype NumberCodec = Codec<bigint | number, bigint> | Codec<number>;\ntype FixedSizeNumberCodec<TSize extends number = number> =\n | FixedSizeCodec<bigint | number, bigint, TSize>\n | FixedSizeCodec<number, number, TSize>;\n\n/**\n * Stores the size of the `encoder` in bytes as a prefix using the `prefix` encoder.\n */\nexport function addEncoderSizePrefix<TFrom>(\n encoder: FixedSizeEncoder<TFrom>,\n prefix: FixedSizeNumberEncoder,\n): FixedSizeEncoder<TFrom>;\nexport function addEncoderSizePrefix<TFrom>(encoder: Encoder<TFrom>, prefix: NumberEncoder): VariableSizeEncoder<TFrom>;\nexport function addEncoderSizePrefix<TFrom>(encoder: Encoder<TFrom>, prefix: NumberEncoder): Encoder<TFrom> {\n const write = ((value, bytes, offset) => {\n // Here we exceptionally use the `encode` function instead of the `write`\n // function to contain the content of the encoder within its own bounds.\n const encoderBytes = encoder.encode(value);\n offset = prefix.write(encoderBytes.length, bytes, offset);\n bytes.set(encoderBytes, offset);\n return offset + encoderBytes.length;\n }) as Encoder<TFrom>['write'];\n\n if (isFixedSize(prefix) && isFixedSize(encoder)) {\n return createEncoder({ ...encoder, fixedSize: prefix.fixedSize + encoder.fixedSize, write });\n }\n\n const prefixMaxSize = isFixedSize(prefix) ? prefix.fixedSize : (prefix.maxSize ?? null);\n const encoderMaxSize = isFixedSize(encoder) ? encoder.fixedSize : (encoder.maxSize ?? null);\n const maxSize = prefixMaxSize !== null && encoderMaxSize !== null ? prefixMaxSize + encoderMaxSize : null;\n\n return createEncoder({\n ...encoder,\n ...(maxSize !== null ? { maxSize } : {}),\n getSizeFromValue: value => {\n const encoderSize = getEncodedSize(value, encoder);\n return getEncodedSize(encoderSize, prefix) + encoderSize;\n },\n write,\n });\n}\n\n/**\n * Bounds the size of the `decoder` by reading the `prefix` encoder prefix.\n */\nexport function addDecoderSizePrefix<TTo>(\n decoder: FixedSizeDecoder<TTo>,\n prefix: FixedSizeNumberDecoder,\n): FixedSizeDecoder<TTo>;\nexport function addDecoderSizePrefix<TTo>(decoder: Decoder<TTo>, prefix: NumberDecoder): VariableSizeDecoder<TTo>;\nexport function addDecoderSizePrefix<TTo>(decoder: Decoder<TTo>, prefix: NumberDecoder): Decoder<TTo> {\n const read = ((bytes, offset) => {\n const [bigintSize, decoderOffset] = prefix.read(bytes, offset);\n const size = Number(bigintSize);\n offset = decoderOffset;\n // Slice the byte array to the contained size if necessary.\n if (offset > 0 || bytes.length > size) {\n bytes = bytes.slice(offset, offset + size);\n }\n assertByteArrayHasEnoughBytesForCodec('addDecoderSizePrefix', size, bytes);\n // Here we exceptionally use the `decode` function instead of the `read`\n // function to contain the content of the decoder within its own bounds.\n return [decoder.decode(bytes), offset + size];\n }) as Decoder<TTo>['read'];\n\n if (isFixedSize(prefix) && isFixedSize(decoder)) {\n return createDecoder({ ...decoder, fixedSize: prefix.fixedSize + decoder.fixedSize, read });\n }\n\n const prefixMaxSize = isFixedSize(prefix) ? prefix.fixedSize : (prefix.maxSize ?? null);\n const decoderMaxSize = isFixedSize(decoder) ? decoder.fixedSize : (decoder.maxSize ?? null);\n const maxSize = prefixMaxSize !== null && decoderMaxSize !== null ? prefixMaxSize + decoderMaxSize : null;\n return createDecoder({ ...decoder, ...(maxSize !== null ? { maxSize } : {}), read });\n}\n\n/**\n * Bounds the size of the `codec` using the provided `prefix` codec prefix.\n */\nexport function addCodecSizePrefix<TFrom, TTo extends TFrom>(\n codec: FixedSizeCodec<TFrom, TTo>,\n prefix: FixedSizeNumberCodec,\n): FixedSizeCodec<TFrom, TTo>;\nexport function addCodecSizePrefix<TFrom, TTo extends TFrom>(\n codec: Codec<TFrom, TTo>,\n prefix: NumberCodec,\n): VariableSizeCodec<TFrom, TTo>;\nexport function addCodecSizePrefix<TFrom, TTo extends TFrom>(\n codec: Codec<TFrom, TTo>,\n prefix: NumberCodec,\n): Codec<TFrom, TTo> {\n return combineCodec(addEncoderSizePrefix(codec, prefix), addDecoderSizePrefix(codec, prefix));\n}\n","import { assertByteArrayHasEnoughBytesForCodec } from './assertions';\nimport { fixBytes } from './bytes';\nimport {\n Codec,\n createDecoder,\n createEncoder,\n Decoder,\n Encoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n isFixedSize,\n Offset,\n} from './codec';\nimport { combineCodec } from './combine-codec';\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 */\nexport function fixEncoderSize<TFrom, TSize extends number>(\n encoder: Encoder<TFrom>,\n fixedBytes: TSize,\n): FixedSizeEncoder<TFrom, TSize> {\n return createEncoder({\n fixedSize: fixedBytes,\n write: (value: TFrom, bytes: Uint8Array, offset: Offset) => {\n // Here we exceptionally use the `encode` function instead of the `write`\n // function as using the nested `write` function on a fixed-sized byte\n // array may result in a out-of-bounds error on the nested encoder.\n const variableByteArray = encoder.encode(value);\n const fixedByteArray =\n variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;\n bytes.set(fixedByteArray, offset);\n return offset + fixedBytes;\n },\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 */\nexport function fixDecoderSize<TTo, TSize extends number>(\n decoder: Decoder<TTo>,\n fixedBytes: TSize,\n): FixedSizeDecoder<TTo, TSize> {\n return createDecoder({\n fixedSize: fixedBytes,\n read: (bytes, offset) => {\n assertByteArrayHasEnoughBytesForCodec('fixCodecSize', 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 (isFixedSize(decoder)) {\n bytes = fixBytes(bytes, decoder.fixedSize);\n }\n // Decode the value using the nested decoder.\n const [value] = decoder.read(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 */\nexport function fixCodecSize<TFrom, TTo extends TFrom, TSize extends number>(\n codec: Codec<TFrom, TTo>,\n fixedBytes: TSize,\n): FixedSizeCodec<TFrom, TTo, TSize> {\n return combineCodec(fixEncoderSize(codec, fixedBytes), fixDecoderSize(codec, fixedBytes));\n}\n","import { assertByteArrayOffsetIsNotOutOfRange } from './assertions';\nimport { Codec, createDecoder, createEncoder, Decoder, Encoder, Offset } from './codec';\nimport { combineCodec } from './combine-codec';\nimport { ReadonlyUint8Array } from './readonly-uint8array';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyEncoder = Encoder<any>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyDecoder = Decoder<any>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyCodec = Codec<any>;\n\ntype OffsetConfig = {\n postOffset?: PostOffsetFunction;\n preOffset?: PreOffsetFunction;\n};\n\ntype PreOffsetFunctionScope = {\n /** The entire byte array. */\n bytes: ReadonlyUint8Array | Uint8Array;\n /** The original offset prior to encode or decode. */\n preOffset: Offset;\n /** Wraps the offset to the byte array length. */\n wrapBytes: (offset: Offset) => Offset;\n};\n\ntype PreOffsetFunction = (scope: PreOffsetFunctionScope) => Offset;\ntype PostOffsetFunction = (\n scope: PreOffsetFunctionScope & {\n /** The modified offset used to encode or decode. */\n newPreOffset: Offset;\n /** The original offset returned by the encoder or decoder. */\n postOffset: Offset;\n },\n) => Offset;\n\n/**\n * Moves the offset of a given encoder.\n */\nexport function offsetEncoder<TEncoder extends AnyEncoder>(encoder: TEncoder, config: OffsetConfig): TEncoder {\n return createEncoder({\n ...encoder,\n write: (value, bytes, preOffset) => {\n const wrapBytes = (offset: Offset) => modulo(offset, bytes.length);\n const newPreOffset = config.preOffset ? config.preOffset({ bytes, preOffset, wrapBytes }) : preOffset;\n assertByteArrayOffsetIsNotOutOfRange('offsetEncoder', newPreOffset, bytes.length);\n const postOffset = encoder.write(value, bytes, newPreOffset);\n const newPostOffset = config.postOffset\n ? config.postOffset({ bytes, newPreOffset, postOffset, preOffset, wrapBytes })\n : postOffset;\n assertByteArrayOffsetIsNotOutOfRange('offsetEncoder', newPostOffset, bytes.length);\n return newPostOffset;\n },\n }) as TEncoder;\n}\n\n/**\n * Moves the offset of a given decoder.\n */\nexport function offsetDecoder<TDecoder extends AnyDecoder>(decoder: TDecoder, config: OffsetConfig): TDecoder {\n return createDecoder({\n ...decoder,\n read: (bytes, preOffset) => {\n const wrapBytes = (offset: Offset) => modulo(offset, bytes.length);\n const newPreOffset = config.preOffset ? config.preOffset({ bytes, preOffset, wrapBytes }) : preOffset;\n assertByteArrayOffsetIsNotOutOfRange('offsetDecoder', newPreOffset, bytes.length);\n const [value, postOffset] = decoder.read(bytes, newPreOffset);\n const newPostOffset = config.postOffset\n ? config.postOffset({ bytes, newPreOffset, postOffset, preOffset, wrapBytes })\n : postOffset;\n assertByteArrayOffsetIsNotOutOfRange('offsetDecoder', newPostOffset, bytes.length);\n return [value, newPostOffset];\n },\n }) as TDecoder;\n}\n\n/**\n * Moves the offset of a given codec.\n */\nexport function offsetCodec<TCodec extends AnyCodec>(codec: TCodec, config: OffsetConfig): TCodec {\n return combineCodec(offsetEncoder(codec, config), offsetDecoder(codec, config)) as TCodec;\n}\n\n/** A modulo function that handles negative dividends and zero divisors. */\nfunction modulo(dividend: number, divisor: number) {\n if (divisor === 0) return 0;\n return ((dividend % divisor) + divisor) % divisor;\n}\n","import { SOLANA_ERROR__CODECS__EXPECTED_POSITIVE_BYTE_LENGTH, SolanaError } from '@solana/errors';\n\nimport {\n Codec,\n createDecoder,\n createEncoder,\n Decoder,\n Encoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n isFixedSize,\n} from './codec';\nimport { combineCodec } from './combine-codec';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyEncoder = Encoder<any>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyDecoder = Decoder<any>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyCodec = Codec<any>;\n\n/**\n * Updates the size of a given encoder.\n */\nexport function resizeEncoder<TFrom, TSize extends number, TNewSize extends number>(\n encoder: FixedSizeEncoder<TFrom, TSize>,\n resize: (size: TSize) => TNewSize,\n): FixedSizeEncoder<TFrom, TNewSize>;\nexport function resizeEncoder<TEncoder extends AnyEncoder>(\n encoder: TEncoder,\n resize: (size: number) => number,\n): TEncoder;\nexport function resizeEncoder<TEncoder extends AnyEncoder>(\n encoder: TEncoder,\n resize: (size: number) => number,\n): TEncoder {\n if (isFixedSize(encoder)) {\n const fixedSize = resize(encoder.fixedSize);\n if (fixedSize < 0) {\n throw new SolanaError(SOLANA_ERROR__CODECS__EXPECTED_POSITIVE_BYTE_LENGTH, {\n bytesLength: fixedSize,\n codecDescription: 'resizeEncoder',\n });\n }\n return createEncoder({ ...encoder, fixedSize }) as TEncoder;\n }\n return createEncoder({\n ...encoder,\n getSizeFromValue: value => {\n const newSize = resize(encoder.getSizeFromValue(value));\n if (newSize < 0) {\n throw new SolanaError(SOLANA_ERROR__CODECS__EXPECTED_POSITIVE_BYTE_LENGTH, {\n bytesLength: newSize,\n codecDescription: 'resizeEncoder',\n });\n }\n return newSize;\n },\n }) as TEncoder;\n}\n\n/**\n * Updates the size of a given decoder.\n */\n\nexport function resizeDecoder<TFrom, TSize extends number, TNewSize extends number>(\n decoder: FixedSizeDecoder<TFrom, TSize>,\n resize: (size: TSize) => TNewSize,\n): FixedSizeDecoder<TFrom, TNewSize>;\nexport function resizeDecoder<TDecoder extends AnyDecoder>(\n decoder: TDecoder,\n resize: (size: number) => number,\n): TDecoder;\nexport function resizeDecoder<TDecoder extends AnyDecoder>(\n decoder: TDecoder,\n resize: (size: number) => number,\n): TDecoder {\n if (isFixedSize(decoder)) {\n const fixedSize = resize(decoder.fixedSize);\n if (fixedSize < 0) {\n throw new SolanaError(SOLANA_ERROR__CODECS__EXPECTED_POSITIVE_BYTE_LENGTH, {\n bytesLength: fixedSize,\n codecDescription: 'resizeDecoder',\n });\n }\n return createDecoder({ ...decoder, fixedSize }) as TDecoder;\n }\n return decoder;\n}\n\n/**\n * Updates the size of a given codec.\n */\nexport function resizeCodec<TFrom, TTo extends TFrom, TSize extends number, TNewSize extends number>(\n codec: FixedSizeCodec<TFrom, TTo, TSize>,\n resize: (size: TSize) => TNewSize,\n): FixedSizeCodec<TFrom, TTo, TNewSize>;\nexport function resizeCodec<TCodec extends AnyCodec>(codec: TCodec, resize: (size: number) => number): TCodec;\nexport function resizeCodec<TCodec extends AnyCodec>(codec: TCodec, resize: (size: number) => number): TCodec {\n return combineCodec(resizeEncoder(codec, resize), resizeDecoder(codec, resize)) as TCodec;\n}\n","import { Codec, Decoder, Encoder, Offset } from './codec';\nimport { combineCodec } from './combine-codec';\nimport { offsetDecoder, offsetEncoder } from './offset-codec';\nimport { resizeDecoder, resizeEncoder } from './resize-codec';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyEncoder = Encoder<any>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyDecoder = Decoder<any>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyCodec = Codec<any>;\n\n/**\n * Adds left padding to the given encoder.\n */\nexport function padLeftEncoder<TEncoder extends AnyEncoder>(encoder: TEncoder, offset: Offset): TEncoder {\n return offsetEncoder(\n resizeEncoder(encoder, size => size + offset),\n { preOffset: ({ preOffset }) => preOffset + offset },\n );\n}\n\n/**\n * Adds right padding to the given encoder.\n */\nexport function padRightEncoder<TEncoder extends AnyEncoder>(encoder: TEncoder, offset: Offset): TEncoder {\n return offsetEncoder(\n resizeEncoder(encoder, size => size + offset),\n { postOffset: ({ postOffset }) => postOffset + offset },\n );\n}\n\n/**\n * Adds left padding to the given decoder.\n */\nexport function padLeftDecoder<TDecoder extends AnyDecoder>(decoder: TDecoder, offset: Offset): TDecoder {\n return offsetDecoder(\n resizeDecoder(decoder, size => size + offset),\n { preOffset: ({ preOffset }) => preOffset + offset },\n );\n}\n\n/**\n * Adds right padding to the given decoder.\n */\nexport function padRightDecoder<TDecoder extends AnyDecoder>(decoder: TDecoder, offset: Offset): TDecoder {\n return offsetDecoder(\n resizeDecoder(decoder, size => size + offset),\n { postOffset: ({ postOffset }) => postOffset + offset },\n );\n}\n\n/**\n * Adds left padding to the given codec.\n */\nexport function padLeftCodec<TCodec extends AnyCodec>(codec: TCodec, offset: Offset): TCodec {\n return combineCodec(padLeftEncoder(codec, offset), padLeftDecoder(codec, offset)) as TCodec;\n}\n\n/**\n * Adds right padding to the given codec.\n */\nexport function padRightCodec<TCodec extends AnyCodec>(codec: TCodec, offset: Offset): TCodec {\n return combineCodec(padRightEncoder(codec, offset), padRightDecoder(codec, offset)) as TCodec;\n}\n","import {\n assertIsFixedSize,\n createDecoder,\n createEncoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n} from './codec';\nimport { combineCodec } from './combine-codec';\nimport { ReadonlyUint8Array } from './readonly-uint8array';\n\nfunction copySourceToTargetInReverse(\n source: ReadonlyUint8Array,\n target_WILL_MUTATE: Uint8Array,\n sourceOffset: number,\n sourceLength: number,\n targetOffset: number = 0,\n) {\n while (sourceOffset < --sourceLength) {\n const leftValue = source[sourceOffset];\n target_WILL_MUTATE[sourceOffset + targetOffset] = source[sourceLength];\n target_WILL_MUTATE[sourceLength + targetOffset] = leftValue;\n sourceOffset++;\n }\n if (sourceOffset === sourceLength) {\n target_WILL_MUTATE[sourceOffset + targetOffset] = source[sourceOffset];\n }\n}\n\n/**\n * Reverses the bytes of a fixed-size encoder.\n */\nexport function reverseEncoder<TFrom, TSize extends number>(\n encoder: FixedSizeEncoder<TFrom, TSize>,\n): FixedSizeEncoder<TFrom, TSize> {\n assertIsFixedSize(encoder);\n return createEncoder({\n ...encoder,\n write: (value: TFrom, bytes, offset) => {\n const newOffset = encoder.write(value, bytes, offset);\n copySourceToTargetInReverse(\n bytes /* source */,\n bytes /* target_WILL_MUTATE */,\n offset /* sourceOffset */,\n offset + encoder.fixedSize /* sourceLength */,\n );\n return newOffset;\n },\n });\n}\n\n/**\n * Reverses the bytes of a fixed-size decoder.\n */\nexport function reverseDecoder<TTo, TSize extends number>(\n decoder: FixedSizeDecoder<TTo, TSize>,\n): FixedSizeDecoder<TTo, TSize> {\n assertIsFixedSize(decoder);\n return createDecoder({\n ...decoder,\n read: (bytes, offset) => {\n const reversedBytes = bytes.slice();\n copySourceToTargetInReverse(\n bytes /* source */,\n reversedBytes /* target_WILL_MUTATE */,\n offset /* sourceOffset */,\n offset + decoder.fixedSize /* sourceLength */,\n );\n return decoder.read(reversedBytes, offset);\n },\n });\n}\n\n/**\n * Reverses the bytes of a fixed-size codec.\n */\nexport function reverseCodec<TFrom, TTo extends TFrom, TSize extends number>(\n codec: FixedSizeCodec<TFrom, TTo, TSize>,\n): FixedSizeCodec<TFrom, TTo, TSize> {\n return combineCodec(reverseEncoder(codec), reverseDecoder(codec));\n}\n","import {\n Codec,\n createCodec,\n createDecoder,\n createEncoder,\n Decoder,\n Encoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n isVariableSize,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from './codec';\nimport { ReadonlyUint8Array } from './readonly-uint8array';\n\n/**\n * Converts an encoder A to a encoder B by mapping their values.\n */\nexport function transformEncoder<TOldFrom, TNewFrom, TSize extends number>(\n encoder: FixedSizeEncoder<TOldFrom, TSize>,\n unmap: (value: TNewFrom) => TOldFrom,\n): FixedSizeEncoder<TNewFrom, TSize>;\nexport function transformEncoder<TOldFrom, TNewFrom>(\n encoder: VariableSizeEncoder<TOldFrom>,\n unmap: (value: TNewFrom) => TOldFrom,\n): VariableSizeEncoder<TNewFrom>;\nexport function transformEncoder<TOldFrom, TNewFrom>(\n encoder: Encoder<TOldFrom>,\n unmap: (value: TNewFrom) => TOldFrom,\n): Encoder<TNewFrom>;\nexport function transformEncoder<TOldFrom, TNewFrom>(\n encoder: Encoder<TOldFrom>,\n unmap: (value: TNewFrom) => TOldFrom,\n): Encoder<TNewFrom> {\n return createEncoder({\n ...(isVariableSize(encoder)\n ? { ...encoder, getSizeFromValue: (value: TNewFrom) => encoder.getSizeFromValue(unmap(value)) }\n : encoder),\n write: (value: TNewFrom, bytes, offset) => encoder.write(unmap(value), bytes, offset),\n });\n}\n\n/**\n * Converts an decoder A to a decoder B by mapping their values.\n */\nexport function transformDecoder<TOldTo, TNewTo, TSize extends number>(\n decoder: FixedSizeDecoder<TOldTo, TSize>,\n map: (value: TOldTo, bytes: ReadonlyUint8Array | Uint8Array, offset: number) => TNewTo,\n): FixedSizeDecoder<TNewTo, TSize>;\nexport function transformDecoder<TOldTo, TNewTo>(\n decoder: VariableSizeDecoder<TOldTo>,\n map: (value: TOldTo, bytes: ReadonlyUint8Array | Uint8Array, offset: number) => TNewTo,\n): VariableSizeDecoder<TNewTo>;\nexport function transformDecoder<TOldTo, TNewTo>(\n decoder: Decoder<TOldTo>,\n map: (value: TOldTo, bytes: ReadonlyUint8Array | Uint8Array, offset: number) => TNewTo,\n): Decoder<TNewTo>;\nexport function transformDecoder<TOldTo, TNewTo>(\n decoder: Decoder<TOldTo>,\n map: (value: TOldTo, bytes: ReadonlyUint8Array | Uint8Array, offset: number) => TNewTo,\n): Decoder<TNewTo> {\n return createDecoder({\n ...decoder,\n read: (bytes: ReadonlyUint8Array | Uint8Array, offset) => {\n const [value, newOffset] = decoder.read(bytes, offset);\n return [map(value, bytes, offset), newOffset];\n },\n });\n}\n\n/**\n * Converts a codec A to a codec B by mapping their values.\n */\nexport function transformCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom, TSize extends number>(\n codec: FixedSizeCodec<TOldFrom, TTo, TSize>,\n unmap: (value: TNewFrom) => TOldFrom,\n): FixedSizeCodec<TNewFrom, TTo, TSize>;\nexport function transformCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom>(\n codec: VariableSizeCodec<TOldFrom, TTo>,\n unmap: (value: TNewFrom) => TOldFrom,\n): VariableSizeCodec<TNewFrom, TTo>;\nexport function transformCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom>(\n codec: Codec<TOldFrom, TTo>,\n unmap: (value: TNewFrom) => TOldFrom,\n): Codec<TNewFrom, TTo>;\nexport function transformCodec<\n TOldFrom,\n TNewFrom,\n TOldTo extends TOldFrom,\n TNewTo extends TNewFrom,\n TSize extends number,\n>(\n codec: FixedSizeCodec<TOldFrom, TOldTo, TSize>,\n unmap: (value: TNewFrom) => TOldFrom,\n map: (value: TOldTo, bytes: ReadonlyUint8Array | Uint8Array, offset: number) => TNewTo,\n): FixedSizeCodec<TNewFrom, TNewTo, TSize>;\nexport function transformCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom>(\n codec: VariableSizeCodec<TOldFrom, TOldTo>,\n unmap: (value: TNewFrom) => TOldFrom,\n map: (value: TOldTo, bytes: ReadonlyUint8Array | Uint8Array, offset: number) => TNewTo,\n): VariableSizeCodec<TNewFrom, TNewTo>;\nexport function transformCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom>(\n codec: Codec<TOldFrom, TOldTo>,\n unmap: (value: TNewFrom) => TOldFrom,\n map: (value: TOldTo, bytes: ReadonlyUint8Array | Uint8Array, offset: number) => TNewTo,\n): Codec<TNewFrom, TNewTo>;\nexport function transformCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom>(\n codec: Codec<TOldFrom, TOldTo>,\n unmap: (value: TNewFrom) => TOldFrom,\n map?: (value: TOldTo, bytes: ReadonlyUint8Array | Uint8Array, offset: number) => TNewTo,\n): Codec<TNewFrom, TNewTo> {\n return createCodec({\n ...transformEncoder(codec, unmap),\n read: map ? transformDecoder(codec, map).read : (codec.read as unknown as Decoder<TNewTo>['read']),\n });\n}\n"]}