draft new api version

This commit is contained in:
yggverse 2024-10-26 23:22:26 +03:00
parent 8a5f1e2a57
commit 3cde80b6a8
22 changed files with 323 additions and 747 deletions

View file

@ -1,15 +1,18 @@
pub mod error;
pub use error::Error;
use glib::GString;
use glib::{Bytes, GString};
/// Entire meta buffer, but [status code](https://geminiprotocol.net/docs/protocol-specification.gmi#status-codes).
///
/// Usefult to grab placeholder text on 10, 11, 31 codes processing
pub struct Meta {
buffer: Vec<u8>,
}
impl Meta {
pub fn from_header(buffer: &[u8] /* @TODO */) -> Result<Self, Error> {
let buffer = match buffer.get(2..) {
pub fn from_header(bytes: &Bytes) -> Result<Self, Error> {
let buffer = match bytes.get(3..) {
Some(bytes) => bytes.to_vec(),
None => return Err(Error::Undefined),
};
@ -23,4 +26,8 @@ impl Meta {
Err(_) => Err(Error::Undefined),
}
}
pub fn buffer(&self) -> &[u8] {
&self.buffer
}
}