@sachitv/avro-typescript 0.4.2 → 0.5.0

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 (122) hide show
  1. package/esm/avro_reader_sync.d.ts +48 -0
  2. package/esm/avro_reader_sync.js +79 -0
  3. package/esm/avro_writer_sync.d.ts +28 -0
  4. package/esm/avro_writer_sync.js +63 -0
  5. package/esm/internal/collections/circular_buffer.d.ts +4 -3
  6. package/esm/internal/collections/circular_buffer.js +8 -6
  7. package/esm/mod.d.ts +17 -0
  8. package/esm/mod.js +11 -0
  9. package/esm/schemas/base_type.d.ts +8 -0
  10. package/esm/schemas/base_type.js +21 -0
  11. package/esm/schemas/complex/array_type.d.ts +31 -10
  12. package/esm/schemas/complex/array_type.js +129 -39
  13. package/esm/schemas/complex/enum_type.d.ts +24 -7
  14. package/esm/schemas/complex/enum_type.js +61 -15
  15. package/esm/schemas/complex/fixed_type.d.ts +27 -12
  16. package/esm/schemas/complex/fixed_type.js +40 -27
  17. package/esm/schemas/complex/map_type.d.ts +31 -10
  18. package/esm/schemas/complex/map_type.js +88 -47
  19. package/esm/schemas/complex/named_type.d.ts +1 -1
  20. package/esm/schemas/complex/named_type.js +2 -2
  21. package/esm/schemas/complex/record_field.d.ts +62 -0
  22. package/esm/schemas/complex/record_field.js +112 -0
  23. package/esm/schemas/complex/record_resolver.d.ts +45 -0
  24. package/esm/schemas/complex/record_resolver.js +92 -0
  25. package/esm/schemas/complex/record_type.d.ts +45 -70
  26. package/esm/schemas/complex/record_type.js +158 -213
  27. package/esm/schemas/complex/record_writer_cache.d.ts +44 -0
  28. package/esm/schemas/complex/record_writer_cache.js +141 -0
  29. package/esm/schemas/complex/record_writer_strategy.d.ts +123 -0
  30. package/esm/schemas/complex/record_writer_strategy.js +309 -0
  31. package/esm/schemas/complex/union_type.d.ts +23 -11
  32. package/esm/schemas/complex/union_type.js +77 -29
  33. package/esm/schemas/logical/decimal_logical_type.d.ts +1 -1
  34. package/esm/schemas/logical/decimal_logical_type.js +2 -2
  35. package/esm/schemas/logical/duration_logical_type.d.ts +1 -1
  36. package/esm/schemas/logical/duration_logical_type.js +2 -2
  37. package/esm/schemas/logical/logical_type.d.ts +27 -9
  38. package/esm/schemas/logical/logical_type.js +50 -17
  39. package/esm/schemas/logical/temporal_logical_types.d.ts +9 -9
  40. package/esm/schemas/logical/temporal_logical_types.js +18 -18
  41. package/esm/schemas/logical/uuid_logical_type.d.ts +1 -1
  42. package/esm/schemas/logical/uuid_logical_type.js +2 -2
  43. package/esm/schemas/primitive/boolean_type.d.ts +15 -4
  44. package/esm/schemas/primitive/boolean_type.js +22 -7
  45. package/esm/schemas/primitive/bytes_type.d.ts +16 -5
  46. package/esm/schemas/primitive/bytes_type.js +31 -16
  47. package/esm/schemas/primitive/double_type.d.ts +13 -2
  48. package/esm/schemas/primitive/double_type.js +34 -5
  49. package/esm/schemas/primitive/fixed_size_base_type.d.ts +11 -7
  50. package/esm/schemas/primitive/fixed_size_base_type.js +14 -14
  51. package/esm/schemas/primitive/float_type.d.ts +11 -2
  52. package/esm/schemas/primitive/float_type.js +26 -5
  53. package/esm/schemas/primitive/int_type.d.ts +17 -6
  54. package/esm/schemas/primitive/int_type.js +26 -17
  55. package/esm/schemas/primitive/long_type.d.ts +16 -5
  56. package/esm/schemas/primitive/long_type.js +30 -16
  57. package/esm/schemas/primitive/null_type.d.ts +15 -4
  58. package/esm/schemas/primitive/null_type.js +20 -7
  59. package/esm/schemas/primitive/primitive_type.d.ts +2 -0
  60. package/esm/schemas/primitive/primitive_type.js +4 -0
  61. package/esm/schemas/primitive/string_type.d.ts +17 -6
  62. package/esm/schemas/primitive/string_type.js +33 -18
  63. package/esm/schemas/resolver.d.ts +6 -0
  64. package/esm/schemas/type.d.ts +64 -4
  65. package/esm/schemas/type.js +97 -0
  66. package/esm/serialization/avro_file_parser_sync.d.ts +34 -0
  67. package/esm/serialization/avro_file_parser_sync.js +160 -0
  68. package/esm/serialization/avro_file_writer_sync.d.ts +47 -0
  69. package/esm/serialization/avro_file_writer_sync.js +211 -0
  70. package/esm/serialization/buffers/blob_readable_buffer.d.ts +4 -3
  71. package/esm/serialization/buffers/blob_readable_buffer.js +20 -6
  72. package/esm/serialization/buffers/buffer.d.ts +6 -1
  73. package/esm/serialization/buffers/buffer.js +3 -0
  74. package/esm/serialization/buffers/buffer_error.d.ts +28 -0
  75. package/esm/serialization/buffers/buffer_error.js +70 -0
  76. package/esm/serialization/buffers/buffer_sync.d.ts +51 -0
  77. package/esm/serialization/buffers/buffer_sync.js +4 -0
  78. package/esm/serialization/buffers/in_memory_buffer.d.ts +1 -0
  79. package/esm/serialization/buffers/in_memory_buffer.js +7 -5
  80. package/esm/serialization/buffers/in_memory_buffer_sync.d.ts +133 -0
  81. package/esm/serialization/buffers/in_memory_buffer_sync.js +259 -0
  82. package/esm/serialization/counting_writable_tap.d.ts +45 -0
  83. package/esm/serialization/counting_writable_tap.js +90 -0
  84. package/esm/serialization/counting_writable_tap_sync.d.ts +46 -0
  85. package/esm/serialization/counting_writable_tap_sync.js +87 -0
  86. package/esm/serialization/decoders/decoder_null_sync.d.ts +12 -0
  87. package/esm/serialization/decoders/decoder_null_sync.js +13 -0
  88. package/esm/serialization/decoders/decoder_sync.d.ts +15 -0
  89. package/esm/serialization/decoders/decoder_sync.js +1 -0
  90. package/esm/serialization/encoders/encoder_null_sync.d.ts +12 -0
  91. package/esm/serialization/encoders/encoder_null_sync.js +13 -0
  92. package/esm/serialization/encoders/encoder_sync.d.ts +15 -0
  93. package/esm/serialization/encoders/encoder_sync.js +1 -0
  94. package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.d.ts +3 -2
  95. package/esm/serialization/streams/fixed_size_stream_readable_buffer_adapter.js +19 -9
  96. package/esm/serialization/streams/fixed_size_stream_reader_sync.d.ts +25 -0
  97. package/esm/serialization/streams/fixed_size_stream_reader_sync.js +63 -0
  98. package/esm/serialization/streams/fixed_size_stream_writer_sync.d.ts +45 -0
  99. package/esm/serialization/streams/fixed_size_stream_writer_sync.js +98 -0
  100. package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.d.ts +5 -3
  101. package/esm/serialization/streams/forward_only_stream_readable_buffer_adapter.js +18 -8
  102. package/esm/serialization/streams/stream_readable_buffer_adapter.d.ts +3 -2
  103. package/esm/serialization/streams/stream_readable_buffer_adapter.js +19 -6
  104. package/esm/serialization/streams/stream_readable_buffer_adapter_sync.d.ts +36 -0
  105. package/esm/serialization/streams/stream_readable_buffer_adapter_sync.js +93 -0
  106. package/esm/serialization/streams/stream_writable_buffer_adapter_sync.d.ts +45 -0
  107. package/esm/serialization/streams/stream_writable_buffer_adapter_sync.js +78 -0
  108. package/esm/serialization/streams/streams_sync.d.ts +36 -0
  109. package/esm/serialization/streams/streams_sync.js +4 -0
  110. package/esm/serialization/tap.d.ts +15 -32
  111. package/esm/serialization/tap.js +45 -134
  112. package/esm/serialization/tap_sync.d.ts +240 -0
  113. package/esm/serialization/tap_sync.js +545 -0
  114. package/esm/serialization/text_encoding.d.ts +16 -0
  115. package/esm/serialization/text_encoding.js +48 -1
  116. package/esm/type/create_type.d.ts +20 -0
  117. package/esm/type/create_type.js +49 -28
  118. package/package.json +1 -1
  119. package/esm/serialization/manipulate_bytes.d.ts +0 -6
  120. package/esm/serialization/manipulate_bytes.js +0 -13
  121. package/esm/serialization/read_uint_le.d.ts +0 -4
  122. package/esm/serialization/read_uint_le.js +0 -14
