11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst { 41cb0ef41Sopenharmony_ci BigInt, 51cb0ef41Sopenharmony_ci Float32Array, 61cb0ef41Sopenharmony_ci Float64Array, 71cb0ef41Sopenharmony_ci MathFloor, 81cb0ef41Sopenharmony_ci Number, 91cb0ef41Sopenharmony_ci Uint8Array, 101cb0ef41Sopenharmony_ci} = primordials; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst { 131cb0ef41Sopenharmony_ci ERR_BUFFER_OUT_OF_BOUNDS, 141cb0ef41Sopenharmony_ci ERR_INVALID_ARG_TYPE, 151cb0ef41Sopenharmony_ci ERR_OUT_OF_RANGE, 161cb0ef41Sopenharmony_ci} = require('internal/errors').codes; 171cb0ef41Sopenharmony_ciconst { validateNumber } = require('internal/validators'); 181cb0ef41Sopenharmony_ciconst { 191cb0ef41Sopenharmony_ci asciiSlice, 201cb0ef41Sopenharmony_ci base64Slice, 211cb0ef41Sopenharmony_ci base64urlSlice, 221cb0ef41Sopenharmony_ci latin1Slice, 231cb0ef41Sopenharmony_ci hexSlice, 241cb0ef41Sopenharmony_ci ucs2Slice, 251cb0ef41Sopenharmony_ci utf8Slice, 261cb0ef41Sopenharmony_ci asciiWrite, 271cb0ef41Sopenharmony_ci base64Write, 281cb0ef41Sopenharmony_ci base64urlWrite, 291cb0ef41Sopenharmony_ci latin1Write, 301cb0ef41Sopenharmony_ci hexWrite, 311cb0ef41Sopenharmony_ci ucs2Write, 321cb0ef41Sopenharmony_ci utf8Write, 331cb0ef41Sopenharmony_ci getZeroFillToggle, 341cb0ef41Sopenharmony_ci} = internalBinding('buffer'); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciconst { 371cb0ef41Sopenharmony_ci privateSymbols: { 381cb0ef41Sopenharmony_ci untransferable_object_private_symbol, 391cb0ef41Sopenharmony_ci }, 401cb0ef41Sopenharmony_ci} = internalBinding('util'); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci// Temporary buffers to convert numbers. 431cb0ef41Sopenharmony_ciconst float32Array = new Float32Array(1); 441cb0ef41Sopenharmony_ciconst uInt8Float32Array = new Uint8Array(float32Array.buffer); 451cb0ef41Sopenharmony_ciconst float64Array = new Float64Array(1); 461cb0ef41Sopenharmony_ciconst uInt8Float64Array = new Uint8Array(float64Array.buffer); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci// Check endianness. 491cb0ef41Sopenharmony_cifloat32Array[0] = -1; // 0xBF800000 501cb0ef41Sopenharmony_ci// Either it is [0, 0, 128, 191] or [191, 128, 0, 0]. It is not possible to 511cb0ef41Sopenharmony_ci// check this with `os.endianness()` because that is determined at compile time. 521cb0ef41Sopenharmony_ciconst bigEndian = uInt8Float32Array[3] === 0; 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_cifunction checkBounds(buf, offset, byteLength) { 551cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 561cb0ef41Sopenharmony_ci if (buf[offset] === undefined || buf[offset + byteLength] === undefined) 571cb0ef41Sopenharmony_ci boundsError(offset, buf.length - (byteLength + 1)); 581cb0ef41Sopenharmony_ci} 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_cifunction checkInt(value, min, max, buf, offset, byteLength) { 611cb0ef41Sopenharmony_ci if (value > max || value < min) { 621cb0ef41Sopenharmony_ci const n = typeof min === 'bigint' ? 'n' : ''; 631cb0ef41Sopenharmony_ci let range; 641cb0ef41Sopenharmony_ci if (byteLength > 3) { 651cb0ef41Sopenharmony_ci if (min === 0 || min === 0n) { 661cb0ef41Sopenharmony_ci range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`; 671cb0ef41Sopenharmony_ci } else { 681cb0ef41Sopenharmony_ci range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and ` + 691cb0ef41Sopenharmony_ci `< 2${n} ** ${(byteLength + 1) * 8 - 1}${n}`; 701cb0ef41Sopenharmony_ci } 711cb0ef41Sopenharmony_ci } else { 721cb0ef41Sopenharmony_ci range = `>= ${min}${n} and <= ${max}${n}`; 731cb0ef41Sopenharmony_ci } 741cb0ef41Sopenharmony_ci throw new ERR_OUT_OF_RANGE('value', range, value); 751cb0ef41Sopenharmony_ci } 761cb0ef41Sopenharmony_ci checkBounds(buf, offset, byteLength); 771cb0ef41Sopenharmony_ci} 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_cifunction boundsError(value, length, type) { 801cb0ef41Sopenharmony_ci if (MathFloor(value) !== value) { 811cb0ef41Sopenharmony_ci validateNumber(value, type); 821cb0ef41Sopenharmony_ci throw new ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value); 831cb0ef41Sopenharmony_ci } 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci if (length < 0) 861cb0ef41Sopenharmony_ci throw new ERR_BUFFER_OUT_OF_BOUNDS(); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci throw new ERR_OUT_OF_RANGE(type || 'offset', 891cb0ef41Sopenharmony_ci `>= ${type ? 1 : 0} and <= ${length}`, 901cb0ef41Sopenharmony_ci value); 911cb0ef41Sopenharmony_ci} 921cb0ef41Sopenharmony_ci 931cb0ef41Sopenharmony_ci// Read integers. 941cb0ef41Sopenharmony_cifunction readBigUInt64LE(offset = 0) { 951cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 961cb0ef41Sopenharmony_ci const first = this[offset]; 971cb0ef41Sopenharmony_ci const last = this[offset + 7]; 981cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 991cb0ef41Sopenharmony_ci boundsError(offset, this.length - 8); 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_ci const lo = first + 1021cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 1031cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 1041cb0ef41Sopenharmony_ci this[++offset] * 2 ** 24; 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ci const hi = this[++offset] + 1071cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 1081cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 1091cb0ef41Sopenharmony_ci last * 2 ** 24; 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci return BigInt(lo) + (BigInt(hi) << 32n); 1121cb0ef41Sopenharmony_ci} 1131cb0ef41Sopenharmony_ci 1141cb0ef41Sopenharmony_cifunction readBigUInt64BE(offset = 0) { 1151cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 1161cb0ef41Sopenharmony_ci const first = this[offset]; 1171cb0ef41Sopenharmony_ci const last = this[offset + 7]; 1181cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 1191cb0ef41Sopenharmony_ci boundsError(offset, this.length - 8); 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci const hi = first * 2 ** 24 + 1221cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 1231cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 1241cb0ef41Sopenharmony_ci this[++offset]; 1251cb0ef41Sopenharmony_ci 1261cb0ef41Sopenharmony_ci const lo = this[++offset] * 2 ** 24 + 1271cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 1281cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 1291cb0ef41Sopenharmony_ci last; 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ci return (BigInt(hi) << 32n) + BigInt(lo); 1321cb0ef41Sopenharmony_ci} 1331cb0ef41Sopenharmony_ci 1341cb0ef41Sopenharmony_cifunction readBigInt64LE(offset = 0) { 1351cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 1361cb0ef41Sopenharmony_ci const first = this[offset]; 1371cb0ef41Sopenharmony_ci const last = this[offset + 7]; 1381cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 1391cb0ef41Sopenharmony_ci boundsError(offset, this.length - 8); 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ci const val = this[offset + 4] + 1421cb0ef41Sopenharmony_ci this[offset + 5] * 2 ** 8 + 1431cb0ef41Sopenharmony_ci this[offset + 6] * 2 ** 16 + 1441cb0ef41Sopenharmony_ci (last << 24); // Overflow 1451cb0ef41Sopenharmony_ci return (BigInt(val) << 32n) + 1461cb0ef41Sopenharmony_ci BigInt(first + 1471cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 1481cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 1491cb0ef41Sopenharmony_ci this[++offset] * 2 ** 24); 1501cb0ef41Sopenharmony_ci} 1511cb0ef41Sopenharmony_ci 1521cb0ef41Sopenharmony_cifunction readBigInt64BE(offset = 0) { 1531cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 1541cb0ef41Sopenharmony_ci const first = this[offset]; 1551cb0ef41Sopenharmony_ci const last = this[offset + 7]; 1561cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 1571cb0ef41Sopenharmony_ci boundsError(offset, this.length - 8); 1581cb0ef41Sopenharmony_ci 1591cb0ef41Sopenharmony_ci const val = (first << 24) + // Overflow 1601cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 1611cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 1621cb0ef41Sopenharmony_ci this[++offset]; 1631cb0ef41Sopenharmony_ci return (BigInt(val) << 32n) + 1641cb0ef41Sopenharmony_ci BigInt(this[++offset] * 2 ** 24 + 1651cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 1661cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 1671cb0ef41Sopenharmony_ci last); 1681cb0ef41Sopenharmony_ci} 1691cb0ef41Sopenharmony_ci 1701cb0ef41Sopenharmony_cifunction readUIntLE(offset, byteLength) { 1711cb0ef41Sopenharmony_ci if (offset === undefined) 1721cb0ef41Sopenharmony_ci throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset); 1731cb0ef41Sopenharmony_ci if (byteLength === 6) 1741cb0ef41Sopenharmony_ci return readUInt48LE(this, offset); 1751cb0ef41Sopenharmony_ci if (byteLength === 5) 1761cb0ef41Sopenharmony_ci return readUInt40LE(this, offset); 1771cb0ef41Sopenharmony_ci if (byteLength === 3) 1781cb0ef41Sopenharmony_ci return readUInt24LE(this, offset); 1791cb0ef41Sopenharmony_ci if (byteLength === 4) 1801cb0ef41Sopenharmony_ci return this.readUInt32LE(offset); 1811cb0ef41Sopenharmony_ci if (byteLength === 2) 1821cb0ef41Sopenharmony_ci return this.readUInt16LE(offset); 1831cb0ef41Sopenharmony_ci if (byteLength === 1) 1841cb0ef41Sopenharmony_ci return this.readUInt8(offset); 1851cb0ef41Sopenharmony_ci 1861cb0ef41Sopenharmony_ci boundsError(byteLength, 6, 'byteLength'); 1871cb0ef41Sopenharmony_ci} 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_cifunction readUInt48LE(buf, offset = 0) { 1901cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 1911cb0ef41Sopenharmony_ci const first = buf[offset]; 1921cb0ef41Sopenharmony_ci const last = buf[offset + 5]; 1931cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 1941cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 6); 1951cb0ef41Sopenharmony_ci 1961cb0ef41Sopenharmony_ci return first + 1971cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 8 + 1981cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 16 + 1991cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 24 + 2001cb0ef41Sopenharmony_ci (buf[++offset] + last * 2 ** 8) * 2 ** 32; 2011cb0ef41Sopenharmony_ci} 2021cb0ef41Sopenharmony_ci 2031cb0ef41Sopenharmony_cifunction readUInt40LE(buf, offset = 0) { 2041cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 2051cb0ef41Sopenharmony_ci const first = buf[offset]; 2061cb0ef41Sopenharmony_ci const last = buf[offset + 4]; 2071cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 2081cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 5); 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ci return first + 2111cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 8 + 2121cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 16 + 2131cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 24 + 2141cb0ef41Sopenharmony_ci last * 2 ** 32; 2151cb0ef41Sopenharmony_ci} 2161cb0ef41Sopenharmony_ci 2171cb0ef41Sopenharmony_cifunction readUInt32LE(offset = 0) { 2181cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 2191cb0ef41Sopenharmony_ci const first = this[offset]; 2201cb0ef41Sopenharmony_ci const last = this[offset + 3]; 2211cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 2221cb0ef41Sopenharmony_ci boundsError(offset, this.length - 4); 2231cb0ef41Sopenharmony_ci 2241cb0ef41Sopenharmony_ci return first + 2251cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 2261cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 2271cb0ef41Sopenharmony_ci last * 2 ** 24; 2281cb0ef41Sopenharmony_ci} 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_cifunction readUInt24LE(buf, offset = 0) { 2311cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 2321cb0ef41Sopenharmony_ci const first = buf[offset]; 2331cb0ef41Sopenharmony_ci const last = buf[offset + 2]; 2341cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 2351cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 3); 2361cb0ef41Sopenharmony_ci 2371cb0ef41Sopenharmony_ci return first + buf[++offset] * 2 ** 8 + last * 2 ** 16; 2381cb0ef41Sopenharmony_ci} 2391cb0ef41Sopenharmony_ci 2401cb0ef41Sopenharmony_cifunction readUInt16LE(offset = 0) { 2411cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 2421cb0ef41Sopenharmony_ci const first = this[offset]; 2431cb0ef41Sopenharmony_ci const last = this[offset + 1]; 2441cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 2451cb0ef41Sopenharmony_ci boundsError(offset, this.length - 2); 2461cb0ef41Sopenharmony_ci 2471cb0ef41Sopenharmony_ci return first + last * 2 ** 8; 2481cb0ef41Sopenharmony_ci} 2491cb0ef41Sopenharmony_ci 2501cb0ef41Sopenharmony_cifunction readUInt8(offset = 0) { 2511cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 2521cb0ef41Sopenharmony_ci const val = this[offset]; 2531cb0ef41Sopenharmony_ci if (val === undefined) 2541cb0ef41Sopenharmony_ci boundsError(offset, this.length - 1); 2551cb0ef41Sopenharmony_ci 2561cb0ef41Sopenharmony_ci return val; 2571cb0ef41Sopenharmony_ci} 2581cb0ef41Sopenharmony_ci 2591cb0ef41Sopenharmony_cifunction readUIntBE(offset, byteLength) { 2601cb0ef41Sopenharmony_ci if (offset === undefined) 2611cb0ef41Sopenharmony_ci throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset); 2621cb0ef41Sopenharmony_ci if (byteLength === 6) 2631cb0ef41Sopenharmony_ci return readUInt48BE(this, offset); 2641cb0ef41Sopenharmony_ci if (byteLength === 5) 2651cb0ef41Sopenharmony_ci return readUInt40BE(this, offset); 2661cb0ef41Sopenharmony_ci if (byteLength === 3) 2671cb0ef41Sopenharmony_ci return readUInt24BE(this, offset); 2681cb0ef41Sopenharmony_ci if (byteLength === 4) 2691cb0ef41Sopenharmony_ci return this.readUInt32BE(offset); 2701cb0ef41Sopenharmony_ci if (byteLength === 2) 2711cb0ef41Sopenharmony_ci return this.readUInt16BE(offset); 2721cb0ef41Sopenharmony_ci if (byteLength === 1) 2731cb0ef41Sopenharmony_ci return this.readUInt8(offset); 2741cb0ef41Sopenharmony_ci 2751cb0ef41Sopenharmony_ci boundsError(byteLength, 6, 'byteLength'); 2761cb0ef41Sopenharmony_ci} 2771cb0ef41Sopenharmony_ci 2781cb0ef41Sopenharmony_cifunction readUInt48BE(buf, offset = 0) { 2791cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 2801cb0ef41Sopenharmony_ci const first = buf[offset]; 2811cb0ef41Sopenharmony_ci const last = buf[offset + 5]; 2821cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 2831cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 6); 2841cb0ef41Sopenharmony_ci 2851cb0ef41Sopenharmony_ci return (first * 2 ** 8 + buf[++offset]) * 2 ** 32 + 2861cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 24 + 2871cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 16 + 2881cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 8 + 2891cb0ef41Sopenharmony_ci last; 2901cb0ef41Sopenharmony_ci} 2911cb0ef41Sopenharmony_ci 2921cb0ef41Sopenharmony_cifunction readUInt40BE(buf, offset = 0) { 2931cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 2941cb0ef41Sopenharmony_ci const first = buf[offset]; 2951cb0ef41Sopenharmony_ci const last = buf[offset + 4]; 2961cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 2971cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 5); 2981cb0ef41Sopenharmony_ci 2991cb0ef41Sopenharmony_ci return first * 2 ** 32 + 3001cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 24 + 3011cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 16 + 3021cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 8 + 3031cb0ef41Sopenharmony_ci last; 3041cb0ef41Sopenharmony_ci} 3051cb0ef41Sopenharmony_ci 3061cb0ef41Sopenharmony_cifunction readUInt32BE(offset = 0) { 3071cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 3081cb0ef41Sopenharmony_ci const first = this[offset]; 3091cb0ef41Sopenharmony_ci const last = this[offset + 3]; 3101cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 3111cb0ef41Sopenharmony_ci boundsError(offset, this.length - 4); 3121cb0ef41Sopenharmony_ci 3131cb0ef41Sopenharmony_ci return first * 2 ** 24 + 3141cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 3151cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 3161cb0ef41Sopenharmony_ci last; 3171cb0ef41Sopenharmony_ci} 3181cb0ef41Sopenharmony_ci 3191cb0ef41Sopenharmony_cifunction readUInt24BE(buf, offset = 0) { 3201cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 3211cb0ef41Sopenharmony_ci const first = buf[offset]; 3221cb0ef41Sopenharmony_ci const last = buf[offset + 2]; 3231cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 3241cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 3); 3251cb0ef41Sopenharmony_ci 3261cb0ef41Sopenharmony_ci return first * 2 ** 16 + buf[++offset] * 2 ** 8 + last; 3271cb0ef41Sopenharmony_ci} 3281cb0ef41Sopenharmony_ci 3291cb0ef41Sopenharmony_cifunction readUInt16BE(offset = 0) { 3301cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 3311cb0ef41Sopenharmony_ci const first = this[offset]; 3321cb0ef41Sopenharmony_ci const last = this[offset + 1]; 3331cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 3341cb0ef41Sopenharmony_ci boundsError(offset, this.length - 2); 3351cb0ef41Sopenharmony_ci 3361cb0ef41Sopenharmony_ci return first * 2 ** 8 + last; 3371cb0ef41Sopenharmony_ci} 3381cb0ef41Sopenharmony_ci 3391cb0ef41Sopenharmony_cifunction readIntLE(offset, byteLength) { 3401cb0ef41Sopenharmony_ci if (offset === undefined) 3411cb0ef41Sopenharmony_ci throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset); 3421cb0ef41Sopenharmony_ci if (byteLength === 6) 3431cb0ef41Sopenharmony_ci return readInt48LE(this, offset); 3441cb0ef41Sopenharmony_ci if (byteLength === 5) 3451cb0ef41Sopenharmony_ci return readInt40LE(this, offset); 3461cb0ef41Sopenharmony_ci if (byteLength === 3) 3471cb0ef41Sopenharmony_ci return readInt24LE(this, offset); 3481cb0ef41Sopenharmony_ci if (byteLength === 4) 3491cb0ef41Sopenharmony_ci return this.readInt32LE(offset); 3501cb0ef41Sopenharmony_ci if (byteLength === 2) 3511cb0ef41Sopenharmony_ci return this.readInt16LE(offset); 3521cb0ef41Sopenharmony_ci if (byteLength === 1) 3531cb0ef41Sopenharmony_ci return this.readInt8(offset); 3541cb0ef41Sopenharmony_ci 3551cb0ef41Sopenharmony_ci boundsError(byteLength, 6, 'byteLength'); 3561cb0ef41Sopenharmony_ci} 3571cb0ef41Sopenharmony_ci 3581cb0ef41Sopenharmony_cifunction readInt48LE(buf, offset = 0) { 3591cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 3601cb0ef41Sopenharmony_ci const first = buf[offset]; 3611cb0ef41Sopenharmony_ci const last = buf[offset + 5]; 3621cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 3631cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 6); 3641cb0ef41Sopenharmony_ci 3651cb0ef41Sopenharmony_ci const val = buf[offset + 4] + last * 2 ** 8; 3661cb0ef41Sopenharmony_ci return (val | (val & 2 ** 15) * 0x1fffe) * 2 ** 32 + 3671cb0ef41Sopenharmony_ci first + 3681cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 8 + 3691cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 16 + 3701cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 24; 3711cb0ef41Sopenharmony_ci} 3721cb0ef41Sopenharmony_ci 3731cb0ef41Sopenharmony_cifunction readInt40LE(buf, offset = 0) { 3741cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 3751cb0ef41Sopenharmony_ci const first = buf[offset]; 3761cb0ef41Sopenharmony_ci const last = buf[offset + 4]; 3771cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 3781cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 5); 3791cb0ef41Sopenharmony_ci 3801cb0ef41Sopenharmony_ci return (last | (last & 2 ** 7) * 0x1fffffe) * 2 ** 32 + 3811cb0ef41Sopenharmony_ci first + 3821cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 8 + 3831cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 16 + 3841cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 24; 3851cb0ef41Sopenharmony_ci} 3861cb0ef41Sopenharmony_ci 3871cb0ef41Sopenharmony_cifunction readInt32LE(offset = 0) { 3881cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 3891cb0ef41Sopenharmony_ci const first = this[offset]; 3901cb0ef41Sopenharmony_ci const last = this[offset + 3]; 3911cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 3921cb0ef41Sopenharmony_ci boundsError(offset, this.length - 4); 3931cb0ef41Sopenharmony_ci 3941cb0ef41Sopenharmony_ci return first + 3951cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 3961cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 3971cb0ef41Sopenharmony_ci (last << 24); // Overflow 3981cb0ef41Sopenharmony_ci} 3991cb0ef41Sopenharmony_ci 4001cb0ef41Sopenharmony_cifunction readInt24LE(buf, offset = 0) { 4011cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 4021cb0ef41Sopenharmony_ci const first = buf[offset]; 4031cb0ef41Sopenharmony_ci const last = buf[offset + 2]; 4041cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 4051cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 3); 4061cb0ef41Sopenharmony_ci 4071cb0ef41Sopenharmony_ci const val = first + buf[++offset] * 2 ** 8 + last * 2 ** 16; 4081cb0ef41Sopenharmony_ci return val | (val & 2 ** 23) * 0x1fe; 4091cb0ef41Sopenharmony_ci} 4101cb0ef41Sopenharmony_ci 4111cb0ef41Sopenharmony_cifunction readInt16LE(offset = 0) { 4121cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 4131cb0ef41Sopenharmony_ci const first = this[offset]; 4141cb0ef41Sopenharmony_ci const last = this[offset + 1]; 4151cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 4161cb0ef41Sopenharmony_ci boundsError(offset, this.length - 2); 4171cb0ef41Sopenharmony_ci 4181cb0ef41Sopenharmony_ci const val = first + last * 2 ** 8; 4191cb0ef41Sopenharmony_ci return val | (val & 2 ** 15) * 0x1fffe; 4201cb0ef41Sopenharmony_ci} 4211cb0ef41Sopenharmony_ci 4221cb0ef41Sopenharmony_cifunction readInt8(offset = 0) { 4231cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 4241cb0ef41Sopenharmony_ci const val = this[offset]; 4251cb0ef41Sopenharmony_ci if (val === undefined) 4261cb0ef41Sopenharmony_ci boundsError(offset, this.length - 1); 4271cb0ef41Sopenharmony_ci 4281cb0ef41Sopenharmony_ci return val | (val & 2 ** 7) * 0x1fffffe; 4291cb0ef41Sopenharmony_ci} 4301cb0ef41Sopenharmony_ci 4311cb0ef41Sopenharmony_cifunction readIntBE(offset, byteLength) { 4321cb0ef41Sopenharmony_ci if (offset === undefined) 4331cb0ef41Sopenharmony_ci throw new ERR_INVALID_ARG_TYPE('offset', 'number', offset); 4341cb0ef41Sopenharmony_ci if (byteLength === 6) 4351cb0ef41Sopenharmony_ci return readInt48BE(this, offset); 4361cb0ef41Sopenharmony_ci if (byteLength === 5) 4371cb0ef41Sopenharmony_ci return readInt40BE(this, offset); 4381cb0ef41Sopenharmony_ci if (byteLength === 3) 4391cb0ef41Sopenharmony_ci return readInt24BE(this, offset); 4401cb0ef41Sopenharmony_ci if (byteLength === 4) 4411cb0ef41Sopenharmony_ci return this.readInt32BE(offset); 4421cb0ef41Sopenharmony_ci if (byteLength === 2) 4431cb0ef41Sopenharmony_ci return this.readInt16BE(offset); 4441cb0ef41Sopenharmony_ci if (byteLength === 1) 4451cb0ef41Sopenharmony_ci return this.readInt8(offset); 4461cb0ef41Sopenharmony_ci 4471cb0ef41Sopenharmony_ci boundsError(byteLength, 6, 'byteLength'); 4481cb0ef41Sopenharmony_ci} 4491cb0ef41Sopenharmony_ci 4501cb0ef41Sopenharmony_cifunction readInt48BE(buf, offset = 0) { 4511cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 4521cb0ef41Sopenharmony_ci const first = buf[offset]; 4531cb0ef41Sopenharmony_ci const last = buf[offset + 5]; 4541cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 4551cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 6); 4561cb0ef41Sopenharmony_ci 4571cb0ef41Sopenharmony_ci const val = buf[++offset] + first * 2 ** 8; 4581cb0ef41Sopenharmony_ci return (val | (val & 2 ** 15) * 0x1fffe) * 2 ** 32 + 4591cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 24 + 4601cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 16 + 4611cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 8 + 4621cb0ef41Sopenharmony_ci last; 4631cb0ef41Sopenharmony_ci} 4641cb0ef41Sopenharmony_ci 4651cb0ef41Sopenharmony_cifunction readInt40BE(buf, offset = 0) { 4661cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 4671cb0ef41Sopenharmony_ci const first = buf[offset]; 4681cb0ef41Sopenharmony_ci const last = buf[offset + 4]; 4691cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 4701cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 5); 4711cb0ef41Sopenharmony_ci 4721cb0ef41Sopenharmony_ci return (first | (first & 2 ** 7) * 0x1fffffe) * 2 ** 32 + 4731cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 24 + 4741cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 16 + 4751cb0ef41Sopenharmony_ci buf[++offset] * 2 ** 8 + 4761cb0ef41Sopenharmony_ci last; 4771cb0ef41Sopenharmony_ci} 4781cb0ef41Sopenharmony_ci 4791cb0ef41Sopenharmony_cifunction readInt32BE(offset = 0) { 4801cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 4811cb0ef41Sopenharmony_ci const first = this[offset]; 4821cb0ef41Sopenharmony_ci const last = this[offset + 3]; 4831cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 4841cb0ef41Sopenharmony_ci boundsError(offset, this.length - 4); 4851cb0ef41Sopenharmony_ci 4861cb0ef41Sopenharmony_ci return (first << 24) + // Overflow 4871cb0ef41Sopenharmony_ci this[++offset] * 2 ** 16 + 4881cb0ef41Sopenharmony_ci this[++offset] * 2 ** 8 + 4891cb0ef41Sopenharmony_ci last; 4901cb0ef41Sopenharmony_ci} 4911cb0ef41Sopenharmony_ci 4921cb0ef41Sopenharmony_cifunction readInt24BE(buf, offset = 0) { 4931cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 4941cb0ef41Sopenharmony_ci const first = buf[offset]; 4951cb0ef41Sopenharmony_ci const last = buf[offset + 2]; 4961cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 4971cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 3); 4981cb0ef41Sopenharmony_ci 4991cb0ef41Sopenharmony_ci const val = first * 2 ** 16 + buf[++offset] * 2 ** 8 + last; 5001cb0ef41Sopenharmony_ci return val | (val & 2 ** 23) * 0x1fe; 5011cb0ef41Sopenharmony_ci} 5021cb0ef41Sopenharmony_ci 5031cb0ef41Sopenharmony_cifunction readInt16BE(offset = 0) { 5041cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 5051cb0ef41Sopenharmony_ci const first = this[offset]; 5061cb0ef41Sopenharmony_ci const last = this[offset + 1]; 5071cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 5081cb0ef41Sopenharmony_ci boundsError(offset, this.length - 2); 5091cb0ef41Sopenharmony_ci 5101cb0ef41Sopenharmony_ci const val = first * 2 ** 8 + last; 5111cb0ef41Sopenharmony_ci return val | (val & 2 ** 15) * 0x1fffe; 5121cb0ef41Sopenharmony_ci} 5131cb0ef41Sopenharmony_ci 5141cb0ef41Sopenharmony_ci// Read floats 5151cb0ef41Sopenharmony_cifunction readFloatBackwards(offset = 0) { 5161cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 5171cb0ef41Sopenharmony_ci const first = this[offset]; 5181cb0ef41Sopenharmony_ci const last = this[offset + 3]; 5191cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 5201cb0ef41Sopenharmony_ci boundsError(offset, this.length - 4); 5211cb0ef41Sopenharmony_ci 5221cb0ef41Sopenharmony_ci uInt8Float32Array[3] = first; 5231cb0ef41Sopenharmony_ci uInt8Float32Array[2] = this[++offset]; 5241cb0ef41Sopenharmony_ci uInt8Float32Array[1] = this[++offset]; 5251cb0ef41Sopenharmony_ci uInt8Float32Array[0] = last; 5261cb0ef41Sopenharmony_ci return float32Array[0]; 5271cb0ef41Sopenharmony_ci} 5281cb0ef41Sopenharmony_ci 5291cb0ef41Sopenharmony_cifunction readFloatForwards(offset = 0) { 5301cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 5311cb0ef41Sopenharmony_ci const first = this[offset]; 5321cb0ef41Sopenharmony_ci const last = this[offset + 3]; 5331cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 5341cb0ef41Sopenharmony_ci boundsError(offset, this.length - 4); 5351cb0ef41Sopenharmony_ci 5361cb0ef41Sopenharmony_ci uInt8Float32Array[0] = first; 5371cb0ef41Sopenharmony_ci uInt8Float32Array[1] = this[++offset]; 5381cb0ef41Sopenharmony_ci uInt8Float32Array[2] = this[++offset]; 5391cb0ef41Sopenharmony_ci uInt8Float32Array[3] = last; 5401cb0ef41Sopenharmony_ci return float32Array[0]; 5411cb0ef41Sopenharmony_ci} 5421cb0ef41Sopenharmony_ci 5431cb0ef41Sopenharmony_cifunction readDoubleBackwards(offset = 0) { 5441cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 5451cb0ef41Sopenharmony_ci const first = this[offset]; 5461cb0ef41Sopenharmony_ci const last = this[offset + 7]; 5471cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 5481cb0ef41Sopenharmony_ci boundsError(offset, this.length - 8); 5491cb0ef41Sopenharmony_ci 5501cb0ef41Sopenharmony_ci uInt8Float64Array[7] = first; 5511cb0ef41Sopenharmony_ci uInt8Float64Array[6] = this[++offset]; 5521cb0ef41Sopenharmony_ci uInt8Float64Array[5] = this[++offset]; 5531cb0ef41Sopenharmony_ci uInt8Float64Array[4] = this[++offset]; 5541cb0ef41Sopenharmony_ci uInt8Float64Array[3] = this[++offset]; 5551cb0ef41Sopenharmony_ci uInt8Float64Array[2] = this[++offset]; 5561cb0ef41Sopenharmony_ci uInt8Float64Array[1] = this[++offset]; 5571cb0ef41Sopenharmony_ci uInt8Float64Array[0] = last; 5581cb0ef41Sopenharmony_ci return float64Array[0]; 5591cb0ef41Sopenharmony_ci} 5601cb0ef41Sopenharmony_ci 5611cb0ef41Sopenharmony_cifunction readDoubleForwards(offset = 0) { 5621cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 5631cb0ef41Sopenharmony_ci const first = this[offset]; 5641cb0ef41Sopenharmony_ci const last = this[offset + 7]; 5651cb0ef41Sopenharmony_ci if (first === undefined || last === undefined) 5661cb0ef41Sopenharmony_ci boundsError(offset, this.length - 8); 5671cb0ef41Sopenharmony_ci 5681cb0ef41Sopenharmony_ci uInt8Float64Array[0] = first; 5691cb0ef41Sopenharmony_ci uInt8Float64Array[1] = this[++offset]; 5701cb0ef41Sopenharmony_ci uInt8Float64Array[2] = this[++offset]; 5711cb0ef41Sopenharmony_ci uInt8Float64Array[3] = this[++offset]; 5721cb0ef41Sopenharmony_ci uInt8Float64Array[4] = this[++offset]; 5731cb0ef41Sopenharmony_ci uInt8Float64Array[5] = this[++offset]; 5741cb0ef41Sopenharmony_ci uInt8Float64Array[6] = this[++offset]; 5751cb0ef41Sopenharmony_ci uInt8Float64Array[7] = last; 5761cb0ef41Sopenharmony_ci return float64Array[0]; 5771cb0ef41Sopenharmony_ci} 5781cb0ef41Sopenharmony_ci 5791cb0ef41Sopenharmony_ci// Write integers. 5801cb0ef41Sopenharmony_cifunction writeBigU_Int64LE(buf, value, offset, min, max) { 5811cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 7); 5821cb0ef41Sopenharmony_ci 5831cb0ef41Sopenharmony_ci let lo = Number(value & 0xffffffffn); 5841cb0ef41Sopenharmony_ci buf[offset++] = lo; 5851cb0ef41Sopenharmony_ci lo = lo >> 8; 5861cb0ef41Sopenharmony_ci buf[offset++] = lo; 5871cb0ef41Sopenharmony_ci lo = lo >> 8; 5881cb0ef41Sopenharmony_ci buf[offset++] = lo; 5891cb0ef41Sopenharmony_ci lo = lo >> 8; 5901cb0ef41Sopenharmony_ci buf[offset++] = lo; 5911cb0ef41Sopenharmony_ci let hi = Number(value >> 32n & 0xffffffffn); 5921cb0ef41Sopenharmony_ci buf[offset++] = hi; 5931cb0ef41Sopenharmony_ci hi = hi >> 8; 5941cb0ef41Sopenharmony_ci buf[offset++] = hi; 5951cb0ef41Sopenharmony_ci hi = hi >> 8; 5961cb0ef41Sopenharmony_ci buf[offset++] = hi; 5971cb0ef41Sopenharmony_ci hi = hi >> 8; 5981cb0ef41Sopenharmony_ci buf[offset++] = hi; 5991cb0ef41Sopenharmony_ci return offset; 6001cb0ef41Sopenharmony_ci} 6011cb0ef41Sopenharmony_ci 6021cb0ef41Sopenharmony_cifunction writeBigUInt64LE(value, offset = 0) { 6031cb0ef41Sopenharmony_ci return writeBigU_Int64LE(this, value, offset, 0n, 0xffffffffffffffffn); 6041cb0ef41Sopenharmony_ci} 6051cb0ef41Sopenharmony_ci 6061cb0ef41Sopenharmony_cifunction writeBigU_Int64BE(buf, value, offset, min, max) { 6071cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 7); 6081cb0ef41Sopenharmony_ci 6091cb0ef41Sopenharmony_ci let lo = Number(value & 0xffffffffn); 6101cb0ef41Sopenharmony_ci buf[offset + 7] = lo; 6111cb0ef41Sopenharmony_ci lo = lo >> 8; 6121cb0ef41Sopenharmony_ci buf[offset + 6] = lo; 6131cb0ef41Sopenharmony_ci lo = lo >> 8; 6141cb0ef41Sopenharmony_ci buf[offset + 5] = lo; 6151cb0ef41Sopenharmony_ci lo = lo >> 8; 6161cb0ef41Sopenharmony_ci buf[offset + 4] = lo; 6171cb0ef41Sopenharmony_ci let hi = Number(value >> 32n & 0xffffffffn); 6181cb0ef41Sopenharmony_ci buf[offset + 3] = hi; 6191cb0ef41Sopenharmony_ci hi = hi >> 8; 6201cb0ef41Sopenharmony_ci buf[offset + 2] = hi; 6211cb0ef41Sopenharmony_ci hi = hi >> 8; 6221cb0ef41Sopenharmony_ci buf[offset + 1] = hi; 6231cb0ef41Sopenharmony_ci hi = hi >> 8; 6241cb0ef41Sopenharmony_ci buf[offset] = hi; 6251cb0ef41Sopenharmony_ci return offset + 8; 6261cb0ef41Sopenharmony_ci} 6271cb0ef41Sopenharmony_ci 6281cb0ef41Sopenharmony_cifunction writeBigUInt64BE(value, offset = 0) { 6291cb0ef41Sopenharmony_ci return writeBigU_Int64BE(this, value, offset, 0n, 0xffffffffffffffffn); 6301cb0ef41Sopenharmony_ci} 6311cb0ef41Sopenharmony_ci 6321cb0ef41Sopenharmony_cifunction writeBigInt64LE(value, offset = 0) { 6331cb0ef41Sopenharmony_ci return writeBigU_Int64LE( 6341cb0ef41Sopenharmony_ci this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn); 6351cb0ef41Sopenharmony_ci} 6361cb0ef41Sopenharmony_ci 6371cb0ef41Sopenharmony_cifunction writeBigInt64BE(value, offset = 0) { 6381cb0ef41Sopenharmony_ci return writeBigU_Int64BE( 6391cb0ef41Sopenharmony_ci this, value, offset, -0x8000000000000000n, 0x7fffffffffffffffn); 6401cb0ef41Sopenharmony_ci} 6411cb0ef41Sopenharmony_ci 6421cb0ef41Sopenharmony_cifunction writeUIntLE(value, offset, byteLength) { 6431cb0ef41Sopenharmony_ci if (byteLength === 6) 6441cb0ef41Sopenharmony_ci return writeU_Int48LE(this, value, offset, 0, 0xffffffffffff); 6451cb0ef41Sopenharmony_ci if (byteLength === 5) 6461cb0ef41Sopenharmony_ci return writeU_Int40LE(this, value, offset, 0, 0xffffffffff); 6471cb0ef41Sopenharmony_ci if (byteLength === 3) 6481cb0ef41Sopenharmony_ci return writeU_Int24LE(this, value, offset, 0, 0xffffff); 6491cb0ef41Sopenharmony_ci if (byteLength === 4) 6501cb0ef41Sopenharmony_ci return writeU_Int32LE(this, value, offset, 0, 0xffffffff); 6511cb0ef41Sopenharmony_ci if (byteLength === 2) 6521cb0ef41Sopenharmony_ci return writeU_Int16LE(this, value, offset, 0, 0xffff); 6531cb0ef41Sopenharmony_ci if (byteLength === 1) 6541cb0ef41Sopenharmony_ci return writeU_Int8(this, value, offset, 0, 0xff); 6551cb0ef41Sopenharmony_ci 6561cb0ef41Sopenharmony_ci boundsError(byteLength, 6, 'byteLength'); 6571cb0ef41Sopenharmony_ci} 6581cb0ef41Sopenharmony_ci 6591cb0ef41Sopenharmony_cifunction writeU_Int48LE(buf, value, offset, min, max) { 6601cb0ef41Sopenharmony_ci value = +value; 6611cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 5); 6621cb0ef41Sopenharmony_ci 6631cb0ef41Sopenharmony_ci const newVal = MathFloor(value * 2 ** -32); 6641cb0ef41Sopenharmony_ci buf[offset++] = value; 6651cb0ef41Sopenharmony_ci value = value >>> 8; 6661cb0ef41Sopenharmony_ci buf[offset++] = value; 6671cb0ef41Sopenharmony_ci value = value >>> 8; 6681cb0ef41Sopenharmony_ci buf[offset++] = value; 6691cb0ef41Sopenharmony_ci value = value >>> 8; 6701cb0ef41Sopenharmony_ci buf[offset++] = value; 6711cb0ef41Sopenharmony_ci buf[offset++] = newVal; 6721cb0ef41Sopenharmony_ci buf[offset++] = (newVal >>> 8); 6731cb0ef41Sopenharmony_ci return offset; 6741cb0ef41Sopenharmony_ci} 6751cb0ef41Sopenharmony_ci 6761cb0ef41Sopenharmony_cifunction writeU_Int40LE(buf, value, offset, min, max) { 6771cb0ef41Sopenharmony_ci value = +value; 6781cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 4); 6791cb0ef41Sopenharmony_ci 6801cb0ef41Sopenharmony_ci const newVal = value; 6811cb0ef41Sopenharmony_ci buf[offset++] = value; 6821cb0ef41Sopenharmony_ci value = value >>> 8; 6831cb0ef41Sopenharmony_ci buf[offset++] = value; 6841cb0ef41Sopenharmony_ci value = value >>> 8; 6851cb0ef41Sopenharmony_ci buf[offset++] = value; 6861cb0ef41Sopenharmony_ci value = value >>> 8; 6871cb0ef41Sopenharmony_ci buf[offset++] = value; 6881cb0ef41Sopenharmony_ci buf[offset++] = MathFloor(newVal * 2 ** -32); 6891cb0ef41Sopenharmony_ci return offset; 6901cb0ef41Sopenharmony_ci} 6911cb0ef41Sopenharmony_ci 6921cb0ef41Sopenharmony_cifunction writeU_Int32LE(buf, value, offset, min, max) { 6931cb0ef41Sopenharmony_ci value = +value; 6941cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 3); 6951cb0ef41Sopenharmony_ci 6961cb0ef41Sopenharmony_ci buf[offset++] = value; 6971cb0ef41Sopenharmony_ci value = value >>> 8; 6981cb0ef41Sopenharmony_ci buf[offset++] = value; 6991cb0ef41Sopenharmony_ci value = value >>> 8; 7001cb0ef41Sopenharmony_ci buf[offset++] = value; 7011cb0ef41Sopenharmony_ci value = value >>> 8; 7021cb0ef41Sopenharmony_ci buf[offset++] = value; 7031cb0ef41Sopenharmony_ci return offset; 7041cb0ef41Sopenharmony_ci} 7051cb0ef41Sopenharmony_ci 7061cb0ef41Sopenharmony_cifunction writeUInt32LE(value, offset = 0) { 7071cb0ef41Sopenharmony_ci return writeU_Int32LE(this, value, offset, 0, 0xffffffff); 7081cb0ef41Sopenharmony_ci} 7091cb0ef41Sopenharmony_ci 7101cb0ef41Sopenharmony_cifunction writeU_Int24LE(buf, value, offset, min, max) { 7111cb0ef41Sopenharmony_ci value = +value; 7121cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 2); 7131cb0ef41Sopenharmony_ci 7141cb0ef41Sopenharmony_ci buf[offset++] = value; 7151cb0ef41Sopenharmony_ci value = value >>> 8; 7161cb0ef41Sopenharmony_ci buf[offset++] = value; 7171cb0ef41Sopenharmony_ci value = value >>> 8; 7181cb0ef41Sopenharmony_ci buf[offset++] = value; 7191cb0ef41Sopenharmony_ci return offset; 7201cb0ef41Sopenharmony_ci} 7211cb0ef41Sopenharmony_ci 7221cb0ef41Sopenharmony_cifunction writeU_Int16LE(buf, value, offset, min, max) { 7231cb0ef41Sopenharmony_ci value = +value; 7241cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 1); 7251cb0ef41Sopenharmony_ci 7261cb0ef41Sopenharmony_ci buf[offset++] = value; 7271cb0ef41Sopenharmony_ci buf[offset++] = (value >>> 8); 7281cb0ef41Sopenharmony_ci return offset; 7291cb0ef41Sopenharmony_ci} 7301cb0ef41Sopenharmony_ci 7311cb0ef41Sopenharmony_cifunction writeUInt16LE(value, offset = 0) { 7321cb0ef41Sopenharmony_ci return writeU_Int16LE(this, value, offset, 0, 0xffff); 7331cb0ef41Sopenharmony_ci} 7341cb0ef41Sopenharmony_ci 7351cb0ef41Sopenharmony_cifunction writeU_Int8(buf, value, offset, min, max) { 7361cb0ef41Sopenharmony_ci value = +value; 7371cb0ef41Sopenharmony_ci // `checkInt()` can not be used here because it checks two entries. 7381cb0ef41Sopenharmony_ci validateNumber(offset, 'offset'); 7391cb0ef41Sopenharmony_ci if (value > max || value < min) { 7401cb0ef41Sopenharmony_ci throw new ERR_OUT_OF_RANGE('value', `>= ${min} and <= ${max}`, value); 7411cb0ef41Sopenharmony_ci } 7421cb0ef41Sopenharmony_ci if (buf[offset] === undefined) 7431cb0ef41Sopenharmony_ci boundsError(offset, buf.length - 1); 7441cb0ef41Sopenharmony_ci 7451cb0ef41Sopenharmony_ci buf[offset] = value; 7461cb0ef41Sopenharmony_ci return offset + 1; 7471cb0ef41Sopenharmony_ci} 7481cb0ef41Sopenharmony_ci 7491cb0ef41Sopenharmony_cifunction writeUInt8(value, offset = 0) { 7501cb0ef41Sopenharmony_ci return writeU_Int8(this, value, offset, 0, 0xff); 7511cb0ef41Sopenharmony_ci} 7521cb0ef41Sopenharmony_ci 7531cb0ef41Sopenharmony_cifunction writeUIntBE(value, offset, byteLength) { 7541cb0ef41Sopenharmony_ci if (byteLength === 6) 7551cb0ef41Sopenharmony_ci return writeU_Int48BE(this, value, offset, 0, 0xffffffffffff); 7561cb0ef41Sopenharmony_ci if (byteLength === 5) 7571cb0ef41Sopenharmony_ci return writeU_Int40BE(this, value, offset, 0, 0xffffffffff); 7581cb0ef41Sopenharmony_ci if (byteLength === 3) 7591cb0ef41Sopenharmony_ci return writeU_Int24BE(this, value, offset, 0, 0xffffff); 7601cb0ef41Sopenharmony_ci if (byteLength === 4) 7611cb0ef41Sopenharmony_ci return writeU_Int32BE(this, value, offset, 0, 0xffffffff); 7621cb0ef41Sopenharmony_ci if (byteLength === 2) 7631cb0ef41Sopenharmony_ci return writeU_Int16BE(this, value, offset, 0, 0xffff); 7641cb0ef41Sopenharmony_ci if (byteLength === 1) 7651cb0ef41Sopenharmony_ci return writeU_Int8(this, value, offset, 0, 0xff); 7661cb0ef41Sopenharmony_ci 7671cb0ef41Sopenharmony_ci boundsError(byteLength, 6, 'byteLength'); 7681cb0ef41Sopenharmony_ci} 7691cb0ef41Sopenharmony_ci 7701cb0ef41Sopenharmony_cifunction writeU_Int48BE(buf, value, offset, min, max) { 7711cb0ef41Sopenharmony_ci value = +value; 7721cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 5); 7731cb0ef41Sopenharmony_ci 7741cb0ef41Sopenharmony_ci const newVal = MathFloor(value * 2 ** -32); 7751cb0ef41Sopenharmony_ci buf[offset++] = (newVal >>> 8); 7761cb0ef41Sopenharmony_ci buf[offset++] = newVal; 7771cb0ef41Sopenharmony_ci buf[offset + 3] = value; 7781cb0ef41Sopenharmony_ci value = value >>> 8; 7791cb0ef41Sopenharmony_ci buf[offset + 2] = value; 7801cb0ef41Sopenharmony_ci value = value >>> 8; 7811cb0ef41Sopenharmony_ci buf[offset + 1] = value; 7821cb0ef41Sopenharmony_ci value = value >>> 8; 7831cb0ef41Sopenharmony_ci buf[offset] = value; 7841cb0ef41Sopenharmony_ci return offset + 4; 7851cb0ef41Sopenharmony_ci} 7861cb0ef41Sopenharmony_ci 7871cb0ef41Sopenharmony_cifunction writeU_Int40BE(buf, value, offset, min, max) { 7881cb0ef41Sopenharmony_ci value = +value; 7891cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 4); 7901cb0ef41Sopenharmony_ci 7911cb0ef41Sopenharmony_ci buf[offset++] = MathFloor(value * 2 ** -32); 7921cb0ef41Sopenharmony_ci buf[offset + 3] = value; 7931cb0ef41Sopenharmony_ci value = value >>> 8; 7941cb0ef41Sopenharmony_ci buf[offset + 2] = value; 7951cb0ef41Sopenharmony_ci value = value >>> 8; 7961cb0ef41Sopenharmony_ci buf[offset + 1] = value; 7971cb0ef41Sopenharmony_ci value = value >>> 8; 7981cb0ef41Sopenharmony_ci buf[offset] = value; 7991cb0ef41Sopenharmony_ci return offset + 4; 8001cb0ef41Sopenharmony_ci} 8011cb0ef41Sopenharmony_ci 8021cb0ef41Sopenharmony_cifunction writeU_Int32BE(buf, value, offset, min, max) { 8031cb0ef41Sopenharmony_ci value = +value; 8041cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 3); 8051cb0ef41Sopenharmony_ci 8061cb0ef41Sopenharmony_ci buf[offset + 3] = value; 8071cb0ef41Sopenharmony_ci value = value >>> 8; 8081cb0ef41Sopenharmony_ci buf[offset + 2] = value; 8091cb0ef41Sopenharmony_ci value = value >>> 8; 8101cb0ef41Sopenharmony_ci buf[offset + 1] = value; 8111cb0ef41Sopenharmony_ci value = value >>> 8; 8121cb0ef41Sopenharmony_ci buf[offset] = value; 8131cb0ef41Sopenharmony_ci return offset + 4; 8141cb0ef41Sopenharmony_ci} 8151cb0ef41Sopenharmony_ci 8161cb0ef41Sopenharmony_cifunction writeUInt32BE(value, offset = 0) { 8171cb0ef41Sopenharmony_ci return writeU_Int32BE(this, value, offset, 0, 0xffffffff); 8181cb0ef41Sopenharmony_ci} 8191cb0ef41Sopenharmony_ci 8201cb0ef41Sopenharmony_cifunction writeU_Int24BE(buf, value, offset, min, max) { 8211cb0ef41Sopenharmony_ci value = +value; 8221cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 2); 8231cb0ef41Sopenharmony_ci 8241cb0ef41Sopenharmony_ci buf[offset + 2] = value; 8251cb0ef41Sopenharmony_ci value = value >>> 8; 8261cb0ef41Sopenharmony_ci buf[offset + 1] = value; 8271cb0ef41Sopenharmony_ci value = value >>> 8; 8281cb0ef41Sopenharmony_ci buf[offset] = value; 8291cb0ef41Sopenharmony_ci return offset + 3; 8301cb0ef41Sopenharmony_ci} 8311cb0ef41Sopenharmony_ci 8321cb0ef41Sopenharmony_cifunction writeU_Int16BE(buf, value, offset, min, max) { 8331cb0ef41Sopenharmony_ci value = +value; 8341cb0ef41Sopenharmony_ci checkInt(value, min, max, buf, offset, 1); 8351cb0ef41Sopenharmony_ci 8361cb0ef41Sopenharmony_ci buf[offset++] = (value >>> 8); 8371cb0ef41Sopenharmony_ci buf[offset++] = value; 8381cb0ef41Sopenharmony_ci return offset; 8391cb0ef41Sopenharmony_ci} 8401cb0ef41Sopenharmony_ci 8411cb0ef41Sopenharmony_cifunction writeUInt16BE(value, offset = 0) { 8421cb0ef41Sopenharmony_ci return writeU_Int16BE(this, value, offset, 0, 0xffff); 8431cb0ef41Sopenharmony_ci} 8441cb0ef41Sopenharmony_ci 8451cb0ef41Sopenharmony_cifunction writeIntLE(value, offset, byteLength) { 8461cb0ef41Sopenharmony_ci if (byteLength === 6) 8471cb0ef41Sopenharmony_ci return writeU_Int48LE(this, value, offset, -0x800000000000, 0x7fffffffffff); 8481cb0ef41Sopenharmony_ci if (byteLength === 5) 8491cb0ef41Sopenharmony_ci return writeU_Int40LE(this, value, offset, -0x8000000000, 0x7fffffffff); 8501cb0ef41Sopenharmony_ci if (byteLength === 3) 8511cb0ef41Sopenharmony_ci return writeU_Int24LE(this, value, offset, -0x800000, 0x7fffff); 8521cb0ef41Sopenharmony_ci if (byteLength === 4) 8531cb0ef41Sopenharmony_ci return writeU_Int32LE(this, value, offset, -0x80000000, 0x7fffffff); 8541cb0ef41Sopenharmony_ci if (byteLength === 2) 8551cb0ef41Sopenharmony_ci return writeU_Int16LE(this, value, offset, -0x8000, 0x7fff); 8561cb0ef41Sopenharmony_ci if (byteLength === 1) 8571cb0ef41Sopenharmony_ci return writeU_Int8(this, value, offset, -0x80, 0x7f); 8581cb0ef41Sopenharmony_ci 8591cb0ef41Sopenharmony_ci boundsError(byteLength, 6, 'byteLength'); 8601cb0ef41Sopenharmony_ci} 8611cb0ef41Sopenharmony_ci 8621cb0ef41Sopenharmony_cifunction writeInt32LE(value, offset = 0) { 8631cb0ef41Sopenharmony_ci return writeU_Int32LE(this, value, offset, -0x80000000, 0x7fffffff); 8641cb0ef41Sopenharmony_ci} 8651cb0ef41Sopenharmony_ci 8661cb0ef41Sopenharmony_cifunction writeInt16LE(value, offset = 0) { 8671cb0ef41Sopenharmony_ci return writeU_Int16LE(this, value, offset, -0x8000, 0x7fff); 8681cb0ef41Sopenharmony_ci} 8691cb0ef41Sopenharmony_ci 8701cb0ef41Sopenharmony_cifunction writeInt8(value, offset = 0) { 8711cb0ef41Sopenharmony_ci return writeU_Int8(this, value, offset, -0x80, 0x7f); 8721cb0ef41Sopenharmony_ci} 8731cb0ef41Sopenharmony_ci 8741cb0ef41Sopenharmony_cifunction writeIntBE(value, offset, byteLength) { 8751cb0ef41Sopenharmony_ci if (byteLength === 6) 8761cb0ef41Sopenharmony_ci return writeU_Int48BE(this, value, offset, -0x800000000000, 0x7fffffffffff); 8771cb0ef41Sopenharmony_ci if (byteLength === 5) 8781cb0ef41Sopenharmony_ci return writeU_Int40BE(this, value, offset, -0x8000000000, 0x7fffffffff); 8791cb0ef41Sopenharmony_ci if (byteLength === 3) 8801cb0ef41Sopenharmony_ci return writeU_Int24BE(this, value, offset, -0x800000, 0x7fffff); 8811cb0ef41Sopenharmony_ci if (byteLength === 4) 8821cb0ef41Sopenharmony_ci return writeU_Int32BE(this, value, offset, -0x80000000, 0x7fffffff); 8831cb0ef41Sopenharmony_ci if (byteLength === 2) 8841cb0ef41Sopenharmony_ci return writeU_Int16BE(this, value, offset, -0x8000, 0x7fff); 8851cb0ef41Sopenharmony_ci if (byteLength === 1) 8861cb0ef41Sopenharmony_ci return writeU_Int8(this, value, offset, -0x80, 0x7f); 8871cb0ef41Sopenharmony_ci 8881cb0ef41Sopenharmony_ci boundsError(byteLength, 6, 'byteLength'); 8891cb0ef41Sopenharmony_ci} 8901cb0ef41Sopenharmony_ci 8911cb0ef41Sopenharmony_cifunction writeInt32BE(value, offset = 0) { 8921cb0ef41Sopenharmony_ci return writeU_Int32BE(this, value, offset, -0x80000000, 0x7fffffff); 8931cb0ef41Sopenharmony_ci} 8941cb0ef41Sopenharmony_ci 8951cb0ef41Sopenharmony_cifunction writeInt16BE(value, offset = 0) { 8961cb0ef41Sopenharmony_ci return writeU_Int16BE(this, value, offset, -0x8000, 0x7fff); 8971cb0ef41Sopenharmony_ci} 8981cb0ef41Sopenharmony_ci 8991cb0ef41Sopenharmony_ci// Write floats. 9001cb0ef41Sopenharmony_cifunction writeDoubleForwards(val, offset = 0) { 9011cb0ef41Sopenharmony_ci val = +val; 9021cb0ef41Sopenharmony_ci checkBounds(this, offset, 7); 9031cb0ef41Sopenharmony_ci 9041cb0ef41Sopenharmony_ci float64Array[0] = val; 9051cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[0]; 9061cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[1]; 9071cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[2]; 9081cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[3]; 9091cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[4]; 9101cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[5]; 9111cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[6]; 9121cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[7]; 9131cb0ef41Sopenharmony_ci return offset; 9141cb0ef41Sopenharmony_ci} 9151cb0ef41Sopenharmony_ci 9161cb0ef41Sopenharmony_cifunction writeDoubleBackwards(val, offset = 0) { 9171cb0ef41Sopenharmony_ci val = +val; 9181cb0ef41Sopenharmony_ci checkBounds(this, offset, 7); 9191cb0ef41Sopenharmony_ci 9201cb0ef41Sopenharmony_ci float64Array[0] = val; 9211cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[7]; 9221cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[6]; 9231cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[5]; 9241cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[4]; 9251cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[3]; 9261cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[2]; 9271cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[1]; 9281cb0ef41Sopenharmony_ci this[offset++] = uInt8Float64Array[0]; 9291cb0ef41Sopenharmony_ci return offset; 9301cb0ef41Sopenharmony_ci} 9311cb0ef41Sopenharmony_ci 9321cb0ef41Sopenharmony_cifunction writeFloatForwards(val, offset = 0) { 9331cb0ef41Sopenharmony_ci val = +val; 9341cb0ef41Sopenharmony_ci checkBounds(this, offset, 3); 9351cb0ef41Sopenharmony_ci 9361cb0ef41Sopenharmony_ci float32Array[0] = val; 9371cb0ef41Sopenharmony_ci this[offset++] = uInt8Float32Array[0]; 9381cb0ef41Sopenharmony_ci this[offset++] = uInt8Float32Array[1]; 9391cb0ef41Sopenharmony_ci this[offset++] = uInt8Float32Array[2]; 9401cb0ef41Sopenharmony_ci this[offset++] = uInt8Float32Array[3]; 9411cb0ef41Sopenharmony_ci return offset; 9421cb0ef41Sopenharmony_ci} 9431cb0ef41Sopenharmony_ci 9441cb0ef41Sopenharmony_cifunction writeFloatBackwards(val, offset = 0) { 9451cb0ef41Sopenharmony_ci val = +val; 9461cb0ef41Sopenharmony_ci checkBounds(this, offset, 3); 9471cb0ef41Sopenharmony_ci 9481cb0ef41Sopenharmony_ci float32Array[0] = val; 9491cb0ef41Sopenharmony_ci this[offset++] = uInt8Float32Array[3]; 9501cb0ef41Sopenharmony_ci this[offset++] = uInt8Float32Array[2]; 9511cb0ef41Sopenharmony_ci this[offset++] = uInt8Float32Array[1]; 9521cb0ef41Sopenharmony_ci this[offset++] = uInt8Float32Array[0]; 9531cb0ef41Sopenharmony_ci return offset; 9541cb0ef41Sopenharmony_ci} 9551cb0ef41Sopenharmony_ci 9561cb0ef41Sopenharmony_ciclass FastBuffer extends Uint8Array { 9571cb0ef41Sopenharmony_ci // Using an explicit constructor here is necessary to avoid relying on 9581cb0ef41Sopenharmony_ci // `Array.prototype[Symbol.iterator]`, which can be mutated by users. 9591cb0ef41Sopenharmony_ci // eslint-disable-next-line no-useless-constructor 9601cb0ef41Sopenharmony_ci constructor(bufferOrLength, byteOffset, length) { 9611cb0ef41Sopenharmony_ci super(bufferOrLength, byteOffset, length); 9621cb0ef41Sopenharmony_ci } 9631cb0ef41Sopenharmony_ci} 9641cb0ef41Sopenharmony_ci 9651cb0ef41Sopenharmony_cifunction addBufferPrototypeMethods(proto) { 9661cb0ef41Sopenharmony_ci proto.readBigUInt64LE = readBigUInt64LE; 9671cb0ef41Sopenharmony_ci proto.readBigUInt64BE = readBigUInt64BE; 9681cb0ef41Sopenharmony_ci proto.readBigUint64LE = readBigUInt64LE; 9691cb0ef41Sopenharmony_ci proto.readBigUint64BE = readBigUInt64BE; 9701cb0ef41Sopenharmony_ci proto.readBigInt64LE = readBigInt64LE; 9711cb0ef41Sopenharmony_ci proto.readBigInt64BE = readBigInt64BE; 9721cb0ef41Sopenharmony_ci proto.writeBigUInt64LE = writeBigUInt64LE; 9731cb0ef41Sopenharmony_ci proto.writeBigUInt64BE = writeBigUInt64BE; 9741cb0ef41Sopenharmony_ci proto.writeBigUint64LE = writeBigUInt64LE; 9751cb0ef41Sopenharmony_ci proto.writeBigUint64BE = writeBigUInt64BE; 9761cb0ef41Sopenharmony_ci proto.writeBigInt64LE = writeBigInt64LE; 9771cb0ef41Sopenharmony_ci proto.writeBigInt64BE = writeBigInt64BE; 9781cb0ef41Sopenharmony_ci 9791cb0ef41Sopenharmony_ci proto.readUIntLE = readUIntLE; 9801cb0ef41Sopenharmony_ci proto.readUInt32LE = readUInt32LE; 9811cb0ef41Sopenharmony_ci proto.readUInt16LE = readUInt16LE; 9821cb0ef41Sopenharmony_ci proto.readUInt8 = readUInt8; 9831cb0ef41Sopenharmony_ci proto.readUIntBE = readUIntBE; 9841cb0ef41Sopenharmony_ci proto.readUInt32BE = readUInt32BE; 9851cb0ef41Sopenharmony_ci proto.readUInt16BE = readUInt16BE; 9861cb0ef41Sopenharmony_ci proto.readUintLE = readUIntLE; 9871cb0ef41Sopenharmony_ci proto.readUint32LE = readUInt32LE; 9881cb0ef41Sopenharmony_ci proto.readUint16LE = readUInt16LE; 9891cb0ef41Sopenharmony_ci proto.readUint8 = readUInt8; 9901cb0ef41Sopenharmony_ci proto.readUintBE = readUIntBE; 9911cb0ef41Sopenharmony_ci proto.readUint32BE = readUInt32BE; 9921cb0ef41Sopenharmony_ci proto.readUint16BE = readUInt16BE; 9931cb0ef41Sopenharmony_ci proto.readIntLE = readIntLE; 9941cb0ef41Sopenharmony_ci proto.readInt32LE = readInt32LE; 9951cb0ef41Sopenharmony_ci proto.readInt16LE = readInt16LE; 9961cb0ef41Sopenharmony_ci proto.readInt8 = readInt8; 9971cb0ef41Sopenharmony_ci proto.readIntBE = readIntBE; 9981cb0ef41Sopenharmony_ci proto.readInt32BE = readInt32BE; 9991cb0ef41Sopenharmony_ci proto.readInt16BE = readInt16BE; 10001cb0ef41Sopenharmony_ci 10011cb0ef41Sopenharmony_ci proto.writeUIntLE = writeUIntLE; 10021cb0ef41Sopenharmony_ci proto.writeUInt32LE = writeUInt32LE; 10031cb0ef41Sopenharmony_ci proto.writeUInt16LE = writeUInt16LE; 10041cb0ef41Sopenharmony_ci proto.writeUInt8 = writeUInt8; 10051cb0ef41Sopenharmony_ci proto.writeUIntBE = writeUIntBE; 10061cb0ef41Sopenharmony_ci proto.writeUInt32BE = writeUInt32BE; 10071cb0ef41Sopenharmony_ci proto.writeUInt16BE = writeUInt16BE; 10081cb0ef41Sopenharmony_ci proto.writeUintLE = writeUIntLE; 10091cb0ef41Sopenharmony_ci proto.writeUint32LE = writeUInt32LE; 10101cb0ef41Sopenharmony_ci proto.writeUint16LE = writeUInt16LE; 10111cb0ef41Sopenharmony_ci proto.writeUint8 = writeUInt8; 10121cb0ef41Sopenharmony_ci proto.writeUintBE = writeUIntBE; 10131cb0ef41Sopenharmony_ci proto.writeUint32BE = writeUInt32BE; 10141cb0ef41Sopenharmony_ci proto.writeUint16BE = writeUInt16BE; 10151cb0ef41Sopenharmony_ci proto.writeIntLE = writeIntLE; 10161cb0ef41Sopenharmony_ci proto.writeInt32LE = writeInt32LE; 10171cb0ef41Sopenharmony_ci proto.writeInt16LE = writeInt16LE; 10181cb0ef41Sopenharmony_ci proto.writeInt8 = writeInt8; 10191cb0ef41Sopenharmony_ci proto.writeIntBE = writeIntBE; 10201cb0ef41Sopenharmony_ci proto.writeInt32BE = writeInt32BE; 10211cb0ef41Sopenharmony_ci proto.writeInt16BE = writeInt16BE; 10221cb0ef41Sopenharmony_ci 10231cb0ef41Sopenharmony_ci proto.readFloatLE = bigEndian ? readFloatBackwards : readFloatForwards; 10241cb0ef41Sopenharmony_ci proto.readFloatBE = bigEndian ? readFloatForwards : readFloatBackwards; 10251cb0ef41Sopenharmony_ci proto.readDoubleLE = bigEndian ? readDoubleBackwards : readDoubleForwards; 10261cb0ef41Sopenharmony_ci proto.readDoubleBE = bigEndian ? readDoubleForwards : readDoubleBackwards; 10271cb0ef41Sopenharmony_ci proto.writeFloatLE = bigEndian ? writeFloatBackwards : writeFloatForwards; 10281cb0ef41Sopenharmony_ci proto.writeFloatBE = bigEndian ? writeFloatForwards : writeFloatBackwards; 10291cb0ef41Sopenharmony_ci proto.writeDoubleLE = bigEndian ? writeDoubleBackwards : writeDoubleForwards; 10301cb0ef41Sopenharmony_ci proto.writeDoubleBE = bigEndian ? writeDoubleForwards : writeDoubleBackwards; 10311cb0ef41Sopenharmony_ci 10321cb0ef41Sopenharmony_ci proto.asciiSlice = asciiSlice; 10331cb0ef41Sopenharmony_ci proto.base64Slice = base64Slice; 10341cb0ef41Sopenharmony_ci proto.base64urlSlice = base64urlSlice; 10351cb0ef41Sopenharmony_ci proto.latin1Slice = latin1Slice; 10361cb0ef41Sopenharmony_ci proto.hexSlice = hexSlice; 10371cb0ef41Sopenharmony_ci proto.ucs2Slice = ucs2Slice; 10381cb0ef41Sopenharmony_ci proto.utf8Slice = utf8Slice; 10391cb0ef41Sopenharmony_ci proto.asciiWrite = asciiWrite; 10401cb0ef41Sopenharmony_ci proto.base64Write = base64Write; 10411cb0ef41Sopenharmony_ci proto.base64urlWrite = base64urlWrite; 10421cb0ef41Sopenharmony_ci proto.latin1Write = latin1Write; 10431cb0ef41Sopenharmony_ci proto.hexWrite = hexWrite; 10441cb0ef41Sopenharmony_ci proto.ucs2Write = ucs2Write; 10451cb0ef41Sopenharmony_ci proto.utf8Write = utf8Write; 10461cb0ef41Sopenharmony_ci} 10471cb0ef41Sopenharmony_ci 10481cb0ef41Sopenharmony_ci// This would better be placed in internal/worker/io.js, but that doesn't work 10491cb0ef41Sopenharmony_ci// because Buffer needs this and that would introduce a cyclic dependency. 10501cb0ef41Sopenharmony_cifunction markAsUntransferable(obj) { 10511cb0ef41Sopenharmony_ci if ((typeof obj !== 'object' && typeof obj !== 'function') || obj === null) 10521cb0ef41Sopenharmony_ci return; // This object is a primitive and therefore already untransferable. 10531cb0ef41Sopenharmony_ci obj[untransferable_object_private_symbol] = true; 10541cb0ef41Sopenharmony_ci} 10551cb0ef41Sopenharmony_ci 10561cb0ef41Sopenharmony_ci// A toggle used to access the zero fill setting of the array buffer allocator 10571cb0ef41Sopenharmony_ci// in C++. 10581cb0ef41Sopenharmony_ci// |zeroFill| can be undefined when running inside an isolate where we 10591cb0ef41Sopenharmony_ci// do not own the ArrayBuffer allocator. Zero fill is always on in that case. 10601cb0ef41Sopenharmony_cilet zeroFill = getZeroFillToggle(); 10611cb0ef41Sopenharmony_cifunction createUnsafeBuffer(size) { 10621cb0ef41Sopenharmony_ci zeroFill[0] = 0; 10631cb0ef41Sopenharmony_ci try { 10641cb0ef41Sopenharmony_ci return new FastBuffer(size); 10651cb0ef41Sopenharmony_ci } finally { 10661cb0ef41Sopenharmony_ci zeroFill[0] = 1; 10671cb0ef41Sopenharmony_ci } 10681cb0ef41Sopenharmony_ci} 10691cb0ef41Sopenharmony_ci 10701cb0ef41Sopenharmony_ci// The connection between the JS land zero fill toggle and the 10711cb0ef41Sopenharmony_ci// C++ one in the NodeArrayBufferAllocator gets lost if the toggle 10721cb0ef41Sopenharmony_ci// is deserialized from the snapshot, because V8 owns the underlying 10731cb0ef41Sopenharmony_ci// memory of this toggle. This resets the connection. 10741cb0ef41Sopenharmony_cifunction reconnectZeroFillToggle() { 10751cb0ef41Sopenharmony_ci zeroFill = getZeroFillToggle(); 10761cb0ef41Sopenharmony_ci} 10771cb0ef41Sopenharmony_ci 10781cb0ef41Sopenharmony_cimodule.exports = { 10791cb0ef41Sopenharmony_ci FastBuffer, 10801cb0ef41Sopenharmony_ci addBufferPrototypeMethods, 10811cb0ef41Sopenharmony_ci markAsUntransferable, 10821cb0ef41Sopenharmony_ci createUnsafeBuffer, 10831cb0ef41Sopenharmony_ci readUInt16BE, 10841cb0ef41Sopenharmony_ci readUInt32BE, 10851cb0ef41Sopenharmony_ci reconnectZeroFillToggle, 10861cb0ef41Sopenharmony_ci}; 1087