use std::net::SocketAddr;
mod connection;
mod custom;
mod dispatch;
mod protocol;
pub(crate) use connection::ConnectionProtocol;
pub use custom::CustomProtocolHooks;
pub use dispatch::ProtocolDispatch;
pub use protocol::ProtocolHooks;
use crate::{
codec::EofError,
push::{FrameLike, PushHandle},
session::ConnectionId,
};
#[derive(Clone, Default)]
#[non_exhaustive]
pub struct ConnectionContext {
connection_id: Option<ConnectionId>,
peer_addr: Option<SocketAddr>,
}
impl ConnectionContext {
pub(crate) const fn with_published_id(mut self, connection_id: ConnectionId) -> Self {
self.connection_id = Some(connection_id);
self
}
pub(crate) const fn with_peer_addr(mut self, peer_addr: Option<SocketAddr>) -> Self {
self.peer_addr = peer_addr;
self
}
#[must_use]
pub const fn connection_id(&self) -> Option<ConnectionId> { self.connection_id }
#[must_use]
pub const fn peer_addr(&self) -> Option<SocketAddr> { self.peer_addr }
}
pub trait WireframeProtocol: Send + Sync + 'static {
type Frame: FrameLike;
type ProtocolError;
fn on_connection_setup(&self, _handle: PushHandle<Self::Frame>, _ctx: &mut ConnectionContext) {}
fn before_send(&self, _frame: &mut Self::Frame, _ctx: &mut ConnectionContext) {}
fn on_command_end(&self, _ctx: &mut ConnectionContext) {}
fn handle_error(&self, _error: Self::ProtocolError, _ctx: &mut ConnectionContext) {}
fn stream_end_frame(&self, _ctx: &mut ConnectionContext) -> Option<Self::Frame> { None }
fn on_eof(&self, _error: &EofError, _partial_data: &[u8], _ctx: &mut ConnectionContext) {}
}