Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,23 @@ function parseMessage(
// Read the metadata
const metadataUint8Array = new Uint8Array(buffer, 4, metadataLength);
const metadataString = new TextDecoder().decode(metadataUint8Array);
const metadata = JSON.parse(metadataString);

// Read the binary data
const binaryData = new Uint8Array(buffer, 4 + metadataLength);
try {
const metadata = JSON.parse(metadataString);

return { metadata, binaryData };
return { metadata, binaryData };
} catch (error) {
console.log({
error,
buffer,
binaryData,
metadataString,
metadataUint8Array,
});
return { metadata: "", binaryData };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say metadata can't be a string but rather an object, however there's no way to parse data without metadata information, so my preference is to rethrow the error instead of creating inconsistent behaviours returning empty strings and arbitrary data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return { metadata: "", binaryData };
throw error;

}
}

export const arrayBufferSerializer = (): MessageSerializer<
Expand Down