Skip to main content

ProtocolHandler

Trait ProtocolHandler 

Source
pub trait ProtocolHandler<ServerContext, ConnectionContext, Ops>:
    DowncastSync
    + Sized
    + Send
    + Sync
where Ops: OpsT, ServerContext: Clone + Send + Sync + 'static, ConnectionContext: Clone + Send + Sync + 'static,
{ // Required methods fn new( methods: Arc<Interface<ServerContext, ConnectionContext, Ops>>, ) -> Self where Self: Sized; fn encoding(&self) -> Encoding; fn handle_message<'life0, 'life1, 'async_trait>( &'life0 self, connection_ctx: ConnectionContext, message: Message, sink: &'life1 WebSocketSink, ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn serialize_notification_message<Msg>( &self, op: Ops, msg: Msg, ) -> Result<Message> where Msg: BorshSerialize + Serialize + Send + Sync + 'static; }
Expand description

Base trait for BorshProtocol and JsonProtocol protocol handlers

Required Methods§

Source

fn new(methods: Arc<Interface<ServerContext, ConnectionContext, Ops>>) -> Self
where Self: Sized,

Construct a protocol handler backed by the given RPC method/notification interface.

Source

fn encoding(&self) -> Encoding

Return the wire encoding (Borsh or JSON) implemented by this handler.

Source

fn handle_message<'life0, 'life1, 'async_trait>( &'life0 self, connection_ctx: ConnectionContext, message: Message, sink: &'life1 WebSocketSink, ) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Decode an incoming WebSocket message, dispatch it to the matching method or notification handler, and send any response back through the sink.

Source

fn serialize_notification_message<Msg>( &self, op: Ops, msg: Msg, ) -> Result<Message>
where Msg: BorshSerialize + Serialize + Send + Sync + 'static,

Serialize a server-initiated notification for the given operation and message into an outgoing WebSocket message.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<ServerContext, ConnectionContext, Ops, Id> ProtocolHandler<ServerContext, ConnectionContext, Ops> for BorshProtocol<ServerContext, ConnectionContext, Ops, Id>
where ServerContext: Clone + Send + Sync + 'static, ConnectionContext: Clone + Send + Sync + 'static, Ops: OpsT, Id: IdT,

Source§

impl<ServerContext, ConnectionContext, Ops, Id> ProtocolHandler<ServerContext, ConnectionContext, Ops> for JsonProtocol<ServerContext, ConnectionContext, Ops, Id>
where ServerContext: Clone + Send + Sync + 'static, ConnectionContext: Clone + Send + Sync + 'static, Ops: OpsT, Id: IdT,