Problem
msgbuf currently only generates Java classes from .proto files. For web applications using SSE (Server-Sent Events) or WebSocket protocols, the client-side TypeScript/JavaScript deserialization and dispatch code must be written by hand. This is repetitive, error-prone, and defeats the purpose of a code generator.
Use Case
A server sends SSE events defined in a .proto file. The Java server code is generated, but the TypeScript client code must be manually written:
// Currently hand-written for each message type:
function dispatchSSEEvent(json: any): void {
switch (json._type) {
case "PatchEvent":
handlePatch(json.controlId, json.patch);
break;
case "StateEvent":
handleState(json.controlId, json.state);
break;
// ... every new event type requires manual additions
}
}
Proposed Solution
Add a TypeScript/JavaScript code generation target to msgbuf. From the same .proto file, generate:
- TypeScript interfaces/classes with typed properties
- JSON deserialization (
fromJson / readFrom methods)
- JSON serialization (
toJson / writeTo methods)
- Polymorphic dispatch for abstract message hierarchies (automatic type-tag based deserialization)
Example generated output:
// Generated from sse.proto
export abstract class SSEEvent {
static fromJson(reader: JsonReader): SSEEvent { /* dispatch by _type */ }
}
export class PatchEvent extends SSEEvent {
controlId: string;
patch: string;
static fromJson(reader: JsonReader): PatchEvent { ... }
toJson(writer: JsonWriter): void { ... }
}
This would ensure client and server are always in sync and eliminate an entire class of serialization bugs.
Problem
msgbuf currently only generates Java classes from
.protofiles. For web applications using SSE (Server-Sent Events) or WebSocket protocols, the client-side TypeScript/JavaScript deserialization and dispatch code must be written by hand. This is repetitive, error-prone, and defeats the purpose of a code generator.Use Case
A server sends SSE events defined in a
.protofile. The Java server code is generated, but the TypeScript client code must be manually written:Proposed Solution
Add a TypeScript/JavaScript code generation target to msgbuf. From the same
.protofile, generate:fromJson/readFrommethods)toJson/writeTomethods)Example generated output:
This would ensure client and server are always in sync and eliminate an entire class of serialization bugs.