pub mod gemini;
pub mod titan;
pub use gemini::Gemini;
pub use titan::Titan;
pub enum Request<'a> {
Gemini(Gemini),
Titan(Titan<'a>),
}
impl<'a> Request<'a> {
pub fn from_bytes(buffer: &'a [u8]) -> Result<Self> {
match buffer.first() {
Some(b) => match b {
b'g' => Ok(Self::Gemini(Gemini::from_bytes(buffer)?)),
b't' => Ok(Self::Titan(Titan::from_bytes(buffer)?)),
_ => bail!("Leading byte error"),
},
None => bail!("Empty request"),
}
}
pub fn into_bytes(self) -> Vec<u8> {
match self {
Self::Gemini(this) => this.into_bytes(),
Self::Titan(this) => this.into_bytes(),
}
}
}
use anyhow::{bail, Result};