Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cortesi/mrpc
A MessagePack-RPC implementation for Rust
https://github.com/cortesi/mrpc
messagepack messagepack-rpc rpc
Last synced: 23 days ago
JSON representation
A MessagePack-RPC implementation for Rust
- Host: GitHub
- URL: https://github.com/cortesi/mrpc
- Owner: cortesi
- License: mit
- Created: 2024-07-28T02:16:59.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-08-06T03:31:59.000Z (3 months ago)
- Last Synced: 2024-10-06T07:08:11.755Z (about 1 month ago)
- Topics: messagepack, messagepack-rpc, rpc
- Language: Rust
- Homepage:
- Size: 137 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Crates.io](https://img.shields.io/crates/v/mrpc.svg)](https://crates.io/crates/mrpc)
[![Documentation](https://docs.rs/mrpc/badge.svg)](https://docs.rs/mrpc)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)# mrpc
A MessagePack-RPC implementation in Rust.
## Features
- Write asynchronous RPC servers and clients
- Support for TCP and Unix domain sockets
- Full msgpack-rpc implementation (requests, responses, notifications)
- Support for bidirectional communication - both servers and clients can handle incoming RPC messages
- Built on `tokio` for async I/O
- Uses `rmpv` for MessagePack serialization## Quick Start
```rust
use mrpc::{Client, Connection, Result, RpcSender, Server};
use rmpv::Value;#[derive(Clone, Default)]
struct Echo;#[async_trait::async_trait]
impl Connection for Echo {
async fn handle_request(
&self,
_: RpcSender,
method: &str,
params: Vec,
) -> Result {
Ok(format!("{} -> {}", method, params[0]).into())
}
}#[tokio::main]
async fn main() -> Result<()> {
// We're just using the default constructor as our ConnectionMaker
let server = Server::from_fn(Echo::default).tcp("127.0.0.1:0").await?;
let addr = server.local_addr().unwrap();
tokio::spawn(server.run());// `Connection` is implemented for (), as a convenience for clients who don't need to handle
// requests or responses.
let client = Client::connect_tcp(&addr.to_string(), ()).await?;
let result = client
.send_request("echo", &[Value::String("Hello there!".into())])
.await?;
println!("{}", result);
Ok(())
}
```