Answers in protobuf from generated structs, and the page reads them (#470)
ipx-wire converted every protobuf answer at run time through prost-reflect and serde_json::Value, so protobuf cost more than the JSON it replaced: decoding 1,488 feeds took 1.50 ms that way against 0.37 ms for serde_json and 0.09 ms for prost's own structs, and GET /api/feeds as protobuf answered about 4 ms after JSON. build.rs now generates those structs (prost-build from protox's descriptors, still no protoc). An answer's JSON goes straight into its struct with serde and out with prost, byte for byte what the runtime path wrote (a test says so); bodies holding a google.protobuf.Value keep the runtime path, as they are only ever read. ipx's calls to the directory and ipx-play build and read the structs directly, through From conversions beside the directory's own types. The page asks for protobuf too, to see what it does in practice. It reads it with web/src/wire.ts, about seventy lines and no library: protobufjs alone was larger gzipped than all protobuf saves the page. build.mts reads the .proto files into a table for it, and the answer names its message in its Content-Type, so the page keeps no table of routes. An answer of null stays JSON, since the empty message would be a feed row of defaults. The offline worker decodes a kept answer to mark what was read offline, and hands the page JSON. The decoder's test caught `pos += varint()[0]`, which adds the length to pos as it was before the varint was read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -215,7 +215,11 @@ not know: `ipx_wire::negotiate`, a layer on each service's routes, converts the
|
||||
by its table of each route's messages (`WIRE` in `web.rs`, `api.rs` and play's `lib.rs`). A route
|
||||
added to a router goes in its table. Debug builds convert every JSON answer strictly, so the cargo
|
||||
tests and the browser suite answer `500` for a field missing from the `.proto` or a route missing
|
||||
from the table. Errors stay JSON. The iOS app's own calls go in protobuf (#469), from Swift
|
||||
from the table. Errors stay JSON, and so does an answer of null. An answer goes into a struct
|
||||
generated from its message (prost, in `crates/wire/build.rs`) and out as protobuf, named in its
|
||||
`Content-Type` (`application/x-protobuf; messageType=ipx.FeedRows`); the page reads it with
|
||||
`web/src/wire.ts`, a decoder of its own driven by the same `.proto` files, which `web/build.mts`
|
||||
reads into the page and the offline worker (#470). The iOS app's own calls go in protobuf (#469), from Swift
|
||||
generated off the same files: a change to them is `sh ios/scripts/proto.sh` too.
|
||||
|
||||
Show notes are feed-supplied HTML from an untrusted source, sanitized with `ammonia` server-side
|
||||
|
||||
Reference in New Issue
Block a user