opencore_jsonrpc_rust/
lib.rs

1//! # OpenCore JSON-RPC Rust
2//!
3//! A simple and elegant library for creating JSON-RPC servers that communicate
4//! with TypeScript frameworks via stdin/stdout.
5//!
6//! ## Features
7//!
8//! - Simple handler registration with type-safe function signatures
9//! - Line-delimited JSON protocol for easy integration
10//! - Automatic request/response serialization
11//! - Clean error handling
12//!
13//! ## Quick Start
14//!
15//! ```no_run
16//! use opencore_jsonrpc_rust::server::BinaryServer;
17//! use serde_json::Value;
18//!
19//! fn add(params: Vec<Value>) -> Result<Value, String> {
20//!     if params.len() != 2 {
21//!         return Err("Expected 2 parameters".into());
22//!     }
23//!     let a = params[0].as_i64().ok_or("Invalid number")?;
24//!     let b = params[1].as_i64().ok_or("Invalid number")?;
25//!     Ok(Value::from(a + b))
26//! }
27//!
28//! fn main() {
29//!     let mut server = BinaryServer::new();
30//!     server.register("add", add);
31//!     server.run();
32//! }
33//! ```
34//!
35//! ## Protocol
36//!
37//! ### Request Format
38//!
39//! ```json
40//! {
41//!   "id": "unique-request-id",
42//!   "action": "method-name",
43//!   "params": [arg1, arg2, ...]
44//! }
45//! ```
46//!
47//! ### Response Format (Success)
48//!
49//! ```json
50//! {
51//!   "status": "ok",
52//!   "id": "unique-request-id",
53//!   "result": <value>
54//! }
55//! ```
56//!
57//! ### Response Format (Error)
58//!
59//! ```json
60//! {
61//!   "status": "error",
62//!   "id": "unique-request-id",
63//!   "error": "error message"
64//! }
65//! ```
66
67pub mod protocol;
68pub mod server;