head_mls.js (1112B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 */ 5 6 "use strict"; 7 8 // 9 // Array equality 10 // 11 function arraysAreEqual(arr1, arr2) { 12 if (arr1.length !== arr2.length) { 13 return false; 14 } 15 for (let i = 0; i < arr1.length; i++) { 16 if (arr1[i] !== arr2[i]) { 17 return false; 18 } 19 } 20 return true; 21 } 22 23 // 24 // Serialization / Derserialization helpers 25 // 26 function stringToByteArray(str) { 27 return new TextEncoder().encode(str); 28 } 29 30 function byteArrayToString(byteArray) { 31 return new TextDecoder().decode(new Uint8Array(byteArray).buffer); 32 } 33 34 function stringToArrayBuffer(str) { 35 return new Uint8Array(new TextEncoder().encode(str)).buffer; 36 } 37 38 function byteArrayToHexString(buffer) { 39 const byteArray = new Uint8Array(buffer); 40 const hexParts = []; 41 for (let i = 0; i < byteArray.length; i++) { 42 const hex = byteArray[i].toString(16); 43 const paddedHex = ("00" + hex).slice(-2); 44 hexParts.push(paddedHex); 45 } 46 return hexParts.join(""); 47 }