Expand description
§JSON-RPC for Embedded Systems
This crate provides a JSON-RPC server implementation for embedded systems.
§Features
#![no_std]
Support: Fully compatible with environments lacking a standard library.- Predictable Memory Usage: Zero dynamic allocation with statically sized buffers.
- Async: Non-blocking I/O with
embedded-io-async
. - Client Compatibility: Uses LSP style framing for JSON-RPC messages.
- Error Handling: Adheres to JSON-RPC standards with robust error reporting.
§Example Usage
§Create an RPC Server
use embedded_jsonrpc::{RpcServer, RpcResponse, JSONRPC_VERSION};
let mut server: RpcServer<'_> = RpcServer::new();
server.register_method("echo", |id, _request_json, response_json| {
let response = RpcResponse {
jsonrpc: JSONRPC_VERSION,
id,
error: None,
};
Ok(serde_json_core::to_slice(&response, response_json).unwrap())
});
§Serve Requests
ⓘ
let mut stream: YourAsyncStream = YourAsyncStream::new();
server.serve(&mut stream).await.unwrap();
§License
This crate is licensed under the Mozilla Public License 2.0 (MPL-2.0). See the LICENSE file for more details.
§References
Structs§
- JSON-RPC Error structure
- JSON-RPC Request structure
- JSON-RPC Response structure
- RPC server
Enums§
- JSON-RPC Standard Error Codes
- Type for errors returned by the RPC server
Constants§
- JSON-RPC Version Currently only supports version 2.0 https://www.jsonrpc.org/specification
Type Aliases§
- Type for RPC handler functions