Repository navigation
Conversation
|
commit: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on
jsonCompatibleWithBytesfrom #186 to support native binary framing over WebSocket (src/websocket.ts) and HTTP batch (src/batch.ts) without Base64 overhead.Problem
Even with
RpcTransportWithCustomEncoding(encodingLevel: "jsonCompatibleWithBytes"), the built-in WebSocket and HTTP batch transports still usedencodingLevel: "string", Base64-encoding everyUint8Array,ArrayBuffer, andTypedArrayinside JSON text frames (+33% wire size and encode/decode copies).Mechanism
Adds a compact binary frame codec (
encodeBinaryFrame/decodeBinaryFrameinsrc/serialize.ts) and wiresWebSocketFrameTransport,BatchClientTransport, andBatchServerTransportontoRpcTransportWithCustomEncoding(encodingLevel: "jsonCompatibleWithBytes"):0..3:\x89CWBmagic4..7: little-endianuint32UTF-8 JSON header byte length8..8+headerByteLength: UTF-8 JSON header where["bytes", Uint8Array, typeName?]leaves are replaced by["bytes", attachmentIndex, byteOffset, byteLength, typeName?](and literal arrays beginning with"bytes"and a number/null second element are escaped as["bytes", null, ...])0..7zero padding bytes to align the attachments section to an 8-byte boundarydecodeBinaryFrameslices 8-byte-alignedUint8Arrayviews into the frame'sArrayBuffer, andEvaluatorconstructsFloat64Array,Int32Array,DataView, etc. directly overview.bufferatview.byteOffsetwhen aligned.options.binary?: boolean):options.binaryis omitted, accepts both text and binary frames on receive, and auto-upgrades replies to binary after receiving a binary frame from the peer. Settingoptions.binary: truesends binary frames immediately;options.binary: falsekeeps outgoing frames as text.Content-Type: application/x-capnweb-binwhenoptions.binary: true(or whenRequesthasContent-Type: application/x-capnweb-bin), and advertisesAccept: application/x-capnweb-bin, text/plain;q=0.9, */*;q=0.8unlessoptions.binary === false. Server handlers (newHttpBatchRpcResponse,nodeHttpBatchRpcResponse) auto-detect binary requests byContent-Typeor\x89CWBmagic and reply in binary when requested or accepted.