Skip to main content

rusty_tpkt/
api.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum TpktError {
5    #[error("TPKT Protocol Error - {}", .0)]
6    ProtocolError(String),
7
8    #[error("TPKT IO Error: {:?}", .0)]
9    IoError(#[from] std::io::Error),
10
11    #[error("TPKT Error: {}", .0)]
12    InternalError(String),
13}
14
15pub enum TpktRecvResult {
16    Closed,
17    Data(Vec<u8>),
18}
19
20pub trait TpktConnection: Send {
21    fn split(self) -> impl std::future::Future<Output = Result<(impl TpktReader, impl TpktWriter), TpktError>> + Send;
22}
23
24pub trait TpktReader: Send {
25    fn recv(&mut self) -> impl std::future::Future<Output = Result<TpktRecvResult, TpktError>> + Send;
26}
27
28pub trait TpktWriter: Send {
29    fn send(&mut self, data: &[u8]) -> impl std::future::Future<Output = Result<(), TpktError>> + Send;
30    fn continue_send(&mut self) -> impl std::future::Future<Output = Result<(), TpktError>> + Send;
31}