@@ -12,14 +12,19 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  var _ReadableTap_lengthHint;
13
13
  import { bigIntToSafeNumber } from "./conversion.js";
14
14
  import { compareUint8Arrays } from "./compare_bytes.js";
15
- import { readUIntLE } from "./read_uint_le.js";
16
- import { invert } from "./manipulate_bytes.js";
17
15
  import { decode, encode } from "./text_encoding.js";
16
+ import { ReadBufferError, WriteBufferError } from "./buffers/buffer_error.js";
18
17
  import { InMemoryReadableBuffer, InMemoryWritableBuffer, } from "./buffers/in_memory_buffer.js";
19
- function assertValidPosition(pos) {
18
+ function assertValidPosition(pos, isWritable = false) {
20
19
  if (!Number.isFinite(pos) || !Number.isInteger(pos) || pos < 0 ||
21
20
  Math.abs(pos) > Number.MAX_SAFE_INTEGER) {
22
- throw new RangeError("Tap position must be an integer within the safe number range.");
21
+ const message = "Tap position must be an integer within the safe number range.";
22
+ if (isWritable) {
23
+ throw new WriteBufferError(message, pos, 0, 0);
24
+ }
25
+ else {
26
+ throw new ReadBufferError(message, pos, 0, 0);
27
+ }
23
28
  }
24
29
  }
25
30
  function isIReadableBuffer(value) {
@@ -94,11 +99,11 @@ export class ReadableTap extends TapBase {
94
99
  */
95
100
  async isValid() {
96
101
  try {
97
- const probe = await this.buffer.read(this.pos, 0);
98
- return probe !== undefined;
102
+ await this.buffer.read(this.pos, 0);
103
+ return true;
99
104
  }
100
105
  catch (err) {
101
- if (err instanceof RangeError) {
106
+ if (err instanceof ReadBufferError) {
102
107
  return false;
103
108
  }
104
109
  throw err;
@@ -119,30 +124,18 @@ export class ReadableTap extends TapBase {
119
124
  return new Uint8Array();
120
125
  }
121
126
  const bytes = await this.buffer.read(0, readLength);
122
- if (bytes) {
123
- return bytes.slice();
124
- }
125
- else {
126
- return new Uint8Array();
127
- }
127
+ return bytes.slice();
128
128
  }
129
129
  /**
130
130
  * Returns the buffer contents from the start up to the current cursor.
131
- * @throws RangeError if the cursor has advanced past the buffer length.
131
+ * @throws ReadBufferError if the cursor has advanced past the buffer length.
132
132
  */
133
133
  async getValue() {
134
- const bytes = await this.buffer.read(0, this.pos);
135
- if (!bytes) {
136
- throw new RangeError("Tap position exceeds buffer length.");
137
- }
138
- return bytes;
134
+ return await this.buffer.read(0, this.pos);
139
135
  }
140
136
  /** Retrieves the byte at the specified position in the buffer. */
141
137
  async getByteAt(position) {
142
138
  const bytes = await this.buffer.read(position, 1);
143
- if (!bytes) {
144
- throw new RangeError("Attempt to read beyond buffer bounds.");
145
- }
146
139
  return bytes[0];
147
140
  }
148
141
  /**
@@ -204,15 +197,12 @@ export class ReadableTap extends TapBase {
204
197
  }
205
198
  /**
206
199
  * Reads a 32-bit little-endian floating point number.
207
- * @throws RangeError if the read would exceed the buffer.
200
+ * @throws ReadBufferError if the read would exceed the buffer.
208
201
  */
209
202
  async readFloat() {
210
203
  const pos = this.pos;
211
204
  this.pos += 4;
212
205
  const bytes = await this.buffer.read(pos, 4);
213
- if (!bytes) {
214
- throw new RangeError("Attempt to read beyond buffer bounds.");
215
- }
216
206
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
217
207
  return view.getFloat32(0, true);
218
208
  }
@@ -224,15 +214,12 @@ export class ReadableTap extends TapBase {
224
214
  }
225
215
  /**
226
216
  * Reads a 64-bit little-endian floating point number.
227
- * @throws RangeError if the read would exceed the buffer.
217
+ * @throws ReadBufferError if the read would exceed the buffer.
228
218
  */
229
219
  async readDouble() {
230
220
  const pos = this.pos;
231
221
  this.pos += 8;
232
222
  const bytes = await this.buffer.read(pos, 8);
233
- if (!bytes) {
234
- throw new RangeError("Attempt to read beyond buffer bounds.");
235
- }
236
223
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
237
224
  return view.getFloat64(0, true);
238
225
  }
@@ -245,16 +232,12 @@ export class ReadableTap extends TapBase {
245
232
  /**
246
233
  * Reads a fixed-length byte sequence into a new buffer.
247
234
  * @param len Number of bytes to read.
248
- * @throws RangeError if the read exceeds the buffer.
235
+ * @throws ReadBufferError if the read exceeds the buffer.
249
236
  */
250
237
  async readFixed(len) {
251
238
  const pos = this.pos;
252
239
  this.pos += len;
253
- const bytes = await this.buffer.read(pos, len);
254
- if (!bytes) {
255
- throw new RangeError("Attempt to read beyond buffer bounds.");
256
- }
257
- return bytes;
240
+ return await this.buffer.read(pos, len);
258
241
  }
259
242
  /**
260
243
  * Skips a fixed-length byte sequence.
@@ -265,7 +248,7 @@ export class ReadableTap extends TapBase {
265
248
  }
266
249
  /**
267
250
  * Reads a length-prefixed byte sequence.
268
- * @throws RangeError if insufficient data remains.
251
+ * @throws ReadBufferError if insufficient data remains.
269
252
  */
270
253
  async readBytes() {
271
254
  const length = bigIntToSafeNumber(await this.readLong(), "readBytes length");
@@ -287,7 +270,7 @@ export class ReadableTap extends TapBase {
287
270
  }
288
271
  /**
289
272
  * Reads a length-prefixed UTF-8 string.
290
- * @throws RangeError when the buffer is exhausted prematurely.
273
+ * @throws ReadBufferError when the buffer is exhausted prematurely.
291
274
  */
292
275
  async readString() {
293
276
  const len = bigIntToSafeNumber(await this.readLong(), "readString length");
@@ -367,38 +350,6 @@ export class ReadableTap extends TapBase {
367
350
  const bytes2 = await tap.readFixed(l2);
368
351
  return compareUint8Arrays(bytes1, bytes2);
369
352
  }
370
- /**
371
- * Decodes the next zig-zag encoded long into an 8-byte two's complement buffer.
372
- */
373
- async unpackLongBytes() {
374
- const res = new Uint8Array(8);
375
- let n = 0;
376
- let i = 0; // Byte index in target buffer.
377
- let j = 6; // Bit offset in current target buffer byte.
378
- let pos = this.pos;
379
- let b = await this.getByteAt(pos++);
380
- const neg = b & 1;
381
- res.fill(0);
382
- // Accumulate the zig-zag decoded bits into the 8-byte buffer, emitting a byte once filled.
383
- n |= (b & 0x7f) >> 1;
384
- while (b & 0x80) {
385
- b = await this.getByteAt(pos++);
386
- n |= (b & 0x7f) << j;
387
- j += 7;
388
- if (j >= 8) {
389
- j -= 8;
390
- res[i++] = n;
391
- n >>= 8;
392
- }
393
- }
394
- res[i] = n;
395
- if (neg) {
396
- // The low bit captured the sign; invert to restore the original negative value.
397
- invert(res, 8);
398
- }
399
- this.pos = pos;
400
- return res;
401
- }
402
353
  }
403
354
  _ReadableTap_lengthHint = new WeakMap();
404
355
  /**
@@ -411,7 +362,7 @@ export class WritableTap extends TapBase {
411
362
  * @param pos The initial position in the buffer (default 0).
412
363
  */
413
364
  constructor(buf, pos = 0) {
414
- assertValidPosition(pos);
365
+ assertValidPosition(pos, true);
415
366
  let buffer;
416
367
  if (buf instanceof ArrayBuffer) {
417
368
  buffer = new InMemoryWritableBuffer(buf, pos);
@@ -456,10 +407,27 @@ export class WritableTap extends TapBase {
456
407
  }
457
408
  /**
458
409
  * Writes a zig-zag encoded 32-bit signed integer.
410
+ * Uses a 32-bit zig-zag + varint path to avoid BigInt casts for performance.
459
411
  * @param n Integer value to write.
460
412
  */
461
413
  async writeInt(n) {
462
- await this.writeLong(BigInt(n));
414
+ if (typeof n !== "number" ||
415
+ !Number.isInteger(n) ||
416
+ n < -2147483648 ||
417
+ n > 2147483647) {
418
+ throw new RangeError(`Value ${n} out of range for Avro int (-2147483648..2147483647)`);
419
+ }
420
+ // Zigzag encode to an unsigned 32-bit integer:
421
+ // (n << 1) ^ (n >> 31)
422
+ let value = ((n << 1) ^ (n >> 31)) >>> 0;
423
+ const buf = new Uint8Array(5);
424
+ let i = 0;
425
+ while (value > 0x7f) {
426
+ buf[i++] = (value & 0x7f) | 0x80;
427
+ value >>>= 7;
428
+ }
429
+ buf[i++] = value;
430
+ await this.appendRawBytes(buf.subarray(0, i));
463
431
  }
464
432
  /**
465
433
  * Writes a zig-zag encoded 64-bit signed integer.
@@ -504,14 +472,12 @@ export class WritableTap extends TapBase {
504
472
  /**
505
473
  * Writes a fixed-length byte sequence from the provided buffer.
506
474
  * @param buf Source buffer to copy from.
507
- * @param len Optional number of bytes to write; defaults to the buffer length.
508
475
  */
509
- async writeFixed(buf, len) {
510
- const length = len ?? buf.length;
511
- if (length === 0) {
476
+ async writeFixed(buf) {
477
+ if (buf.length === 0) {
512
478
  return;
513
479
  }
514
- await this.appendRawBytes(buf.slice(0, length));
480
+ await this.appendRawBytes(buf);
515
481
  }
516
482
  /**
517
483
  * Writes a length-prefixed byte sequence backed by the provided buffer.
@@ -520,7 +486,7 @@ export class WritableTap extends TapBase {
520
486
  async writeBytes(buf) {
521
487
  const len = buf.length;
522
488
  await this.writeLong(BigInt(len));
523
- await this.writeFixed(buf, len);
489
+ await this.writeFixed(buf);
524
490
  }
525
491
  /**
526
492
  * Writes a length-prefixed UTF-8 string.
@@ -530,7 +496,7 @@ export class WritableTap extends TapBase {
530
496
  const encoded = encode(str);
531
497
  const len = encoded.length;
532
498
  await this.writeLong(BigInt(len));
533
- await this.writeFixed(encoded, len);
499
+ await this.writeFixed(encoded);
534
500
  }
535
501
  /**
536
502
  * Writes a binary string as raw bytes without a length prefix.
@@ -547,59 +513,4 @@ export class WritableTap extends TapBase {
547
513
  }
548
514
  await this.appendRawBytes(bytes);
549
515
  }
550
- /**
551
- * Encodes an 8-byte two's complement integer into zig-zag encoded varint bytes.
552
- * @param arr Buffer containing the 8-byte value to encode; reused during processing.
553
- */
554
- async packLongBytes(arr) {
555
- const bufView = new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
556
- const neg = (bufView.getUint8(7) & 0x80) >> 7;
557
- let j = 1;
558
- let k = 0;
559
- let m = 3;
560
- let n;
561
- if (neg) {
562
- // Temporarily convert to magnitude so the zig-zag representation can strip the sign bit.
563
- invert(arr, 8);
564
- n = 1;
565
- }
566
- else {
567
- n = 0;
568
- }
569
- const parts = [
570
- readUIntLE(bufView, 0, 3),
571
- readUIntLE(bufView, 3, 3),
572
- readUIntLE(bufView, 6, 2),
573
- ];
574
- while (m && !parts[--m]) {
575
- /* skip trailing zeros */
576
- }
577
- const emitted = [];
578
- // Pack 24-bit chunks into the zig-zag bucket, flushing continuation bytes as needed.
579
- while (k < m) {
580
- n |= parts[k++] << j;
581
- j += 24;
582
- while (j > 7) {
583
- emitted.push((n & 0x7f) | 0x80);
584
- n >>= 7;
585
- j -= 7;
586
- }
587
- }
588
- n |= parts[m] << j;
589
- do {
590
- const byte = n & 0x7f;
591
- n >>= 7;
592
- if (n) {
593
- emitted.push(byte | 0x80);
594
- }
595
- else {
596
- emitted.push(byte);
597
- }
598
- } while (n);
599
- if (neg) {
600
- // Restore the original negative representation in the supplied buffer.
601
- invert(arr, 8);
602
- }
603
- await this.appendRawBytes(Uint8Array.from(emitted));
604
- }
605
516
  }
@@ -0,0 +1,240 @@
1
+ import { TapBase } from "./tap.js";
2
+ import type { ISyncReadable, ISyncWritable } from "./buffers/buffer_sync.js";
3
+ /**
4
+ * Interface for synchronous readable tap operations in Avro serialization.
5
+ */
6
+ export interface SyncReadableTapLike {
7
+ /** Returns whether the cursor is positioned within the buffer bounds. */
8
+ isValid(): boolean;
9
+ /** Returns whether more data can be read from the current position. */
10
+ canReadMore(): boolean;
11
+ /** Returns the buffer contents from the start up to the current cursor. */
12
+ getValue(): Uint8Array;
13
+ /** Reads the next byte as a boolean value and advances the cursor. */
14
+ readBoolean(): boolean;
15
+ /** Skips a boolean value by advancing the cursor by one byte. */
16
+ skipBoolean(): void;
17
+ /** Reads a variable-length zig-zag encoded 32-bit signed integer. */
18
+ readInt(): number;
19
+ /** Reads a variable-length zig-zag encoded 64-bit signed integer as bigint. */
20
+ readLong(): bigint;
21
+ /** Skips a zig-zag encoded 32-bit integer. */
22
+ skipInt(): void;
23
+ /** Skips a zig-zag encoded 64-bit integer. */
24
+ skipLong(): void;
25
+ /** Reads a 32-bit little-endian floating point number. */
26
+ readFloat(): number;
27
+ /** Skips a 32-bit floating point value by advancing four bytes. */
28
+ skipFloat(): void;
29
+ /** Reads a 64-bit little-endian floating point number. */
30
+ readDouble(): number;
31
+ /** Skips a 64-bit floating point value by advancing eight bytes. */
32
+ skipDouble(): void;
33
+ /** Reads a fixed-length byte sequence. */
34
+ readFixed(len: number): Uint8Array;
35
+ /** Skips a fixed-length byte sequence. */
36
+ skipFixed(len: number): void;
37
+ /** Reads a length-prefixed byte sequence. */
38
+ readBytes(): Uint8Array;
39
+ /** Skips a length-prefixed byte sequence. */
40
+ skipBytes(): void;
41
+ /** Reads a length-prefixed UTF-8 string. */
42
+ readString(): string;
43
+ /** Skips a length-prefixed UTF-8 string. */
44
+ skipString(): void;
45
+ /** Compares boolean values from this tap and another. */
46
+ matchBoolean(tap: SyncReadableTapLike): number;
47
+ /** Compares 32-bit integer values from this tap and another. */
48
+ matchInt(tap: SyncReadableTapLike): number;
49
+ /** Compares 64-bit integer values from this tap and another. */
50
+ matchLong(tap: SyncReadableTapLike): number;
51
+ /** Compares 32-bit float values from this tap and another. */
52
+ matchFloat(tap: SyncReadableTapLike): number;
53
+ /** Compares 64-bit double values from this tap and another. */
54
+ matchDouble(tap: SyncReadableTapLike): number;
55
+ /** Compares fixed-length byte sequences from this tap and another. */
56
+ matchFixed(tap: SyncReadableTapLike, len: number): number;
57
+ /** Compares length-prefixed byte sequences from this tap and another. */
58
+ matchBytes(tap: SyncReadableTapLike): number;
59
+ /** Compares length-prefixed strings from this tap and another. */
60
+ matchString(tap: SyncReadableTapLike): number;
61
+ }
62
+ /**
63
+ * Interface for synchronous writable tap operations in Avro serialization.
64
+ */
65
+ export interface SyncWritableTapLike {
66
+ /** Returns whether the tap is valid for writing. */
67
+ isValid(): boolean;
68
+ /** Writes a boolean value as a single byte. */
69
+ writeBoolean(value: boolean): void;
70
+ /** Writes a zig-zag encoded 32-bit signed integer. */
71
+ writeInt(value: number): void;
72
+ /** Writes a zig-zag encoded 64-bit signed integer. */
73
+ writeLong(value: bigint): void;
74
+ /** Writes a 32-bit little-endian floating point number. */
75
+ writeFloat(value: number): void;
76
+ /** Writes a 64-bit little-endian floating point number. */
77
+ writeDouble(value: number): void;
78
+ /** Writes a fixed-length byte sequence. */
79
+ writeFixed(buf: Uint8Array): void;
80
+ /** Writes a length-prefixed byte sequence. */
81
+ writeBytes(buf: Uint8Array): void;
82
+ /** Writes a length-prefixed UTF-8 string. */
83
+ writeString(str: string): void;
84
+ /** Writes raw binary bytes without a length prefix. */
85
+ writeBinary(str: string, len: number): void;
86
+ }
87
+ /**
88
+ * Synchronous readable tap over an in-memory buffer.
89
+ * Mirrors ReadableTap but without Promises.
90
+ */
91
+ export declare class SyncReadableTap extends TapBase implements SyncReadableTapLike {
92
+ private readonly buffer;
93
+ /**
94
+ * Creates a new SyncReadableTap.
95
+ * @param buf The buffer to read from, either an ArrayBuffer or ISyncReadable.
96
+ * @param pos The initial position in the buffer (default 0).
97
+ */
98
+ constructor(buf: ArrayBuffer | ISyncReadable, pos?: number);
99
+ /** Returns whether the cursor is positioned within the buffer bounds. */
100
+ isValid(): boolean;
101
+ /** Returns whether more data can be read from the current position. */
102
+ canReadMore(): boolean;
103
+ /** Returns the buffer contents from the start up to the current cursor. */
104
+ getValue(): Uint8Array;
105
+ /** Retrieves the byte at the specified position in the buffer. */
106
+ private getByteAt;
107
+ /** Reads the next byte as a boolean value and advances the cursor. */
108
+ readBoolean(): boolean;
109
+ /** Skips a boolean value by advancing the cursor by one byte. */
110
+ skipBoolean(): void;
111
+ /** Reads a variable-length zig-zag encoded 32-bit signed integer. */
112
+ readInt(): number;
113
+ /** Reads a variable-length zig-zag encoded 64-bit signed integer as bigint. */
114
+ readLong(): bigint;
115
+ /** Skips a zig-zag encoded 32-bit integer by delegating to skipLong. */
116
+ skipInt(): void;
117
+ /** Skips a zig-zag encoded 64-bit integer, advancing past continuation bytes. */
118
+ skipLong(): void;
119
+ /** Reads a 32-bit little-endian floating point number. */
120
+ readFloat(): number;
121
+ /** Skips a 32-bit floating point value by advancing four bytes. */
122
+ skipFloat(): void;
123
+ /** Reads a 64-bit little-endian floating point number. */
124
+ readDouble(): number;
125
+ /** Skips a 64-bit floating point value by advancing eight bytes. */
126
+ skipDouble(): void;
127
+ /** Reads a fixed-length byte sequence. */
128
+ readFixed(len: number): Uint8Array;
129
+ /** Skips a fixed-length byte sequence. */
130
+ skipFixed(len: number): void;
131
+ /** Reads a length-prefixed byte sequence. */
132
+ readBytes(): Uint8Array;
133
+ /** Skips a length-prefixed byte sequence. */
134
+ skipBytes(): void;
135
+ /** Reads a length-prefixed UTF-8 string. */
136
+ readString(): string;
137
+ /** Skips a length-prefixed UTF-8 string. */
138
+ skipString(): void;
139
+ /** Compares boolean values from this tap and another. */
140
+ matchBoolean(tap: SyncReadableTapLike): number;
141
+ /** Compares 32-bit integer values from this tap and another. */
142
+ matchInt(tap: SyncReadableTapLike): number;
143
+ /** Compares 64-bit integer values from this tap and another. */
144
+ matchLong(tap: SyncReadableTapLike): number;
145
+ /** Compares 32-bit float values from this tap and another. */
146
+ matchFloat(tap: SyncReadableTapLike): number;
147
+ /** Compares 64-bit double values from this tap and another. */
148
+ matchDouble(tap: SyncReadableTapLike): number;
149
+ /** Compares fixed-length byte sequences from this tap and another. */
150
+ matchFixed(tap: SyncReadableTapLike, len: number): number;
151
+ /** Compares length-prefixed byte sequences from this tap and another. */
152
+ matchBytes(tap: SyncReadableTapLike): number;
153
+ /** Compares length-prefixed strings from this tap and another. */
154
+ matchString(tap: SyncReadableTapLike): number;
155
+ }
156
+ /**
157
+ * Synchronous writable tap over an in-memory buffer (Uint8Array / ArrayBuffer).
158
+ * Mirrors WritableTap but without Promises.
159
+ */
160
+ /**
161
+ * High-performance synchronous writable tap for Avro serialization.
162
+ *
163
+ * Key optimizations:
164
+ * - Buffer pool pattern: Pre-allocated static buffers eliminate GC pressure
165
+ * - Varint encoding: Direct buffer writing avoids intermediate allocations
166
+ * - ASCII string optimization: Fast path for ASCII strings, encodeInto() for Unicode
167
+ * - Static primitive buffers: Reuse buffers for booleans, floats, and doubles
168
+ */
169
+ export declare class SyncWritableTap extends TapBase implements SyncWritableTapLike {
170
+ private readonly buffer;
171
+ private static readonly INT_MIN;
172
+ private static readonly INT_MAX;
173
+ private static readonly floatBuffer;
174
+ private static readonly floatView;
175
+ private static readonly float32Bytes;
176
+ private static readonly float64Bytes;
177
+ private static readonly trueByte;
178
+ private static readonly falseByte;
179
+ private static readonly varintBufferLong;
180
+ private static readonly varintBufferInt;
181
+ private static readonly stringBuffer;
182
+ private static encodedStringBuffer;
183
+ private static binaryBuffer;
184
+ /**
185
+ * Creates a new SyncWritableTap.
186
+ * @param buf The buffer to write to, either an ArrayBuffer or ISyncWritable.
187
+ * @param pos The initial position in the buffer (default 0).
188
+ */
189
+ constructor(buf: ArrayBuffer | ISyncWritable, pos?: number);
190
+ /** Returns whether the tap is valid for writing. */
191
+ isValid(): boolean;
192
+ /** Appends raw bytes to the buffer and advances the cursor. */
193
+ private appendRawBytes;
194
+ /** Writes a boolean value as a single byte. */
195
+ writeBoolean(value: boolean): void;
196
+ /**
197
+ * Writes a 32-bit integer using zigzag + varint encoding.
198
+ * Uses 32-bit math to avoid BigInt casts for performance.
199
+ */
200
+ writeInt(value: number): void;
201
+ /** Encodes a 32-bit integer using zigzag + varint encoding. */
202
+ private writeVarint32ZigZag;
203
+ /**
204
+ * Writes a 64-bit integer using zigzag + varint encoding.
205
+ *
206
+ * Optimizations:
207
+ * - Buffer pool: Uses pre-allocated varintBufferLong to avoid allocations
208
+ * - Direct buffer writing: Encodes into a shared buffer then appends a slice
209
+ *
210
+ * Performance impact: ~3x faster than original array-based approach
211
+ */
212
+ writeLong(value: bigint): void;
213
+ /** Writes a 32-bit little-endian floating point number. */
214
+ writeFloat(value: number): void;
215
+ /** Writes a 64-bit little-endian floating point number. */
216
+ writeDouble(value: number): void;
217
+ /** Writes a fixed-length byte sequence. */
218
+ writeFixed(buf: Uint8Array): void;
219
+ /** Writes a length-prefixed byte sequence. */
220
+ writeBytes(buf: Uint8Array): void;
221
+ /**
222
+ * Writes a UTF-8 encoded string with length prefix.
223
+ *
224
+ * Optimizations:
225
+ * - ASCII fast path: Direct charCodeAt() loop for ASCII strings (most common)
226
+ * - Unicode optimization: Uses TextEncoder.encodeInto() for zero-copy encoding
227
+ * - Buffer pool: Reuses stringBuffer to avoid allocations
228
+ * - Size estimation: Conservative UTF-8 size prediction (2x chars)
229
+ *
230
+ * Performance: ASCII strings ~800ns, Unicode strings ~1µs with encodeInto()
231
+ * Rationale: ASCII dominates real-world usage, Unicode needs zero-copy encoding
232
+ */
233
+ writeString(str: string): void;
234
+ /** Writes raw binary bytes without a length prefix. */
235
+ writeBinary(str: string, len: number): void;
236
+ /** Ensures the encoded string buffer is at least minSize bytes. */
237
+ private static ensureEncodedStringBuffer;
238
+ /** Ensures the binary buffer is at least size bytes. */
239
+ private static ensureBinaryBuffer;
240
+ }