Skip to main content

vv_agent/app_server/transport/
mod.rs

1pub mod channel;
2pub mod stdio;
3
4use std::future::Future;
5use std::pin::Pin;
6
7use serde::{Deserialize, Serialize};
8
9use crate::app_server::protocol::{AppServerError, JsonRpcMessage};
10
11pub type TransportFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14#[serde(transparent)]
15pub struct ConnectionId(u64);
16
17impl ConnectionId {
18    pub fn new(value: u64) -> Self {
19        Self(value)
20    }
21
22    pub fn as_u64(self) -> u64 {
23        self.0
24    }
25}
26
27#[derive(Debug, Clone, PartialEq)]
28pub enum TransportEvent {
29    Opened {
30        connection_id: ConnectionId,
31    },
32    Message {
33        connection_id: ConnectionId,
34        message: JsonRpcMessage,
35    },
36    Closed {
37        connection_id: ConnectionId,
38    },
39}
40
41pub trait AppServerTransport {
42    fn next_event(&mut self)
43        -> TransportFuture<'_, Option<Result<TransportEvent, AppServerError>>>;
44
45    fn send(
46        &self,
47        connection_id: ConnectionId,
48        message: JsonRpcMessage,
49    ) -> TransportFuture<'_, Result<(), AppServerError>>;
50}