vv_agent/app_server/transport/
mod.rs1pub 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 ProtocolError {
37 connection_id: ConnectionId,
38 error: AppServerError,
39 },
40 Closed {
41 connection_id: ConnectionId,
42 },
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46pub enum TransportConnectionMode {
47 Single,
48 Multiple,
49}
50
51pub trait AppServerTransport {
52 fn next_event(&mut self)
53 -> TransportFuture<'_, Option<Result<TransportEvent, AppServerError>>>;
54
55 fn send(
56 &self,
57 connection_id: ConnectionId,
58 message: JsonRpcMessage,
59 ) -> TransportFuture<'_, Result<(), AppServerError>>;
60
61 fn connection_mode(&self) -> TransportConnectionMode {
62 TransportConnectionMode::Single
63 }
64}