Skip to content

Commit

Permalink
fix raw bytes (de)serialization (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxshady authored Aug 14, 2024
1 parent 88b992a commit 4ad0910
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions shared/helpers/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,11 @@ alt::MValueByteArray V8Helpers::V8ToRawBytes(v8::Local<v8::Value> 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();
Expand All @@ -547,14 +547,14 @@ v8::MaybeLocal<v8::Value> 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<v8::Value>();

// Check for magic bytes
uint8_t* magicBytesPtr;
if(!deserializer.ReadRawBytes(sizeof(magicBytes), (const void**)&magicBytesPtr)) return v8::MaybeLocal<v8::Value>();
if(memcmp(magicBytesPtr, magicBytes, sizeof(magicBytes)) != 0) return v8::MaybeLocal<v8::Value>();

bool headerValid;
if(!deserializer.ReadHeader(ctx).To(&headerValid) || !headerValid) return v8::MaybeLocal<v8::Value>();

// Deserialize the value
v8::MaybeLocal<v8::Value> result = deserializer.ReadValue(ctx);

Expand Down

0 comments on commit 4ad0910

Please sign in to comment.