workflow_rpc/server/protocol/
mod.rs

1//!
2//! Protocol module containing protocol handlers in charge
3//! of incoming and outgoing message serialization and
4//! RPC method and notification dispatch.
5//!
6
7pub mod borsh;
8pub mod serde_json;
9
10use crate::imports::*;
11pub use crate::server::result::Result;
12use crate::server::Interface;
13use workflow_websocket::server::{Message, Result as WebSocketResult, WebSocketSink};
14
15pub use self::borsh::BorshProtocol;
16pub use self::serde_json::JsonProtocol;
17
18/// Base trait for [`BorshProtocol`] and [`JsonProtocol`] protocol handlers
19#[async_trait]
20pub trait ProtocolHandler<ServerContext, ConnectionContext, Ops>:
21    DowncastSync + Sized + Send + Sync
22where
23    Ops: OpsT,
24    ServerContext: Clone + Send + Sync + 'static,
25    ConnectionContext: Clone + Send + Sync + 'static,
26{
27    fn new(methods: Arc<Interface<ServerContext, ConnectionContext, Ops>>) -> Self
28    where
29        Self: Sized;
30
31    fn encoding(&self) -> Encoding;
32
33    async fn handle_message(
34        &self,
35        connection_ctx: ConnectionContext,
36        message: Message,
37        sink: &WebSocketSink,
38    ) -> WebSocketResult<()>;
39
40    fn serialize_notification_message<Msg>(
41        &self,
42        op: Ops,
43        msg: Msg,
44    ) -> Result<tungstenite::Message>
45    where
46        Msg: BorshSerialize + Serialize + Send + Sync + 'static;
47}