You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(serialization): document Protobuf in API, site, and CHANGELOG
- docs/API.md: Protobuf subsection under runtime:serialization (Schema/parse/build,
decoded value shape, proto3 + edition 2023).
- site: re-add the Protobuf section to the API reference page, a new Protobuf
guide page (/docs/serialization/protobuf) + nav link, and site-meta entries.
- CHANGELOG: [Unreleased] Added — pure-JS reflective Protobuf.
Copy file name to clipboardExpand all lines: docs/API.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -484,18 +484,25 @@ pub/sub topics are follow-ups (D29).
484
484
485
485
## `runtime:serialization`
486
486
487
-
A high-performance parsing and serialization module for structured data formats: XML, YAML, TOML, JSONL, and MessagePack. These parsers are backed by optimized Rust implementations and are exposed via zero-cost host boundaries.
487
+
A high-performance parsing and serialization module for structured data formats: XML, YAML, TOML, JSONL, MessagePack, and Protobuf. The text/binary parsers are backed by optimized Rust implementations; Protobuf is a pure-JS reflective implementation. All are exposed via zero-cost host boundaries.
@@ -529,6 +536,16 @@ For XML, it also provides a `DecoderStream`:
529
536
| --- | --- |
530
537
| `newXML.DecoderStream()` | A `TransformStream` that parses XML chunks. |
531
538
539
+
For Protobuf, schemas are compiled from `.proto` source at runtime (pure JS, reflective — proto3 and edition 2023; proto2-only constructs are rejected):
540
+
541
+
| Export | Description |
542
+
| --- | --- |
543
+
| `newProtobuf.Schema(proto, opts?)` | Compiles a `.proto` source string (or a `{ filename: source }` map for multi-file schemas with `import`s; the `google/protobuf/*` well-known types resolve automatically). |
544
+
| `schema.parse(messageName, bytes)` | Decodes a `Uint8Array` for the fully-qualified `messageName`. |
545
+
| `schema.build(messageName, value)` | Encodes a JavaScript object into a `Uint8Array`. |
546
+
547
+
Decoded value shape: camelCase field names; 64-bit integer fields (`int64`/`uint64`/`sint64`/`fixed64`/`sfixed64`) as **BigInt**; enums as their value-name string (unknown numbers kept as numbers); `bytes` as `Uint8Array`; maps as plain objects; nested messages as plain objects. Fields absent on the wire are omitted.
desc: "Schema-aware Protobuf parsing and building. Pure-JS and reflective: the .proto is compiled at runtime (proto3 and edition 2023; proto2-only constructs are rejected). Decoded objects use camelCase keys, BigInt for 64-bit ints, enum value-names, and Uint8Array for bytes.",
109
+
exports: [
110
+
{sig: "new Protobuf.Schema(proto, options?)",type: "Schema",desc: "Compiles a .proto source string (or a { filename: source } map for multi-file schemas with imports; google/protobuf well-known types resolve automatically).",ex: `const schema = new Protobuf.Schema('syntax = "proto3"; message Hello { string name = 1; }');`},
111
+
{sig: "schema.parse(messageName, bytes)",type: "(string, Uint8Array) => object",desc: "Decodes a byte array into a JavaScript object for the fully-qualified message name.",ex: `schema.parse("Hello", bytes);`},
112
+
{sig: "schema.build(messageName, value)",type: "(string, object) => Uint8Array",desc: "Encodes a JavaScript object into a Protobuf byte array.",ex: `schema.build("Hello", { name: "world" });`},
A pure-JavaScript, reflective Protobuf implementation in <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">runtime:serialization</code>. The <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">.proto</code> schema is compiled at runtime — no codegen, no build step. proto3 and edition 2023 are supported; proto2-only constructs are rejected.
Construct a <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">Protobuf.Schema</code> from <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">.proto</code> source. Pass a single string, or a <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">{`{ filename: source }`}</code> map for multi-file schemas with imports.
20
+
</p>
21
+
<divclassName="mt-6">
22
+
<CodeBlockcode={`import { Protobuf } from "runtime:serialization";
Use <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">schema.build</code> and <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">schema.parse</code> with a fully-qualified message name.
Decoded objects use camelCase field names (or the explicit <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">json_name</code>). 64-bit integer fields surface as <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">BigInt</code>; enums as their value-name string; <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">bytes</code> as <codeclassName="rounded bg-zinc-100 px-1.5 py-0.5 text-[13px]">Uint8Array</code>; maps as plain objects. Fields absent on the wire are omitted.
58
+
</p>
59
+
<divclassName="mt-6">
60
+
<CodeBlockcode={`const schema = new Protobuf.Schema(\`
61
+
syntax = "proto3";
62
+
enum Status { ACTIVE = 0; ARCHIVED = 1; }
63
+
message Account { uint64 id = 1; Status status = 2; }
Copy file name to clipboardExpand all lines: site/src/site-meta.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ export const PAGES = {
42
42
"/api/fs": {section: "API reference",title: "runtime:fs",description: "Blob-based async file I/O — `file()` handles, `write()`, `readDir`, `stat`, `mkdir`, `remove`, `rename`, and `Glob`; confined to a root jail. Gated on FileRead/FileWrite."},
43
43
"/api/net": {section: "API reference",title: "runtime:net",description: "TCP sockets following the WinterTC Sockets API — `connect()` and `listen()`. Gated on Net/NetListen."},
44
44
"/api/http": {section: "API reference",title: "runtime:http",description: "an HTTP/1.1 server, `serve((request) => response)`, using the Web `Request`/`Response` objects. Gated on NetListen."},
45
-
"/api/serialization": {section: "API reference",title: "runtime:serialization",description: "high-performance native parsers for JSONL, XML, YAML, and TOML via streams and synchronous functions."},
45
+
"/api/serialization": {section: "API reference",title: "runtime:serialization",description: "serialization for JSONL, XML, YAML, TOML, MessagePack (native), and Protobuf (pure-JS, reflective)."},
46
46
"/api/websocket": {section: "API reference",title: "runtime:websocket",description: "WebSocket client and server functionality native to the engine."},
47
47
48
48
// Comparisons
@@ -63,6 +63,7 @@ export const PAGES = {
63
63
"/docs/serialization/xml": {section: "Guides",title: "XML Parsing",description: "synchronous and streaming fast XML processing."},
0 commit comments