Lines Matching refs:offset

54 function checkBounds(buf, offset, byteLength) {
55 validateNumber(offset, 'offset');
56 if (buf[offset] === undefined || buf[offset + byteLength] === undefined)
57 boundsError(offset, buf.length - (byteLength + 1));
60 function checkInt(value, min, max, buf, offset, byteLength) {
76 checkBounds(buf, offset, byteLength);
82 throw new ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value);
88 throw new ERR_OUT_OF_RANGE(type || 'offset',
94 function readBigUInt64LE(offset = 0) {
95 validateNumber(offset, 'offset');
96 const first = this[offset];
97 const last = this[offset + 7];
99 boundsError(offset, this.length - 8);
102 this[++offset] * 2 ** 8 +
103 this[++offset] * 2 ** 16 +
104 this[++offset] * 2 ** 24;
106 const hi = this[++offset] +
107 this[++offset] * 2 ** 8 +
108 this[++offset] * 2 ** 16 +
114 function readBigUInt64BE(offset = 0) {
115 validateNumber(offset, 'offset');
116 const first = this[offset];
117 const last = this[offset + 7];
119 boundsError(offset, this.length - 8);
122 this[++offset] * 2 ** 16 +
123 this[++offset] * 2 ** 8 +
124 this[++offset];
126 const lo = this[++offset] * 2 ** 24 +
127 this[++offset] * 2 ** 16 +
128 this[++offset] * 2 ** 8 +
134 function readBigInt64LE(offset = 0) {
135 validateNumber(offset, 'offset');
136 const first = this[offset];
137 const last = this[offset + 7];
139 boundsError(offset, this.length - 8);
141 const val = this[offset + 4] +
142 this[offset + 5] * 2 ** 8 +
143 this[offset + 6] * 2 ** 16 +
147 this[++offset] * 2 ** 8 +
148 this[++offset] * 2 ** 16 +
149 this[++offset] * 2 ** 24);
152 function readBigInt64BE(offset = 0) {
153 validateNumber(offset, 'offset');
154 const first = this[offset];
155 const last = this[offset + 7];
157 boundsError(offset, this.length - 8);
160 this[++offset] * 2 ** 16 +
161 this[++offset] * 2 ** 8 +
162 this[++offset];
164 BigInt(this[++offset] * 2 ** 24 +
165 this[++offset] * 2 ** 16 +
166 this[++offset] * 2 ** 8 +
170 function readUIntLE(offset, byteLength) {
171 if (offset === undefined)
172 throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset);
174 return readUInt48LE(this, offset);
176 return readUInt40LE(this, offset);
178 return readUInt24LE(this, offset);
180 return this.readUInt32LE(offset);
182 return this.readUInt16LE(offset);
184 return this.readUInt8(offset);
189 function readUInt48LE(buf, offset = 0) {
190 validateNumber(offset, 'offset');
191 const first = buf[offset];
192 const last = buf[offset + 5];
194 boundsError(offset, buf.length - 6);
197 buf[++offset] * 2 ** 8 +
198 buf[++offset] * 2 ** 16 +
199 buf[++offset] * 2 ** 24 +
200 (buf[++offset] + last * 2 ** 8) * 2 ** 32;
203 function readUInt40LE(buf, offset = 0) {
204 validateNumber(offset, 'offset');
205 const first = buf[offset];
206 const last = buf[offset + 4];
208 boundsError(offset, buf.length - 5);
211 buf[++offset] * 2 ** 8 +
212 buf[++offset] * 2 ** 16 +
213 buf[++offset] * 2 ** 24 +
217 function readUInt32LE(offset = 0) {
218 validateNumber(offset, 'offset');
219 const first = this[offset];
220 const last = this[offset + 3];
222 boundsError(offset, this.length - 4);
225 this[++offset] * 2 ** 8 +
226 this[++offset] * 2 ** 16 +
230 function readUInt24LE(buf, offset = 0) {
231 validateNumber(offset, 'offset');
232 const first = buf[offset];
233 const last = buf[offset + 2];
235 boundsError(offset, buf.length - 3);
237 return first + buf[++offset] * 2 ** 8 + last * 2 ** 16;
240 function readUInt16LE(offset = 0) {
241 validateNumber(offset, 'offset');
242 const first = this[offset];
243 const last = this[offset + 1];
245 boundsError(offset, this.length - 2);
250 function readUInt8(offset = 0) {
251 validateNumber(offset, 'offset');
252 const val = this[offset];
254 boundsError(offset, this.length - 1);
259 function readUIntBE(offset, byteLength) {
260 if (offset === undefined)
261 throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset);
263 return readUInt48BE(this, offset);
265 return readUInt40BE(this, offset);
267 return readUInt24BE(this, offset);
269 return this.readUInt32BE(offset);
271 return this.readUInt16BE(offset);
273 return this.readUInt8(offset);
278 function readUInt48BE(buf, offset = 0) {
279 validateNumber(offset, 'offset');
280 const first = buf[offset];
281 const last = buf[offset + 5];
283 boundsError(offset, buf.length - 6);
285 return (first * 2 ** 8 + buf[++offset]) * 2 ** 32 +
286 buf[++offset] * 2 ** 24 +
287 buf[++offset] * 2 ** 16 +
288 buf[++offset] * 2 ** 8 +
292 function readUInt40BE(buf, offset = 0) {
293 validateNumber(offset, 'offset');
294 const first = buf[offset];
295 const last = buf[offset + 4];
297 boundsError(offset, buf.length - 5);
300 buf[++offset] * 2 ** 24 +
301 buf[++offset] * 2 ** 16 +
302 buf[++offset] * 2 ** 8 +
306 function readUInt32BE(offset = 0) {
307 validateNumber(offset, 'offset');
308 const first = this[offset];
309 const last = this[offset + 3];
311 boundsError(offset, this.length - 4);
314 this[++offset] * 2 ** 16 +
315 this[++offset] * 2 ** 8 +
319 function readUInt24BE(buf, offset = 0) {
320 validateNumber(offset, 'offset');
321 const first = buf[offset];
322 const last = buf[offset + 2];
324 boundsError(offset, buf.length - 3);
326 return first * 2 ** 16 + buf[++offset] * 2 ** 8 + last;
329 function readUInt16BE(offset = 0) {
330 validateNumber(offset, 'offset');
331 const first = this[offset];
332 const last = this[offset + 1];
334 boundsError(offset, this.length - 2);
339 function readIntLE(offset, byteLength) {
340 if (offset === undefined)
341 throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset);
343 return readInt48LE(this, offset);
345 return readInt40LE(this, offset);
347 return readInt24LE(this, offset);
349 return this.readInt32LE(offset);
351 return this.readInt16LE(offset);
353 return this.readInt8(offset);
358 function readInt48LE(buf, offset = 0) {
359 validateNumber(offset, 'offset');
360 const first = buf[offset];
361 const last = buf[offset + 5];
363 boundsError(offset, buf.length - 6);
365 const val = buf[offset + 4] + last * 2 ** 8;
368 buf[++offset] * 2 ** 8 +
369 buf[++offset] * 2 ** 16 +
370 buf[++offset] * 2 ** 24;
373 function readInt40LE(buf, offset = 0) {
374 validateNumber(offset, 'offset');
375 const first = buf[offset];
376 const last = buf[offset + 4];
378 boundsError(offset, buf.length - 5);
382 buf[++offset] * 2 ** 8 +
383 buf[++offset] * 2 ** 16 +
384 buf[++offset] * 2 ** 24;
387 function readInt32LE(offset = 0) {
388 validateNumber(offset, 'offset');
389 const first = this[offset];
390 const last = this[offset + 3];
392 boundsError(offset, this.length - 4);
395 this[++offset] * 2 ** 8 +
396 this[++offset] * 2 ** 16 +
400 function readInt24LE(buf, offset = 0) {
401 validateNumber(offset, 'offset');
402 const first = buf[offset];
403 const last = buf[offset + 2];
405 boundsError(offset, buf.length - 3);
407 const val = first + buf[++offset] * 2 ** 8 + last * 2 ** 16;
411 function readInt16LE(offset = 0) {
412 validateNumber(offset, 'offset');
413 const first = this[offset];
414 const last = this[offset + 1];
416 boundsError(offset, this.length - 2);
422 function readInt8(offset = 0) {
423 validateNumber(offset, 'offset');
424 const val = this[offset];
426 boundsError(offset, this.length - 1);
431 function readIntBE(offset, byteLength) {
432 if (offset === undefined)
433 throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset);
435 return readInt48BE(this, offset);
437 return readInt40BE(this, offset);
439 return readInt24BE(this, offset);
441 return this.readInt32BE(offset);
443 return this.readInt16BE(offset);
445 return this.readInt8(offset);
450 function readInt48BE(buf, offset = 0) {
451 validateNumber(offset, 'offset');
452 const first = buf[offset];
453 const last = buf[offset + 5];
455 boundsError(offset, buf.length - 6);
457 const val = buf[++offset] + first * 2 ** 8;
459 buf[++offset] * 2 ** 24 +
460 buf[++offset] * 2 ** 16 +
461 buf[++offset] * 2 ** 8 +
465 function readInt40BE(buf, offset = 0) {
466 validateNumber(offset, 'offset');
467 const first = buf[offset];
468 const last = buf[offset + 4];
470 boundsError(offset, buf.length - 5);
473 buf[++offset] * 2 ** 24 +
474 buf[++offset] * 2 ** 16 +
475 buf[++offset] * 2 ** 8 +
479 function readInt32BE(offset = 0) {
480 validateNumber(offset, 'offset');
481 const first = this[offset];
482 const last = this[offset + 3];
484 boundsError(offset, this.length - 4);
487 this[++offset] * 2 ** 16 +
488 this[++offset] * 2 ** 8 +
492 function readInt24BE(buf, offset = 0) {
493 validateNumber(offset, 'offset');
494 const first = buf[offset];
495 const last = buf[offset + 2];
497 boundsError(offset, buf.length - 3);
499 const val = first * 2 ** 16 + buf[++offset] * 2 ** 8 + last;
503 function readInt16BE(offset = 0) {
504 validateNumber(offset, 'offset');
505 const first = this[offset];
506 const last = this[offset + 1];
508 boundsError(offset, this.length - 2);
515 function readFloatBackwards(offset = 0) {
516 validateNumber(offset, 'offset');
517 const first = this[offset];
518 const last = this[offset + 3];
520 boundsError(offset, this.length - 4);
523 uInt8Float32Array[2] = this[++offset];
524 uInt8Float32Array[1] = this[++offset];
529 function readFloatForwards(offset = 0) {
530 validateNumber(offset, 'offset');
531 const first = this[offset];
532 const last = this[offset + 3];
534 boundsError(offset, this.length - 4);
537 uInt8Float32Array[1] = this[++offset];
538 uInt8Float32Array[2] = this[++offset];
543 function readDoubleBackwards(offset = 0) {
544 validateNumber(offset, 'offset');
545 const first = this[offset];
546 const last = this[offset + 7];
548 boundsError(offset, this.length - 8);
551 uInt8Float64Array[6] = this[++offset];
552 uInt8Float64Array[5] = this[++offset];
553 uInt8Float64Array[4] = this[++offset];
554 uInt8Float64Array[3] = this[++offset];
555 uInt8Float64Array[2] = this[++offset];
556 uInt8Float64Array[1] = this[++offset];
561 function readDoubleForwards(offset = 0) {
562 validateNumber(offset, 'offset');
563 const first = this[offset];
564 const last = this[offset + 7];
566 boundsError(offset, this.length - 8);
569 uInt8Float64Array[1] = this[++offset];
570 uInt8Float64Array[2] = this[++offset];
571 uInt8Float64Array[3] = this[++offset];
572 uInt8Float64Array[4] = this[++offset];
573 uInt8Float64Array[5] = this[++offset];
574 uInt8Float64Array[6] = this[++offset];
580 function writeBigU_Int64LE(buf, value, offset, min, max) {
581 checkInt(value, min, max, buf, offset, 7);
584 buf[offset++] = lo;
586 buf[offset++] = lo;
588 buf[offset++] = lo;
590 buf[offset++] = lo;
592 buf[offset++] = hi;
594 buf[offset++] = hi;
596 buf[offset++] = hi;
598 buf[offset++] = hi;
599 return offset;
602 function writeBigUInt64LE(value, offset = 0) {
603 return writeBigU_Int64LE(this, value, offset, 0n, 0xffffffffffffffffn);
606 function writeBigU_Int64BE(buf, value, offset, min, max) {
607 checkInt(value, min, max, buf, offset, 7);
610 buf[offset + 7] = lo;
612 buf[offset + 6] = lo;
614 buf[offset + 5] = lo;
616 buf[offset + 4] = lo;
618 buf[offset + 3] = hi;
620 buf[offset + 2] = hi;
622 buf[offset + 1] = hi;
624 buf[offset] = hi;
625 return offset + 8;
628 function writeBigUInt64BE(value, offset = 0) {
629 return writeBigU_Int64BE(this, value, offset, 0n, 0xffffffffffffffffn);
632 function writeBigInt64LE(value, offset = 0) {
634 this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn);
637 function writeBigInt64BE(value, offset = 0) {
639 this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn);
642 function writeUIntLE(value, offset, byteLength) {
644 return writeU_Int48LE(this, value, offset, 0, 0xffffffffffff);
646 return writeU_Int40LE(this, value, offset, 0, 0xffffffffff);
648 return writeU_Int24LE(this, value, offset, 0, 0xffffff);
650 return writeU_Int32LE(this, value, offset, 0, 0xffffffff);
652 return writeU_Int16LE(this, value, offset, 0, 0xffff);
654 return writeU_Int8(this, value, offset, 0, 0xff);
659 function writeU_Int48LE(buf, value, offset, min, max) {
661 checkInt(value, min, max, buf, offset, 5);
664 buf[offset++] = value;
666 buf[offset++] = value;
668 buf[offset++] = value;
670 buf[offset++] = value;
671 buf[offset++] = newVal;
672 buf[offset++] = (newVal >>> 8);
673 return offset;
676 function writeU_Int40LE(buf, value, offset, min, max) {
678 checkInt(value, min, max, buf, offset, 4);
681 buf[offset++] = value;
683 buf[offset++] = value;
685 buf[offset++] = value;
687 buf[offset++] = value;
688 buf[offset++] = MathFloor(newVal * 2 ** -32);
689 return offset;
692 function writeU_Int32LE(buf, value, offset, min, max) {
694 checkInt(value, min, max, buf, offset, 3);
696 buf[offset++] = value;
698 buf[offset++] = value;
700 buf[offset++] = value;
702 buf[offset++] = value;
703 return offset;
706 function writeUInt32LE(value, offset = 0) {
707 return writeU_Int32LE(this, value, offset, 0, 0xffffffff);
710 function writeU_Int24LE(buf, value, offset, min, max) {
712 checkInt(value, min, max, buf, offset, 2);
714 buf[offset++] = value;
716 buf[offset++] = value;
718 buf[offset++] = value;
719 return offset;
722 function writeU_Int16LE(buf, value, offset, min, max) {
724 checkInt(value, min, max, buf, offset, 1);
726 buf[offset++] = value;
727 buf[offset++] = (value >>> 8);
728 return offset;
731 function writeUInt16LE(value, offset = 0) {
732 return writeU_Int16LE(this, value, offset, 0, 0xffff);
735 function writeU_Int8(buf, value, offset, min, max) {
738 validateNumber(offset, 'offset');
742 if (buf[offset] === undefined)
743 boundsError(offset, buf.length - 1);
745 buf[offset] = value;
746 return offset + 1;
749 function writeUInt8(value, offset = 0) {
750 return writeU_Int8(this, value, offset, 0, 0xff);
753 function writeUIntBE(value, offset, byteLength) {
755 return writeU_Int48BE(this, value, offset, 0, 0xffffffffffff);
757 return writeU_Int40BE(this, value, offset, 0, 0xffffffffff);
759 return writeU_Int24BE(this, value, offset, 0, 0xffffff);
761 return writeU_Int32BE(this, value, offset, 0, 0xffffffff);
763 return writeU_Int16BE(this, value, offset, 0, 0xffff);
765 return writeU_Int8(this, value, offset, 0, 0xff);
770 function writeU_Int48BE(buf, value, offset, min, max) {
772 checkInt(value, min, max, buf, offset, 5);
775 buf[offset++] = (newVal >>> 8);
776 buf[offset++] = newVal;
777 buf[offset + 3] = value;
779 buf[offset + 2] = value;
781 buf[offset + 1] = value;
783 buf[offset] = value;
784 return offset + 4;
787 function writeU_Int40BE(buf, value, offset, min, max) {
789 checkInt(value, min, max, buf, offset, 4);
791 buf[offset++] = MathFloor(value * 2 ** -32);
792 buf[offset + 3] = value;
794 buf[offset + 2] = value;
796 buf[offset + 1] = value;
798 buf[offset] = value;
799 return offset + 4;
802 function writeU_Int32BE(buf, value, offset, min, max) {
804 checkInt(value, min, max, buf, offset, 3);
806 buf[offset + 3] = value;
808 buf[offset + 2] = value;
810 buf[offset + 1] = value;
812 buf[offset] = value;
813 return offset + 4;
816 function writeUInt32BE(value, offset = 0) {
817 return writeU_Int32BE(this, value, offset, 0, 0xffffffff);
820 function writeU_Int24BE(buf, value, offset, min, max) {
822 checkInt(value, min, max, buf, offset, 2);
824 buf[offset + 2] = value;
826 buf[offset + 1] = value;
828 buf[offset] = value;
829 return offset + 3;
832 function writeU_Int16BE(buf, value, offset, min, max) {
834 checkInt(value, min, max, buf, offset, 1);
836 buf[offset++] = (value >>> 8);
837 buf[offset++] = value;
838 return offset;
841 function writeUInt16BE(value, offset = 0) {
842 return writeU_Int16BE(this, value, offset, 0, 0xffff);
845 function writeIntLE(value, offset, byteLength) {
847 return writeU_Int48LE(this, value, offset, -0x800000000000, 0x7fffffffffff);
849 return writeU_Int40LE(this, value, offset, -0x8000000000, 0x7fffffffff);
851 return writeU_Int24LE(this, value, offset, -0x800000, 0x7fffff);
853 return writeU_Int32LE(this, value, offset, -0x80000000, 0x7fffffff);
855 return writeU_Int16LE(this, value, offset, -0x8000, 0x7fff);
857 return writeU_Int8(this, value, offset, -0x80, 0x7f);
862 function writeInt32LE(value, offset = 0) {
863 return writeU_Int32LE(this, value, offset, -0x80000000, 0x7fffffff);
866 function writeInt16LE(value, offset = 0) {
867 return writeU_Int16LE(this, value, offset, -0x8000, 0x7fff);
870 function writeInt8(value, offset = 0) {
871 return writeU_Int8(this, value, offset, -0x80, 0x7f);
874 function writeIntBE(value, offset, byteLength) {
876 return writeU_Int48BE(this, value, offset, -0x800000000000, 0x7fffffffffff);
878 return writeU_Int40BE(this, value, offset, -0x8000000000, 0x7fffffffff);
880 return writeU_Int24BE(this, value, offset, -0x800000, 0x7fffff);
882 return writeU_Int32BE(this, value, offset, -0x80000000, 0x7fffffff);
884 return writeU_Int16BE(this, value, offset, -0x8000, 0x7fff);
886 return writeU_Int8(this, value, offset, -0x80, 0x7f);
891 function writeInt32BE(value, offset = 0) {
892 return writeU_Int32BE(this, value, offset, -0x80000000, 0x7fffffff);
895 function writeInt16BE(value, offset = 0) {
896 return writeU_Int16BE(this, value, offset, -0x8000, 0x7fff);
900 function writeDoubleForwards(val, offset = 0) {
902 checkBounds(this, offset, 7);
905 this[offset++] = uInt8Float64Array[0];
906 this[offset++] = uInt8Float64Array[1];
907 this[offset++] = uInt8Float64Array[2];
908 this[offset++] = uInt8Float64Array[3];
909 this[offset++] = uInt8Float64Array[4];
910 this[offset++] = uInt8Float64Array[5];
911 this[offset++] = uInt8Float64Array[6];
912 this[offset++] = uInt8Float64Array[7];
913 return offset;
916 function writeDoubleBackwards(val, offset = 0) {
918 checkBounds(this, offset, 7);
921 this[offset++] = uInt8Float64Array[7];
922 this[offset++] = uInt8Float64Array[6];
923 this[offset++] = uInt8Float64Array[5];
924 this[offset++] = uInt8Float64Array[4];
925 this[offset++] = uInt8Float64Array[3];
926 this[offset++] = uInt8Float64Array[2];
927 this[offset++] = uInt8Float64Array[1];
928 this[offset++] = uInt8Float64Array[0];
929 return offset;
932 function writeFloatForwards(val, offset = 0) {
934 checkBounds(this, offset, 3);
937 this[offset++] = uInt8Float32Array[0];
938 this[offset++] = uInt8Float32Array[1];
939 this[offset++] = uInt8Float32Array[2];
940 this[offset++] = uInt8Float32Array[3];
941 return offset;
944 function writeFloatBackwards(val, offset = 0) {
946 checkBounds(this, offset, 3);
949 this[offset++] = uInt8Float32Array[3];
950 this[offset++] = uInt8Float32Array[2];
951 this[offset++] = uInt8Float32Array[1];
952 this[offset++] = uInt8Float32Array[0];
953 return offset;