begin header holder implementation with lazy parser by getters, add request::Mode, add common header_bytes helper

This commit is contained in:
yggverse 2025-03-24 06:50:08 +02:00
parent a12a73d311
commit 7c518cecf6
13 changed files with 267 additions and 151 deletions

View file

@ -0,0 +1,27 @@
pub mod error;
pub mod header;
pub use error::Error;
pub use header::Header;
pub const CODE: &[u8] = b"20";
pub struct Default {
pub header: Header,
pub content: Option<Vec<u8>>,
}
impl Default {
// Constructors
pub fn parse(buffer: &[u8]) -> Result<Self, Error> {
if !buffer.starts_with(CODE) {
return Err(Error::Code);
}
let header = Header::parse(buffer).map_err(|e| Error::Header(e))?;
Ok(Self {
content: buffer.get(header.len() + 1..).map(|v| v.to_vec()),
header,
})
}
}