mod framed;
#[cfg(feature = "tcp")]
pub mod tcp;
#[cfg(feature = "usb")]
pub mod usb;
pub use framed::{FramedReader, FramedWriter, StreamTransport};
use crate::error::Result;
use crate::wire::{MAX_PAYLOAD, Message, VERSION_SKIP_CHECKSUM};
use std::future::Future;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WireConfig {
pub compute_checksum: bool,
pub verify_checksum: bool,
pub max_payload: u32,
}
impl WireConfig {
pub const INITIAL: Self = Self {
compute_checksum: true,
verify_checksum: false,
max_payload: MAX_PAYLOAD,
};
pub fn negotiated(version: u32, max_payload: u32) -> Self {
let checksum = version < VERSION_SKIP_CHECKSUM;
Self {
compute_checksum: checksum,
verify_checksum: checksum,
max_payload,
}
}
}
pub trait MessageSink: Send {
fn send(&mut self, msg: Message) -> impl Future<Output = Result<()>> + Send;
}
pub trait MessageSource: Send {
fn recv(&mut self) -> impl Future<Output = Result<Message>> + Send;
}
pub trait Transport: MessageSink + MessageSource + 'static {
type Sink: MessageSink + 'static;
type Source: MessageSource + 'static;
fn configure(&mut self, config: WireConfig);
fn split(self) -> (Self::Sink, Self::Source);
}