Files
ipx/crates/wire/proto/ipx.proto
rays 236bd02d88 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>
2026-11-17 00:21:41 +00:00

495 lines
11 KiB
Protocol Buffer

// ipx's API under /api (crates/ipx/src/web.rs), the same answers its JSON gives, each message named
// after the Rust struct it mirrors where there is one (web/src/types.ts mirrors the same). A field
// added in Rust goes here too: debug builds refuse an answer with a field missing here.
//
// How the JSON maps (crates/wire/src/lib.rs):
// * A field name is the JSON key.
// * A Rust Option is `optional`, or a message; so is a field with a serde default, which an absent
// field must leave to Rust.
// * A message whose only field is `repeated ... items` is a JSON array, top-level or as a field.
// An Option<Vec> in a body is one (Words), so leaving a list alone and emptying it differ.
// * A body field that takes null to clear it is a google.protobuf.Value: absent leaves it, null
// clears it, a value sets it.
// * An answer of JSON null stays JSON null: the empty message would be a row of defaults.
syntax = "proto3";
package ipx;
import "google/protobuf/struct.proto";
import "directory.proto";
// A list of words, as an Option<Vec<String>> in a body: absent, or this.
message Words {
repeated string items = 1;
}
// ---- signing in, and you ----
// POST /api/login, the body.
message Credentials {
string name = 1;
string password = 2;
}
// POST /api/login, the answer.
message SignedIn {
string name = 1;
bool admin = 2;
}
message Theme {
string name = 1;
string mode = 2;
}
// GET /api/me.
message Me {
string name = 1;
bool admin = 2;
optional string sign_out = 3;
repeated string blocked = 4;
int64 deadair_saved = 5;
optional Theme theme = 6;
string version = 7;
bool typesafe_key_set = 8;
// "server" or "own".
string signals = 9;
uint64 signal_days = 10;
}
// PATCH /api/me, the body.
message MePatch {
Words blocked = 1;
google.protobuf.Value typesafe_key = 2;
}
message ApiToken {
int64 id = 1;
string name = 2;
int64 created = 3;
optional int64 last_used = 4;
}
// GET /api/tokens.
message ApiTokens {
repeated ApiToken items = 1;
}
// POST /api/tokens, the body.
message NewToken {
string name = 1;
}
// POST /api/tokens, the answer: the only time the token is shown.
message MadeToken {
int64 id = 1;
string name = 2;
string token = 3;
}
// POST /api/push/devices, the body.
message PushDevice {
string token = 1;
optional bool sandbox = 2;
}
// ---- feeds ----
message FailingRow {
string reason = 1;
optional string new_url = 2;
}
message FeedRow {
string id = 1;
string url = 2;
optional string title = 3;
optional string image = 4;
optional string folder = 5;
optional string category = 6;
optional string feed_category = 7;
repeated string keywords = 8;
repeated string blocked = 9;
bool deadair = 10;
int64 deadair_pause = 11;
bool allow_explicit = 12;
bool auto_download = 13;
optional uint64 max_new_per_check = 14;
optional string group = 15;
bool orphaned = 16;
bool managed = 17;
optional string schedule = 18;
optional uint64 schedule_mins = 19;
uint64 every_mins = 20;
optional int64 last_checked = 21;
optional int64 next_check = 22;
optional string last_error = 23;
optional FailingRow failing = 24;
int64 entries = 25;
int64 downloaded = 26;
int64 unread = 27;
int64 subscribers = 28;
bool pinned = 29;
bool kept = 30;
bool hide_from_all = 31;
bool hide_from_signals = 32;
bool private = 33;
bool private_by_address = 34;
}
// GET /api/feeds.
message FeedRows {
repeated FeedRow items = 1;
}
// POST /api/feeds, the body.
message NewFeed {
string url = 1;
optional string folder = 2;
repeated string keywords = 3;
optional bool allow_explicit = 4;
}
// POST /api/feeds, the answer.
message AddedFeed {
string id = 1;
bool existing = 2;
}
// PATCH /api/feeds/{id}, the body: what is there changes, what is not is left.
message FeedPatch {
optional string url = 1;
google.protobuf.Value schedule = 2;
google.protobuf.Value folder = 3;
google.protobuf.Value category = 4;
Words keywords = 5;
Words blocked = 6;
optional bool allow_explicit = 7;
optional bool auto_download = 8;
google.protobuf.Value max_new_per_check = 9;
optional bool pinned = 10;
optional bool kept = 11;
optional bool hide_from_all = 12;
optional bool hide_from_signals = 13;
google.protobuf.Value deadair = 14;
optional int64 deadair_pause = 15;
optional bool private = 16;
}
// POST /api/feeds/{id}/download-latest, the body.
message HowMany {
optional int64 count = 1;
}
// POST /api/feeds/{id}/download-latest, the answer.
message Queued {
uint64 queued = 1;
}
// POST /api/feeds/{id}/read-all, POST /api/read-all.
message Marked {
uint64 marked = 1;
}
// POST /api/fetch, the body.
message FetchBody {
optional string feed = 1;
optional bool force = 2;
}
// POST /api/opml, the body.
message OpmlBody {
string xml = 1;
}
// POST /api/opml, the answer.
message OpmlImported {
uint64 added = 1;
uint64 already = 2;
}
// ---- items ----
message EncRow {
int64 id = 1;
optional int64 deadair = 2;
optional bool deadair_pending = 3;
string feed_id = 4;
string guid = 5;
string url = 6;
optional string mime = 7;
optional int64 length = 8;
optional string path = 9;
string state = 10;
optional string last_error = 11;
}
// GET /api/entries/{feed_id}/{guid}.
message EntryRow {
string guid = 1;
string feed_id = 2;
optional string title = 3;
optional string link = 4;
optional int64 published = 5;
optional string description = 6;
optional string markdown = 7;
optional string markdown_html = 8;
bool read = 9;
bool flagged = 10;
optional string image = 11;
optional int64 duration = 12;
optional int64 episode = 13;
optional int64 season = 14;
int64 position = 15;
repeated EncRow enclosures = 16;
}
// GET /api/entries, /api/feeds/{id}/entries, /api/signals/{id}/entries.
message EntryPage {
int64 total = 1;
repeated EntryRow entries = 2;
}
// POST /api/entries/{feed_id}/{guid}/flags, the body. The answer is the feed's FeedRow, or JSON
// null when the feed is not yours.
message Flags {
optional bool read = 1;
optional bool flagged = 2;
}
// POST /api/entries/{feed_id}/{guid}/position, the body.
message Position {
int64 secs = 1;
optional int64 duration = 2;
optional int64 deadair = 3;
}
// POST /api/entries/{feed_id}/{guid}/share, the body.
message ShareBody {
optional int64 enc = 1;
}
// POST /api/entries/{feed_id}/{guid}/share, the answer.
message ShareLink {
optional string url = 1;
optional string why = 2;
}
// ---- Signals ----
message SignalRow {
int64 id = 1;
string name = 2;
repeated string keywords = 3;
optional string description = 4;
optional string icon = 5;
int64 items = 6;
int64 unread = 7;
}
// GET /api/signals.
message SignalRows {
repeated SignalRow items = 1;
}
// POST /api/signals and PATCH /api/signals/{id}, the body.
message SignalBody {
optional string name = 1;
Words keywords = 2;
google.protobuf.Value description = 3;
google.protobuf.Value icon = 4;
}
// POST /api/signals, the answer.
message SignalId {
int64 id = 1;
}
// POST /api/signals/icon, the body. Each candidate is [icon, label].
message IconAsk {
string name = 1;
repeated string keywords = 2;
optional string description = 3;
repeated google.protobuf.ListValue candidates = 4;
}
// POST /api/signals/icon, the answer.
message Icon {
string icon = 1;
}
// ---- the directory ----
message PopularRow {
string id = 1;
optional string title = 2;
optional string image = 3;
int64 subscribers = 4;
bool subscribed = 5;
optional string feed = 6;
optional string category = 7;
optional string subcategory = 8;
bool podcast = 9;
}
// GET /api/popular, GET /api/directory.
message PopularRows {
repeated PopularRow items = 1;
}
message ListedItem {
string guid = 1;
optional string title = 2;
optional string link = 3;
optional int64 published = 4;
optional int64 duration = 5;
optional string description = 6;
}
// GET /api/directory/{id}.
message Listed {
optional string description = 1;
optional string failing = 2;
repeated ListedItem items = 3;
bool can_admin = 4;
}
// POST /api/popular/{id}, the answer.
message FeedId {
string id = 1;
}
message BlockedRow {
string id = 1;
optional string title = 2;
int64 at = 3;
}
// GET /api/directory-admin.
message DirAdmin {
repeated directory.Instance instances = 1;
repeated BlockedRow blocked = 2;
}
// When the snapshot last went: a SnapshotResult's fields when it was taken, the error when not.
message Shared {
int64 at = 1;
optional uint64 accepted = 2;
optional uint64 refused_private = 3;
optional uint64 refused_blocked = 4;
optional uint64 refused_invalid = 5;
optional string error = 6;
}
// GET /api/directory-status.
message DirStatus {
bool configured = 1;
optional string name = 2;
optional string access = 3;
optional string error = 4;
optional Shared shared = 5;
}
// ---- the server ----
// GET /api/status.
message Status {
uint64 feeds = 1;
int64 pending = 2;
int64 downloaded = 3;
string version = 4;
}
// GET /api/settings.
message Settings {
string schedule = 1;
uint64 every_mins = 2;
uint64 max_new_per_check = 3;
repeated string media_types = 4;
string download_dir = 5;
double max_total_gb = 6;
uint64 max_age_days = 7;
uint64 art_cache_mb = 8;
string directory_url = 9;
bool directory_token_set = 10;
bool directory_share = 11;
string play_url = 12;
bool play_token_set = 13;
bool signals_on_server = 14;
uint64 signal_days = 15;
bool typesafe_server_key = 16;
}
// PATCH /api/settings, the body.
message SettingsPatch {
optional string schedule = 1;
optional uint64 max_new_per_check = 2;
Words media_types = 3;
optional double max_total_gb = 4;
optional uint64 max_age_days = 5;
optional uint64 art_cache_mb = 6;
optional string directory_url = 7;
optional string directory_token = 8;
optional bool directory_share = 9;
optional string play_url = 10;
optional string play_token = 11;
optional bool signals_on_server = 12;
optional uint64 signal_days = 13;
}
message Account {
int64 id = 1;
string name = 2;
bool admin = 3;
bool password = 4;
optional int64 created = 5;
optional int64 last_login = 6;
}
// GET /api/users.
message Accounts {
repeated Account items = 1;
}
// POST /api/users, the body.
message NewUser {
string name = 1;
optional string password = 2;
optional bool admin = 3;
}
// PATCH /api/users/{id}, the body.
message UserPatch {
bool admin = 1;
}
message LogLine {
uint64 seq = 1;
int64 ts = 2;
string level = 3;
string target = 4;
string msg = 5;
}
// GET /api/logs.
message LogPage {
repeated LogLine lines = 1;
uint64 latest = 2;
}
// POST /api/client, the body.
message ClientEvent {
string ev = 1;
optional string msg = 2;
optional string src = 3;
optional uint32 line = 4;
optional string feed = 5;
optional int64 enclosure = 6;
optional bool deadair = 7;
optional uint64 ms = 8;
optional string filter = 9;
optional string trace = 10;
optional string span = 11;
optional uint64 start = 12;
optional string state = 13;
}