(self)
| 213 | return {"jsonrpc": "2.0", "id": req_id, "result": result} |
| 214 | |
| 215 | def run(self): |
| 216 | log("在 stdin 上监听 JSON-RPC 2.0 消息...") |
| 217 | |
| 218 | for raw_line in sys.stdin: |
| 219 | line = raw_line.strip() |
| 220 | if not line: |
| 221 | continue |
| 222 | try: |
| 223 | msg = json.loads(line) |
| 224 | response = self.dispatch(msg) |
| 225 | if response is not None: |
| 226 | print(json.dumps(response, ensure_ascii=False), flush=True) |
| 227 | except json.JSONDecodeError as e: |
| 228 | log(f"JSON 解析错误: {e} | 输入: {line[:60]}") |
| 229 | except Exception as e: |
| 230 | log(f"调度错误: {e}") |
| 231 | |
| 232 | |
| 233 | if __name__ == "__main__": |
no test coverage detected