#json-rpc-server #rpc-server #client #standard #error #memory

no-std embedded-jsonrpc

A JSON-RPC 2.0 server implementation for embedded systems

4 releases (2 breaking)

new 0.3.0 Nov 28, 2024
0.2.1 Nov 28, 2024
0.2.0 Nov 28, 2024
0.1.0 Nov 26, 2024

#323 in Embedded development

Download history 104/week @ 2024-11-21

104 downloads per month

MPL-2.0 license

23KB
425 lines

embedded-jsonrpc

A JSON-RPC 2.0 server implementation for embedded systems.

Usage

embedded-jsonrpc = { version = 0.3, default-features = false, features = ["defmt"] }

lib.rs:

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

Dependencies

~1.8–2.7MB
~56K SLoC