use crate::effect::{Correlation, FileUploadProgress, TimerId, TransportId};
use std::borrow::Cow;
#[derive(Debug, Clone)]
pub struct InboundBytes(pub bytes::Bytes);
impl InboundBytes {
pub fn from_static(s: &'static [u8]) -> Self {
Self(bytes::Bytes::from_static(s))
}
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
}
#[derive(Debug, Clone)]
pub enum PortOutcome {
Ok(ReplyBytes),
Err(PortError),
}
#[derive(Debug, Default, Clone)]
pub struct ReplyBytes(pub bytes::Bytes);
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PortError {
Timeout,
Http(u16),
Storage(u32),
Network,
Other(u32),
}
#[derive(Debug, Clone)]
pub struct AppCommand {
pub name: Cow<'static, str>,
pub payload: bytes::Bytes,
}
impl AppCommand {
pub fn new(name: &'static str, payload: impl Into<bytes::Bytes>) -> Self {
Self {
name: Cow::Borrowed(name),
payload: payload.into(),
}
}
}
#[derive(Debug, Clone)]
pub enum Tick {
Inbound(InboundBytes),
PortReply {
corr: Correlation,
outcome: PortOutcome,
},
PortProgress {
corr: Correlation,
progress: FileUploadProgress,
},
Timer(TimerId),
Command(AppCommand),
Connected(TransportId),
Disconnected(TransportId),
}