Skip to content

feat: add encoding levels to RPC transport#144

Open
ashkalor wants to merge 3 commits intocloudflare:mainfrom
ashkalor:ak/feat/encoding-levels
Open

feat: add encoding levels to RPC transport#144
ashkalor wants to merge 3 commits intocloudflare:mainfrom
ashkalor:ak/feat/encoding-levels

Conversation

@ashkalor
Copy link

@ashkalor ashkalor commented Mar 4, 2026

Implements the encoding level architecture suggested by @kentonv in #133, handling serialization at the transport layer rather than through a global WireFormat hook.

Summary

  • Add EncodingLevel type with four levels: stringify, devalue, partial, passthrough
  • Add optional encodingLevel property to RpcTransport interface
  • Add wrapTransport() helper for custom binary formats (CBOR, MessagePack, etc.)
  • Serialize/deserialize based on transport's encoding level
  • Maintain full backwards compatibility (stringify is the default)

Encoding Levels

Level Format Use Case
stringify JSON string Default, max compatibility
devalue JS objects Avoid double-parse overhead
partial JS objects + raw Uint8Array Binary data without base64
passthrough Structured-clonable postMessage, Workers

Motivation

Binary formats like CBOR can significantly outperform JSON for large payloads by avoiding base64 encoding cycles. This architecture lets transports declare their capabilities and have serialization handled appropriately.

@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2026

⚠️ No Changeset found

Latest commit: eddff04

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@burdiyan
Copy link

burdiyan commented Mar 4, 2026

Having some examples in the README.md would be appreciated 🙏.

@ashkalor
Copy link
Author

ashkalor commented Mar 7, 2026

Having some examples in the README.md would be appreciated 🙏.

Hey just added them, let me know if it looks good. Didn't initially add them because I was expecting some kind of feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants