From 7d6c0e68a19ad5e2e4e05cfc219d446be6ff2286 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Thu, 30 Nov 2023 22:52:53 +0300 Subject: jsonrpc: Enhance the API and add support for TCP, Unix, and TLS protocols. --- jsonrpc/src/lib.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'jsonrpc/src/lib.rs') diff --git a/jsonrpc/src/lib.rs b/jsonrpc/src/lib.rs index f73b5e6..65fb38f 100644 --- a/jsonrpc/src/lib.rs +++ b/jsonrpc/src/lib.rs @@ -1,4 +1,5 @@ -//! A fast and lightweight async [JSONRPC 2.0](https://www.jsonrpc.org/specification) implementation. +//! A fast and lightweight async implementation of [JSON-RPC +//! 2.0](https://www.jsonrpc.org/specification), supporting the Tcp and Unix protocols. //! //! # Example //! @@ -6,6 +7,7 @@ //! use std::sync::Arc; //! //! use serde_json::Value; +//! use smol::net::{TcpStream, TcpListener}; //! //! use karyons_jsonrpc::{JsonRPCError, Server, Client, register_service, ServerConfig, ClientConfig}; //! @@ -23,9 +25,9 @@ //! let ex = Arc::new(smol::Executor::new()); //! //! // Creates a new server -//! let endpoint = "tcp://127.0.0.1:60000".parse().unwrap(); +//! let listener = TcpListener::bind("127.0.0.1:60000").await.unwrap(); //! let config = ServerConfig::default(); -//! let server = Server::new_with_endpoint(&endpoint, config, ex.clone()).await.unwrap(); +//! let server = Server::new(listener.into(), config, ex.clone()); //! //! // Register the HelloWorld service //! register_service!(HelloWorld, say_hello); @@ -39,9 +41,9 @@ //! async { //! //! // Creates a new client -//! let endpoint = "tcp://127.0.0.1:60000".parse().unwrap(); +//! let conn = TcpStream::connect("127.0.0.1:60000").await.unwrap(); //! let config = ClientConfig::default(); -//! let client = Client::new_with_endpoint(&endpoint, config).await.unwrap(); +//! let client = Client::new(conn.into(), config); //! //! let result: String = client.call("HelloWorld.say_hello", "world".to_string()).await.unwrap(); //! }; @@ -55,12 +57,13 @@ pub mod message; mod server; mod service; -pub const JSONRPC_VERSION: &str = "2.0"; - -use error::{Error, Result}; - pub use client::{Client, ClientConfig}; pub use codec::CodecConfig; pub use error::Error as JsonRPCError; pub use server::{Server, ServerConfig}; pub use service::{RPCMethod, RPCService}; + +pub use karyons_net::Endpoint; + +const JSONRPC_VERSION: &str = "2.0"; +use error::{Error, Result}; -- cgit v1.2.3