mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 17:45:35 +00:00
begin header holder implementation with lazy parser by getters, add request::Mode, add common header_bytes helper
This commit is contained in:
parent
a12a73d311
commit
7c518cecf6
13 changed files with 267 additions and 151 deletions
27
src/client/connection/response/success/default.rs
Normal file
27
src/client/connection/response/success/default.rs
Normal 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,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue