pw-js-world 0.0.5-dev.24aedef → 0.0.5-dev.46673a2

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.
@@ -0,0 +1,770 @@
1
+ /**
2
+ * CREDIT: Anatoly for making this Buffer Reader so I don't have to!
3
+ * Source: https://github.com/Anatoly03/pixelwalker.js/blob/9bb3c7e39a45006086a2abae8c515599bd3db835/src/util/buffer-reader.ts
4
+ * License: ISC
5
+ */
6
+
7
+ /**
8
+ * Data during the communication in the process is dynamic
9
+ * typed. Every entry is followed by a byte identifying the
10
+ * type, followed by data. The type header is noted by its'
11
+ * 7-bit notation.
12
+ */
13
+ export enum ComponentTypeHeader {
14
+ String = 0,
15
+ Byte = 1,
16
+ Int16 = 2,
17
+ Int32 = 3,
18
+ Int64 = 4,
19
+ Float = 5,
20
+ Double = 6,
21
+ Boolean = 7,
22
+ ByteArray = 8,
23
+ }
24
+
25
+ /**
26
+ * A Buffer reader is a special buffer extension made to perform
27
+ * game-specific tasks in the field of communication.
28
+ *
29
+ * @implements Buffer
30
+ */
31
+ export default class BufferReader {
32
+ private buffer: Buffer;
33
+ private offset: number = 0;
34
+
35
+ /**
36
+ *
37
+ */
38
+ private constructor(buffer: Buffer) {
39
+ this.buffer = buffer;
40
+ }
41
+
42
+ //
43
+ //
44
+ // Static Methods
45
+ //
46
+ //
47
+
48
+ /**
49
+ *
50
+ */
51
+ public static from(from: Uint8Array | Buffer): BufferReader {
52
+ if (from instanceof Buffer) return new BufferReader(from);
53
+ return new BufferReader(Buffer.from(from));
54
+ }
55
+
56
+ /**
57
+ *
58
+ */
59
+ public static alloc(amount: number) {
60
+ return BufferReader.from(Buffer.alloc(amount));
61
+ }
62
+
63
+ //
64
+ //
65
+ // Message Component Types
66
+ //
67
+ //
68
+
69
+ /**
70
+ * @param {string} value
71
+ * @returns {Buffer}
72
+ */
73
+ public static String(value: string = ''): Buffer {
74
+ const stringByteLen = Buffer.byteLength(value);
75
+ const lengthByteCount = this.length7BitInt(stringByteLen);
76
+
77
+ const buffer = BufferReader.alloc(1 + lengthByteCount + stringByteLen);
78
+ buffer.writeUInt8(ComponentTypeHeader.String);
79
+ buffer.write7BitInt(stringByteLen);
80
+ buffer.write(value);
81
+
82
+ return buffer.toBuffer();
83
+ }
84
+
85
+ /**
86
+ * @param {number} value
87
+ * @returns {Buffer}
88
+ */
89
+ public static Byte(value: number = 0): Buffer {
90
+ const buffer = BufferReader.alloc(2);
91
+ buffer.writeUInt8(ComponentTypeHeader.Byte);
92
+ buffer.writeUInt8(value);
93
+ return buffer.toBuffer();
94
+ }
95
+
96
+ /**
97
+ * @param {number} value
98
+ * @returns {Buffer}
99
+ */
100
+ public static Int16(value: number = 0): Buffer {
101
+ const buffer = BufferReader.alloc(3);
102
+ buffer.writeUInt8(ComponentTypeHeader.Int16);
103
+ buffer.writeUInt16LE(value);
104
+ return buffer.toBuffer();
105
+ }
106
+
107
+ /**
108
+ * @param {number} value
109
+ * @returns {Buffer}
110
+ */
111
+ public static Int32(value: number = 0): Buffer {
112
+ const buffer = BufferReader.alloc(5);
113
+ buffer.writeUInt8(ComponentTypeHeader.Int32);
114
+ buffer.writeInt32LE(value);
115
+ return buffer.toBuffer();
116
+ }
117
+
118
+ /**
119
+ * @param {bigint} value
120
+ * @returns {Buffer}
121
+ */
122
+ public static Int64(value: bigint = BigInt(0).valueOf()): Buffer {
123
+ const buffer = BufferReader.alloc(9);
124
+ buffer.writeUInt8(ComponentTypeHeader.Int64);
125
+ buffer.writeBigInt64LE(value);
126
+ return buffer.toBuffer();
127
+ }
128
+
129
+ /**
130
+ * @param {number} value
131
+ * @returns {Buffer}
132
+ */
133
+ public static Float(value: number = 0): Buffer {
134
+ const buffer = BufferReader.alloc(5);
135
+ buffer.writeUInt8(ComponentTypeHeader.Float);
136
+ buffer.writeFloatBE(value);
137
+ return buffer.toBuffer();
138
+ }
139
+
140
+ /**
141
+ * @param {number} value
142
+ * @returns {Buffer}
143
+ */
144
+ public static Double(value: number = 0): Buffer {
145
+ const buffer = BufferReader.alloc(9);
146
+ buffer.writeUInt8(ComponentTypeHeader.Double);
147
+ buffer.writeDoubleBE(value);
148
+ return buffer.toBuffer();
149
+ }
150
+
151
+ /**
152
+ * @param {boolean} value
153
+ * @returns {Buffer}
154
+ */
155
+ public static Boolean(value: boolean = false): Buffer {
156
+ const buffer = BufferReader.alloc(2);
157
+ buffer.writeUInt8(ComponentTypeHeader.Boolean);
158
+ buffer.writeUInt8(value ? 1 : 0);
159
+ return buffer.toBuffer();
160
+ }
161
+
162
+ /**
163
+ * @param {Uint8Array} buffer
164
+ * @returns {Buffer}
165
+ */
166
+ public static ByteArray(buffer: Buffer = Buffer.from([0])): Buffer {
167
+ // const bufferByteLen = Buffer.byteLength(buffer);
168
+
169
+ // const bufLength = Buffer.alloc(length7BitInt(bufferByteLen));
170
+ // write7BitInt(bufLength, bufferByteLen, 0);
171
+
172
+ // return Buffer.concat([Buffer.from([8]), bufLength, buffer]);
173
+
174
+ const stringByteLen = Buffer.byteLength(buffer);
175
+ const lengthByteCount = this.length7BitInt(stringByteLen);
176
+
177
+ const prefix = BufferReader.alloc(1 + lengthByteCount);
178
+ prefix.writeUInt8(ComponentTypeHeader.String);
179
+ prefix.write7BitInt(lengthByteCount);
180
+
181
+ return Buffer.concat([prefix.toBuffer(), buffer]);
182
+ }
183
+
184
+ /**
185
+ * @param {number} value
186
+ * @returns {Buffer}
187
+ */
188
+ public static Magic(value: number): Buffer {
189
+ if (value === undefined) throw new Error('Received undefined magic byte')
190
+ return Buffer.from([value]);
191
+ }
192
+
193
+ /**
194
+ * @param {number} value
195
+ * @returns {Buffer}
196
+ */
197
+ public static Bit7(value: number = 0): Buffer {
198
+ const buffer = BufferReader.alloc(this.length7BitInt(value));
199
+ buffer.write7BitInt(value);
200
+ return buffer.toBuffer();
201
+ }
202
+
203
+ /**
204
+ * @param tt
205
+ * @param value
206
+ */
207
+ public static Dynamic(tt: ComponentTypeHeader, value: boolean | number | bigint | string | Buffer): Buffer {
208
+ switch (tt) {
209
+ case ComponentTypeHeader.String:
210
+ return this.String(value as string);
211
+ case ComponentTypeHeader.Byte:
212
+ return this.Byte(value as number);
213
+ case ComponentTypeHeader.Int16:
214
+ return this.Int16(value as number);
215
+ case ComponentTypeHeader.Int32:
216
+ return this.Int32(value as number);
217
+ case ComponentTypeHeader.Int64:
218
+ return this.Int64(value as bigint);
219
+ case ComponentTypeHeader.Float:
220
+ return this.Float(value as number);
221
+ case ComponentTypeHeader.Double:
222
+ return this.Double(value as number);
223
+ case ComponentTypeHeader.Boolean:
224
+ return this.Boolean(value as boolean);
225
+ case ComponentTypeHeader.ByteArray:
226
+ return this.ByteArray(value as Buffer);
227
+ }
228
+ }
229
+
230
+ //
231
+ //
232
+ // Overrides
233
+ //
234
+ //
235
+
236
+ /**
237
+ *
238
+ */
239
+ public get length() {
240
+ return this.buffer.length - this.offset;
241
+ }
242
+
243
+ /**
244
+ *
245
+ */
246
+ public subarray(start: number = this.offset, end: number = this.length): BufferReader {
247
+ return new BufferReader(this.buffer.subarray(start, this.offset + end));
248
+ }
249
+
250
+ /**
251
+ *
252
+ */
253
+ public write(value: string) {
254
+ return (this.offset = this.buffer.write(value, this.offset));
255
+ }
256
+
257
+ /**
258
+ *
259
+ */
260
+ public writeBigInt64BE(value: bigint) {
261
+ return (this.offset = this.buffer.writeBigInt64BE(value, this.offset));
262
+ }
263
+
264
+ /**
265
+ *
266
+ */
267
+ public writeBigInt64LE(value: bigint) {
268
+ return (this.offset = this.buffer.writeBigInt64LE(value, this.offset));
269
+ }
270
+
271
+ /**
272
+ *
273
+ */
274
+ public writeUInt8(value: number) {
275
+ return (this.offset = this.buffer.writeUInt8(value, this.offset));
276
+ }
277
+
278
+ /**
279
+ *
280
+ */
281
+ public writeUInt16LE(value: number) {
282
+ return (this.offset = this.buffer.writeUInt16LE(value, this.offset));
283
+ }
284
+
285
+ /**
286
+ *
287
+ */
288
+ public writeUInt16BE(value: number) {
289
+ return (this.offset = this.buffer.writeUInt16BE(value, this.offset));
290
+ }
291
+
292
+ /**
293
+ *
294
+ */
295
+ public writeUInt32LE(value: number) {
296
+ return (this.offset = this.buffer.writeUInt32LE(value, this.offset));
297
+ }
298
+
299
+ /**
300
+ *
301
+ */
302
+ public writeUInt32BE(value: number) {
303
+ return (this.offset = this.buffer.writeUInt32BE(value, this.offset));
304
+ }
305
+
306
+ /**
307
+ *
308
+ */
309
+ public writeInt8(value: number) {
310
+ return (this.offset = this.buffer.writeInt8(value, this.offset));
311
+ }
312
+
313
+ /**
314
+ *
315
+ */
316
+ public writeInt16LE(value: number) {
317
+ return (this.offset = this.buffer.writeInt16LE(value, this.offset));
318
+ }
319
+
320
+ /**
321
+ *
322
+ */
323
+ public writeInt16BE(value: number) {
324
+ return (this.offset = this.buffer.writeInt16BE(value, this.offset));
325
+ }
326
+
327
+ /**
328
+ *
329
+ */
330
+ public writeInt32LE(value: number) {
331
+ return (this.offset = this.buffer.writeInt32LE(value, this.offset));
332
+ }
333
+
334
+ /**
335
+ *
336
+ */
337
+ public writeInt32BE(value: number) {
338
+ return (this.offset = this.buffer.writeInt32BE(value, this.offset));
339
+ }
340
+
341
+ /**
342
+ *
343
+ */
344
+ public writeFloatLE(value: number) {
345
+ return (this.offset = this.buffer.writeFloatLE(value, this.offset));
346
+ }
347
+
348
+ /**
349
+ *
350
+ */
351
+ public writeFloatBE(value: number) {
352
+ return (this.offset = this.buffer.writeFloatBE(value, this.offset));
353
+ }
354
+
355
+ /**
356
+ *
357
+ */
358
+ public writeDoubleLE(value: number) {
359
+ return (this.offset = this.buffer.writeDoubleLE(value, this.offset));
360
+ }
361
+
362
+ /**
363
+ *
364
+ */
365
+ public writeDoubleBE(value: number) {
366
+ return (this.offset = this.buffer.writeDoubleBE(value, this.offset));
367
+ }
368
+
369
+ /**
370
+ *
371
+ */
372
+ public readBigUInt64BE() {
373
+ const tmp = this.buffer.readBigUInt64BE(this.offset);
374
+ this.offset += 8;
375
+ return tmp;
376
+ }
377
+
378
+ /**
379
+ *
380
+ */
381
+ public readBigUInt64LE() {
382
+ const tmp = this.buffer.readBigUInt64LE(this.offset);
383
+ this.offset += 8;
384
+ return tmp;
385
+ }
386
+
387
+ /**
388
+ *
389
+ */
390
+ public readBigInt64BE() {
391
+ const tmp = this.buffer.readBigInt64BE(this.offset);
392
+ this.offset += 8;
393
+ return tmp;
394
+ }
395
+
396
+ /**
397
+ *
398
+ */
399
+ public readBigInt64LE() {
400
+ const tmp = this.buffer.readBigInt64LE(this.offset);
401
+ this.offset += 8;
402
+ return tmp;
403
+ }
404
+
405
+ // public readUIntLE() {
406
+ // const tmp = this.buffer.readUIntLE(this.offset);
407
+ // this.offset += 1;
408
+ // return tmp;
409
+ // }
410
+
411
+ // public readUIntBE() {
412
+ // const tmp = this.buffer.readUIntBE(this.offset);
413
+ // this.offset += 1;
414
+ // return tmp;
415
+ // }
416
+
417
+ // public readIntLE() {
418
+ // const tmp = this.buffer.readIntLE(this.offset);
419
+ // this.offset += 1;
420
+ // return tmp;
421
+ // }
422
+
423
+ // public readIntBE() {
424
+ // const tmp = this.buffer.readIntBE(this.offset);
425
+ // this.offset += 1;
426
+ // return tmp;
427
+ // }
428
+
429
+ /**
430
+ *
431
+ */
432
+ public expectUInt8(value: number) {
433
+ const tmp = this.buffer.readUInt8(this.offset);
434
+ this.offset += 1;
435
+ if (tmp !== value) throw new Error(`Expected ${value} but got ${tmp}`);
436
+ return tmp;
437
+ }
438
+
439
+ /**
440
+ *
441
+ */
442
+ public readUInt8() {
443
+ const tmp = this.buffer.readUInt8(this.offset);
444
+ this.offset += 1;
445
+ return tmp;
446
+ }
447
+
448
+ /**
449
+ *
450
+ */
451
+ public readUInt16LE() {
452
+ const tmp = this.buffer.readUInt16LE(this.offset);
453
+ this.offset += 2;
454
+ return tmp;
455
+ }
456
+
457
+ /**
458
+ *
459
+ */
460
+ public readUInt16BE() {
461
+ const tmp = this.buffer.readUInt16BE(this.offset);
462
+ this.offset += 2;
463
+ return tmp;
464
+ }
465
+
466
+ /**
467
+ *
468
+ */
469
+ public readUInt32LE() {
470
+ const tmp = this.buffer.readUInt32LE(this.offset);
471
+ this.offset += 4;
472
+ return tmp;
473
+ }
474
+
475
+ /**
476
+ *
477
+ */
478
+ public readUInt32BE() {
479
+ const tmp = this.buffer.readUInt32BE(this.offset);
480
+ this.offset += 4;
481
+ return tmp;
482
+ }
483
+
484
+ /**
485
+ *
486
+ */
487
+ public readInt8() {
488
+ const tmp = this.buffer.readInt8(this.offset);
489
+ this.offset += 1;
490
+ return tmp;
491
+ }
492
+
493
+ /**
494
+ *
495
+ */
496
+ public readInt16LE() {
497
+ const tmp = this.buffer.readInt16LE(this.offset);
498
+ this.offset += 2;
499
+ return tmp;
500
+ }
501
+
502
+ /**
503
+ *
504
+ */
505
+ public readInt16BE() {
506
+ const tmp = this.buffer.readInt16BE(this.offset);
507
+ this.offset += 2;
508
+ return tmp;
509
+ }
510
+
511
+ /**
512
+ *
513
+ */
514
+ public readInt32LE() {
515
+ const tmp = this.buffer.readInt32LE(this.offset);
516
+ this.offset += 4;
517
+ return tmp;
518
+ }
519
+
520
+ /**
521
+ *
522
+ */
523
+ public readInt32BE() {
524
+ const tmp = this.buffer.readInt32BE(this.offset);
525
+ this.offset += 4;
526
+ return tmp;
527
+ }
528
+
529
+ /**
530
+ *
531
+ */
532
+ public readFloatLE() {
533
+ const tmp = this.buffer.readFloatLE(this.offset);
534
+ this.offset += 4;
535
+ return tmp;
536
+ }
537
+
538
+ /**
539
+ *
540
+ */
541
+ public readFloatBE() {
542
+ const tmp = this.buffer.readFloatBE(this.offset);
543
+ this.offset += 4;
544
+ return tmp;
545
+ }
546
+
547
+ /**
548
+ *
549
+ */
550
+ public readDoubleLE() {
551
+ const tmp = this.buffer.readDoubleLE(this.offset);
552
+ this.offset += 8;
553
+ return tmp;
554
+ }
555
+
556
+ /**
557
+ *
558
+ */
559
+ public readDoubleBE() {
560
+ const tmp = this.buffer.readDoubleBE(this.offset);
561
+ this.offset += 8;
562
+ return tmp;
563
+ }
564
+
565
+ public read(tt: ComponentTypeHeader, littleEndian?: boolean): string | number | bigint | boolean | Buffer;
566
+ public read(tt: ComponentTypeHeader.String, littleEndian?: boolean): string;
567
+ public read(tt: ComponentTypeHeader.Byte, littleEndian?: boolean): number;
568
+ public read(tt: ComponentTypeHeader.Int16, littleEndian?: boolean): number;
569
+ public read(tt: ComponentTypeHeader.Int32, littleEndian?: boolean): number;
570
+ public read(tt: ComponentTypeHeader.Int64, littleEndian?: boolean): bigint;
571
+ public read(tt: ComponentTypeHeader.Float, littleEndian?: boolean): number;
572
+ public read(tt: ComponentTypeHeader.Double, littleEndian?: boolean): number;
573
+ public read(tt: ComponentTypeHeader.Boolean, littleEndian?: boolean): boolean;
574
+ public read(tt: ComponentTypeHeader.ByteArray, littleEndian?: boolean): Buffer;
575
+
576
+ public read(tt: ComponentTypeHeader, little = true): string | number | bigint | boolean | Buffer {
577
+ switch (tt) {
578
+ case ComponentTypeHeader.String:
579
+ return this.readDynamicBuffer().toString("ascii");
580
+ case ComponentTypeHeader.Byte:
581
+ return this.readUInt8();
582
+ case ComponentTypeHeader.Int16:
583
+ return little ? this.readInt16LE() : this.readInt16BE();
584
+ case ComponentTypeHeader.Int32:
585
+ return little ? this.readInt32LE() : this.readInt32BE();
586
+ case ComponentTypeHeader.Int64:
587
+ return little ? this.readBigInt64LE() : this.readBigInt64BE();
588
+ case ComponentTypeHeader.Float:
589
+ return little ? this.readFloatLE() : this.readFloatBE();
590
+ case ComponentTypeHeader.Double:
591
+ return little ? this.readDoubleLE() : this.readDoubleBE();
592
+ case ComponentTypeHeader.Boolean:
593
+ return !!this.readUInt8();
594
+ case ComponentTypeHeader.ByteArray:
595
+ return this.readDynamicBuffer();
596
+ }
597
+ }
598
+
599
+ //
600
+ //
601
+ // Methods
602
+ //
603
+ //
604
+
605
+ /**
606
+ *
607
+ */
608
+ public toBuffer(): Buffer {
609
+ return this.buffer;
610
+ }
611
+
612
+ /**
613
+ * https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer
614
+ */
615
+ public toArrayBuffer(): ArrayBuffer {
616
+ const arrayBuffer = new ArrayBuffer(this.length);
617
+ const view = new Uint8Array(arrayBuffer);
618
+ for (let i = 0; i < this.length; ++i) {
619
+ view[i] = this.buffer[i];
620
+ }
621
+ return arrayBuffer;
622
+ }
623
+
624
+ /**
625
+ *
626
+ */
627
+ public at(idx: number) {
628
+ return this.buffer[idx];
629
+ }
630
+
631
+ /**
632
+ * Advanced the buffer reader by pffset.
633
+ */
634
+ public advanceOffset(relativeOffset = 1): this {
635
+ this.offset += relativeOffset;
636
+ return this;
637
+ }
638
+
639
+ /**
640
+ * This function reads how many bytes a normal integer would take
641
+ * as a 7-bit number
642
+ *
643
+ * 1(000 0001) 0(111 1110)
644
+ */
645
+ public static length7BitInt(value: number): number {
646
+ let size = 0;
647
+ do (value >>= 7), size++;
648
+ while (value > 0);
649
+ return size;
650
+ }
651
+
652
+ /**
653
+ * Reads in an integer in 7-bit notation. A 7-bit integer
654
+ * encoding splits a number into a variable size of bits,
655
+ * in which the first bit is set while bytes are following.
656
+ *
657
+ * @example
658
+ *
659
+ * ```
660
+ * 1111 0000 1010 1010 1000 0000 0000 0001 Reading In
661
+ * ^--- ---- ^--- ---- ^--- ---- ^--- ----
662
+ * 111 0000 010 1010 000 0000 000 0001 Writing Out
663
+ * ```
664
+ */
665
+ public read7BitInt(): number {
666
+ let value = 0,
667
+ shift = 0,
668
+ byte = 0xff;
669
+
670
+ while (byte & 0x80) {
671
+ byte = this.readUInt8();
672
+ value |= (byte & 0x7f) << shift;
673
+ shift += 7;
674
+ }
675
+
676
+ return value;
677
+ }
678
+
679
+ /**
680
+ * Write a normal integer value into buffer at offset.
681
+ */
682
+ public write7BitInt(value: number) {
683
+ while (value >= 128) {
684
+ this.writeUInt8((value & 127) | 128);
685
+ value >>= 7;
686
+ }
687
+ this.writeUInt8(value);
688
+ }
689
+
690
+ /**
691
+ * Reads a dynamic buffer which is prepended by its' length
692
+ * in 7-bit encoding.
693
+ */
694
+ public readDynamicBuffer() {
695
+ const length = this.read7BitInt();
696
+ const value = this.subarray(this.offset, length);
697
+ this.offset += length;
698
+ return value.toBuffer();
699
+ }
700
+
701
+ /**
702
+ * Append a buffer to the current buffer. Asserts the cursor
703
+ * to be at the end of the current buffer.
704
+ */
705
+ public append(buffer: Buffer) {
706
+ if (this.offset !== this.length - 1) throw new Error("Cursor hasn't finished reading yet.");
707
+ this.buffer = Buffer.concat([this.buffer, buffer]);
708
+ return this;
709
+ }
710
+
711
+ /**
712
+ * Keep Deserializing the buffer for typed data until
713
+ * you reach the end of the buffer. Typed data consists
714
+ * of a type indicator in 7-bit-encoding and data following
715
+ * accordingly.
716
+ */
717
+ public deserialize() {
718
+ const arr: (string | number | boolean | Buffer | bigint)[] = [];
719
+
720
+ while (this.offset < this.length) {
721
+ const type = this.read7BitInt();
722
+
723
+ switch (type) {
724
+ case ComponentTypeHeader.String:
725
+ arr.push(this.readDynamicBuffer().toString("ascii"));
726
+ break;
727
+ case ComponentTypeHeader.Byte:
728
+ arr.push(this.readUInt8());
729
+ break;
730
+ case ComponentTypeHeader.Int16: // = Int16 (short)
731
+ arr.push(this.readInt16BE());
732
+ break;
733
+ case ComponentTypeHeader.Int32: // = Int32
734
+ arr.push(this.readInt32BE());
735
+ break;
736
+ case ComponentTypeHeader.Int64:
737
+ arr.push(this.readBigInt64BE());
738
+ break;
739
+ case ComponentTypeHeader.Float:
740
+ arr.push(this.readFloatBE());
741
+ break;
742
+ case ComponentTypeHeader.Double:
743
+ arr.push(this.readDoubleBE());
744
+ break;
745
+ case ComponentTypeHeader.Boolean:
746
+ arr.push(!!this.readUInt8()); // !! is truthy
747
+ break;
748
+ case ComponentTypeHeader.ByteArray:
749
+ arr.push(this.readDynamicBuffer());
750
+ break;
751
+ default:
752
+ throw new Error(`While serializing a buffer for data, an unexpected type 0x${type.toString(16)} was read. Expected one of 0-8`);
753
+ }
754
+ }
755
+
756
+ return arr;
757
+ }
758
+
759
+ [Symbol.for("nodejs.util.inspect.custom")]() {
760
+ let s = '<BufferReader';
761
+ let copy = BufferReader.from(this.buffer);
762
+ copy.offset = this.offset;
763
+
764
+ for (let i = 0; i < 20 && this.offset + i < this.length - 1; i++) {
765
+ s += ' ' + copy.readUInt8().toString(16).padStart(2, '0');
766
+ }
767
+
768
+ return s + '>';
769
+ }
770
+ }