MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / readMessage

Function readMessage

crates/opencode-plugin/host/plugin-host.ts:120–138  ·  view source on GitHub ↗

* Read one Content-Length framed JSON-RPC message from stdin. * Returns null on EOF.

()

Source from the content-addressed store, hash-verified

118 * Returns null on EOF.
119 */
120async function readMessage(): Promise<JsonRpcRequest | null> {
121 // Read header lines until empty line
122 let header = "";
123 while (true) {
124 const byte = await readExact(1);
125 if (byte.length === 0) return null;
126 header += decoder.decode(byte);
127 if (header.endsWith("\r\n\r\n")) break;
128 }
129
130 const match = header.match(/Content-Length:\s*(\d+)/i);
131 if (!match) {
132 throw new Error(`Invalid header: ${header}`);
133 }
134
135 const contentLength = parseInt(match[1], 10);
136 const body = await readExact(contentLength);
137 return JSON.parse(decoder.decode(body));
138}
139
140function send(response: JsonRpcResponse): void {
141 process.stdout.write(encodeResponse(response));

Callers 1

mainFunction · 0.85

Calls 2

readExactFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected