Appearance
| 1 | @@IF.dotnet() | |
| 2 | ||
| 3 | namespace Analysis.Protocol is | |
| 4 | // Wire helper for the JSON analysis protocol. One JSON object per line, | |
| 5 | // newline-terminated; a message never contains a raw newline (JSON escapes | |
| 6 | // them inside strings), so `read_line` is a complete framing primitive. | |
| 7 | // | |
| 8 | // Requests deserialize into the REQUEST discriminated union (by the | |
| 9 | // `command` field); responses serialize from the RESPONSE union (tagged | |
| 10 | // with `kind`). Wire field names are the ghūl property names verbatim | |
| 11 | // (snake_case). Both go through REFLECTION_JSON rather than | |
| 12 | // System.Text.Json's reflection path, which a Native AOT build cannot run. | |
| 13 | class JSON_PROTOCOL is | |
| 14 | // Deserialize one request line. A malformed line throws; the reader | |
| 15 | // thread catches it and queues a PARSE_ERROR frame, which the | |
| 16 | // despatcher answers with an error response. | |
| 17 | deserialize_request(line: string) -> Request? static => | |
| 18 | cast Request?(REFLECTION_JSON.read(line, typeof Request)) | |
| 19 | ||
| 20 | // Serialize a response onto a single line and flush. Every response | |
| 21 | // frame is one line; the client splits stdout on '\n'. | |
| 22 | write_response(writer: IO.TextWriter, response: Response) static is | |
| 23 | writer.write(REFLECTION_JSON.write(response, typeof Response)) | |
| 24 | writer.write("\n") | |
| 25 | writer.flush() | |
| 26 | si | |
| 27 | si | |
| 28 | si |