mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
27 lines
570 B
Rust
27 lines
570 B
Rust
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(Error::Header)?;
|
|
Ok(Self {
|
|
content: buffer.get(header.len() + 1..).map(|v| v.to_vec()),
|
|
header,
|
|
})
|
|
}
|
|
}
|