feat: Support ArrayBuffer and Buffer Views serialization#201
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
66c4db3 to
4231ea8
Compare
🦋 Changeset detectedLatest commit: 2821584 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
I have read the CLA Document and I hereby sign the CLA |
kentonv
left a comment
There was a problem hiding this comment.
Design looks good to me. I'm overloaded and don't have time to review line-by-line, maybe @dimitropoulos or @teamchong can take it.
commit: |
| `["bytes", base64]`, `["bytes", base64, type]` | ||
|
|
||
| A byte container, represented as a base64-encoded string. If `type` is omitted, the receiver | ||
| should deserialize bytes as its default `Uint8Array` for backwards compatibility. Otherwise, |
There was a problem hiding this comment.
Can you clarify endianness? Currently multi-byte typed arrays go on the wire as raw native-endian bytes: my recommendation is to mandate little-endian on the wire
| throw new TypeError(`Unknown bytes type marker type: ${typeof value[2]}`); | ||
| } | ||
|
|
||
| let buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength); |
There was a problem hiding this comment.
I believe when misaligned untrusted input throws a raw RangeError ("byte length of Int16Array should be a multiple of 2"). We probably want to validate byteLength % BYTES_PER_ELEMENT === 0
| } | ||
|
|
||
| let buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength); | ||
| switch (value[2]) { |
There was a problem hiding this comment.
This is likely more then a patch change
A current-main receiver ignores value[2] entirely and returns a Uint8Array of raw bytes for a 3-element message (eg. new sender Float64Array → old receiver yields a 16-byte Buffer).
Added serialization support for ArrayBuffer and Buffer views, like Int8Array, Uint8ClampedArray, etc.