use std::fmt::Debug;
use bytes::Bytes;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ResumptionMessage {
pub command: Command,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Command {
Start(u64),
Resume(u64),
ResumeOk(u64),
ResumeErr(u64),
Forward(Data),
}
#[derive(Clone, Eq, PartialEq)]
pub struct Data {
pub chunk: Bytes,
}
impl From<Bytes> for Data {
fn from(value: Bytes) -> Self {
Data { chunk: value }
}
}
impl Debug for Data {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Data(len: {})", self.chunk.len())
}
}
impl From<Bytes> for Command {
fn from(value: Bytes) -> Self {
Command::Forward(Data::from(value))
}
}
impl From<Command> for ResumptionMessage {
fn from(command: Command) -> Self {
ResumptionMessage::new(command)
}
}
impl From<Bytes> for ResumptionMessage {
fn from(value: Bytes) -> Self {
ResumptionMessage::from(Command::from(value))
}
}
impl ResumptionMessage {
pub fn new(command: Command) -> Self {
Self { command }
}
}