OpenCore JSON-RPC Rust
A simple and elegant library for creating JSON-RPC servers that communicate with TypeScript frameworks via stdin/stdout.
Features
- Simple API - Register handlers with a clean, type-safe interface
- Line-delimited JSON - Easy integration with any language that can spawn processes
- Automatic serialization - Request/response handling is transparent
- Robust error handling - Clear error messages and graceful failure modes
- Well-tested - Comprehensive unit and integration tests
- Fully documented - Complete API documentation with examples
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use BinaryServer;
use Value;
Protocol
Request Format
Requests are sent as line-delimited JSON to stdin:
Response Format
Responses are written as line-delimited JSON to stdout:
Success:
Error:
Examples
Basic Math Operations
use BinaryServer;
use Value;
String Operations
use BinaryServer;
use Value;
Complex Data Structures
use BinaryServer;
use ;
TypeScript Integration
Here's how to use this library from TypeScript (Using OpenCore Framework):
import { Server } from '@open-core/framework/server'
@Server.BinaryService({
name: 'math',
binary: 'math',
timeoutMs: 2000,
})
export class MathBinaryService {
@Server.BinaryCall({ action: 'sum' })
sum(a: number, b: number): Promise<number> {
throw new Error('BinaryCall proxy')
// or return null as any
}
}
Error Handling
Handlers should return Result<Value, String>:
Ok(value)- Success with a JSON valueErr(message)- Error with a descriptive message
The server automatically handles:
- Invalid JSON in requests
- Unknown actions
- Serialization errors
- I/O errors
Testing
Run the test suite:
Run with output:
Documentation
Generate and view the full API documentation:
License
MIT
Contributing
Contributions are welcome! Please ensure:
- All tests pass (
cargo test) - Code is formatted (
cargo fmt) - No clippy warnings (
cargo clippy) - Documentation is updated