From 74c81201ada893be338ab4d370d3de4126b826cc Mon Sep 17 00:00:00 2001 From: xshady Date: Sat, 10 Aug 2024 15:15:08 +0300 Subject: [PATCH] fix raw bytes (de)serialization --- shared/helpers/Serialization.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shared/helpers/Serialization.cpp b/shared/helpers/Serialization.cpp index 9bd23f80..5275f905 100644 --- a/shared/helpers/Serialization.cpp +++ b/shared/helpers/Serialization.cpp @@ -518,11 +518,11 @@ alt::MValueByteArray V8Helpers::V8ToRawBytes(v8::Local val) v8::ValueSerializer serializer(isolate, &delegate); delegate.SetSerializer(&serializer); - serializer.WriteHeader(); - // Write the magic bytes to the buffer serializer.WriteRawBytes(magicBytes, sizeof(magicBytes)); + serializer.WriteHeader(); + // Write the serialized value to the buffer bool result; if(!serializer.WriteValue(ctx, val).To(&result) || !result) return alt::MValueByteArray(); @@ -547,14 +547,14 @@ v8::MaybeLocal V8Helpers::RawBytesToV8(alt::MValueByteArrayConst rawB v8::ValueDeserializer deserializer(isolate, data, size, &delegate); delegate.SetDeserializer(&deserializer); - bool headerValid; - if(!deserializer.ReadHeader(ctx).To(&headerValid) || !headerValid) return v8::MaybeLocal(); - // Check for magic bytes uint8_t* magicBytesPtr; if(!deserializer.ReadRawBytes(sizeof(magicBytes), (const void**)&magicBytesPtr)) return v8::MaybeLocal(); if(memcmp(magicBytesPtr, magicBytes, sizeof(magicBytes)) != 0) return v8::MaybeLocal(); + bool headerValid; + if(!deserializer.ReadHeader(ctx).To(&headerValid) || !headerValid) return v8::MaybeLocal(); + // Deserialize the value v8::MaybeLocal result = deserializer.ReadValue(ctx);