capnproto-rust icon indicating copy to clipboard operation
capnproto-rust copied to clipboard

Is there a way for a server to accept multiple type of clients?

Open neodes-h opened this issue 3 years ago • 1 comments

Hi there,

I have two interfaces:

interface Margin {
    struct Item {
        symbolId @0 : Int32;
        price @1 : Float64;
        amount @2 : Int32
    }

    get @0 () -> (margin: List(Item));
}

interface StockWatchList {
    struct Stock {
        symbolId @0 : Int32;
        exId @1 : Int16; 
    }

    struct Delay {
        symbolId @0 : Int32; 
        exId @1 : Int16; 
        spiderDelay @2 : Int32; 
        source @3 : Int16;
    }

    getWatchList @0 () -> (stock_list: List(Stock));
    insertDelay @1(delay: Delay);
}

I'm trying to implement a server accepting either a margin::Client or a stock_watch_list::Client, but when constructing the rpc system, I have to specify the type of the client:

struct RpcClient;
impl margin::Server for RpcClient {...}
impl stock_watch_list::Server for RpcClient {...}

let client: margin::Client = capnp_rpc::new_client(RpcClient);
// or 
// let client: stock_watch_list::Client = capnp_rpc::new_client(RpcClient);
let rpc_system = RpcSystem::new(network, Some(client.clone().client));

Is there a way to enable this system to accept multiple types of clients?

Thanks a lot.

neodes-h avatar Feb 24 '22 02:02 neodes-h

You could define a new interface that gives access to both of your existing interfaces:

interface Meta {
  getMargin @0 () -> Margin;
  getStockWatchList @1 () -> StockWatchList;
}

dwrensha avatar Jun 05 '22 17:06 dwrensha

Another thing that might work is to define an interface that extends both of your existing interfaces:

interface Meta extends (Margin, StockWatchList) {}

dwrensha avatar Nov 07 '22 15:11 dwrensha