{"ScriptPreparationCode":"function serializeToArrayBuffer(obj) {\r\n const encoder = new TextEncoder();\r\n let bufferArray = [];\r\n\r\n function serialize(value) {\r\n if (typeof value === \u0022string\u0022) {\r\n bufferArray.push(1); // Type marker for string\r\n const encoded = encoder.encode(value);\r\n bufferArray.push(...new Uint8Array(new Uint32Array([encoded.length]).buffer));\r\n bufferArray.push(...encoded);\r\n } else if (typeof value === \u0022number\u0022) {\r\n bufferArray.push(2); // Type marker for number\r\n bufferArray.push(...new Uint8Array(new Float64Array([value]).buffer));\r\n } else if (typeof value === \u0022boolean\u0022) {\r\n bufferArray.push(3); // Type marker for boolean\r\n bufferArray.push(value ? 1 : 0);\r\n } else if (Array.isArray(value)) {\r\n bufferArray.push(4); // Type marker for array\r\n bufferArray.push(...new Uint8Array(new Uint32Array([value.length]).buffer));\r\n value.forEach((item) =\u003E serialize(item));\r\n } else if (value \u0026\u0026 typeof value === \u0022object\u0022) {\r\n bufferArray.push(5); // Type marker for object\r\n const keys = Object.keys(value);\r\n bufferArray.push(...new Uint8Array(new Uint32Array([keys.length]).buffer));\r\n keys.forEach((key) =\u003E {\r\n serialize(key); // Serialize key as string\r\n serialize(value[key]); // Serialize value\r\n });\r\n } else if (value === null) {\r\n bufferArray.push(6); // Type marker for null\r\n }\r\n }\r\n\r\n serialize(obj);\r\n return new Uint8Array(bufferArray).buffer;\r\n}\r\n\r\nfunction deserializeFromArrayBuffer(buffer) {\r\n const decoder = new TextDecoder();\r\n const uint8Array = new Uint8Array(buffer);\r\n let offset = 0;\r\n\r\n function deserialize() {\r\n const type = uint8Array[offset\u002B\u002B];\r\n if (type === 1) {\r\n // String\r\n const length = new Uint32Array(uint8Array.buffer.slice(offset, offset \u002B 4))[0];\r\n offset \u002B= 4;\r\n const str = decoder.decode(uint8Array.slice(offset, offset \u002B length));\r\n offset \u002B= length;\r\n return str;\r\n } else if (type === 2) {\r\n // Number\r\n const num = new Float64Array(uint8Array.buffer.slice(offset, offset \u002B 8))[0];\r\n offset \u002B= 8;\r\n return num;\r\n } else if (type === 3) {\r\n // Boolean\r\n return uint8Array[offset\u002B\u002B] === 1;\r\n } else if (type === 4) {\r\n // Array\r\n const length = new Uint32Array(uint8Array.buffer.slice(offset, offset \u002B 4))[0];\r\n offset \u002B= 4;\r\n const arr = [];\r\n for (let i = 0; i \u003C length; i\u002B\u002B) {\r\n arr.push(deserialize());\r\n }\r\n return arr;\r\n } else if (type === 5) {\r\n // Object\r\n const length = new Uint32Array(uint8Array.buffer.slice(offset, offset \u002B 4))[0];\r\n offset \u002B= 4;\r\n const obj = {};\r\n for (let i = 0; i \u003C length; i\u002B\u002B) {\r\n const key = deserialize(); // Deserialize key (string)\r\n const value = deserialize(); // Deserialize value\r\n obj[key] = value;\r\n }\r\n return obj;\r\n } else if (type === 6) {\r\n // Null\r\n return null;\r\n } else {\r\n throw new Error(\u0022Unknown type marker: \u0022 \u002B type);\r\n }\r\n }\r\n\r\n return deserialize();\r\n}\r\n\r\nconst test = {\r\n a: \u0022hohojoho\u0022,\r\n b: { c: [1, \u0022string\u0022, { nested: true }, null] },\r\n d: 1,\r\n e: true,\r\n f: null,\r\n};\r\n","TestCases":[{"Name":"arraybuffer","Code":"const buffer = serializeToArrayBuffer(test);\r\nconst result = deserializeFromArrayBuffer(buffer);","IsDeferred":false},{"Name":"json","Code":"const jsonStr = JSON.stringify(test);\r\nconst result = JSON.parse(jsonStr);","IsDeferred":false}]}