Crate msgpack_rpc [] [src]

An implementation of Msgpack-RPC, based on tokio-proto and rmp.

This crate focuses on bi-directional RPC on single I/O.

Example

// Create a client from an I/O.
let endpoint = msgpack_rpc::Endpoint::from_io(&handle, StdioStream::new(4, 4));
let client = endpoint.into_client();

// Call a precedure and receive its response asynchronously.
let task = client.request("hello", vec![])
    .and_then(|response| {
        eprintln!("{:?}", response);
        ok(())
    });

// Start the event loop.
core.run(task).unwrap();

You can serve request/notifications from peer, by using endpoint:

use msgpack_rpc::Handler;

struct RootHandler {
    /* ... */
}

impl Handler for RootHandler {
    type RequestFuture = BoxFuture<Value, Value>;
    type NofityFuture = BoxFuture<(), ()>;

    fn handle_request(
        &self,
        method: &str,
        params: Value,
        client: &Client,
    ) -> Self::RequestFuture {
        // ...
    }

    fn handle_notification(
        &self,
        method: &str,
        params: Value,
        client: &Client,
    ) -> Self::NotifyFuture {
        // ...
    }
}

// Launch an endpoint service on the event loop of `handle`.
// It will spawn a service to handle requests/notifications from a peer.
endpoint.launch(&handle, RootHandler { /* ... */ });

Modules

io

definition of I/O streams and helper functions.

Structs

Ack
Client

A client of Msgpack-RPC

Endpoint

An endpoint represents a peer of MessagePack-RPC.

Response

The return type of Client::request(), represents a future of RPC request.

Enums

Value

Represents any valid MessagePack value.

Traits

Handler

A handler of requests/notifications.