mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-02 18:15:37 +00:00
remove extra size argument
This commit is contained in:
parent
1c0de40617
commit
eab1786918
1 changed files with 7 additions and 14 deletions
|
|
@ -3,7 +3,6 @@ use glib::{Bytes, Uri};
|
||||||
/// [Titan](gemini://transjovian.org/titan/page/The%20Titan%20Specification) protocol enum object for `Request`
|
/// [Titan](gemini://transjovian.org/titan/page/The%20Titan%20Specification) protocol enum object for `Request`
|
||||||
pub struct Titan {
|
pub struct Titan {
|
||||||
pub uri: Uri,
|
pub uri: Uri,
|
||||||
pub size: usize,
|
|
||||||
pub mime: String,
|
pub mime: String,
|
||||||
pub token: Option<String>,
|
pub token: Option<String>,
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
|
|
@ -13,16 +12,9 @@ impl Titan {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Build valid new `Self`
|
/// Build valid new `Self`
|
||||||
pub fn build(
|
pub fn build(uri: Uri, mime: String, token: Option<String>, data: Vec<u8>) -> Self {
|
||||||
uri: Uri,
|
|
||||||
size: usize,
|
|
||||||
mime: String,
|
|
||||||
token: Option<String>,
|
|
||||||
data: Vec<u8>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
uri,
|
uri,
|
||||||
size,
|
|
||||||
mime,
|
mime,
|
||||||
token,
|
token,
|
||||||
data,
|
data,
|
||||||
|
|
@ -33,18 +25,19 @@ impl Titan {
|
||||||
|
|
||||||
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)
|
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)
|
||||||
pub fn to_bytes(&self) -> Bytes {
|
pub fn to_bytes(&self) -> Bytes {
|
||||||
|
// Calculate data size
|
||||||
|
let size = self.data.len();
|
||||||
|
|
||||||
// Build header
|
// Build header
|
||||||
let mut header = format!("{};size={};mime={}", self.uri, self.size, self.mime);
|
let mut header = format!("{};size={size};mime={}", self.uri, self.mime);
|
||||||
if let Some(ref token) = self.token {
|
if let Some(ref token) = self.token {
|
||||||
header.push_str(&format!(";token={token}"));
|
header.push_str(&format!(";token={token}"));
|
||||||
}
|
}
|
||||||
header.push_str("\r\n");
|
header.push_str("\r\n");
|
||||||
|
|
||||||
let header_bytes = header.into_bytes();
|
|
||||||
|
|
||||||
// Build request
|
// Build request
|
||||||
let mut bytes: Vec<u8> = Vec::with_capacity(self.size + header_bytes.len());
|
let mut bytes: Vec<u8> = Vec::with_capacity(size + 1024); // @TODO
|
||||||
bytes.extend(header_bytes);
|
bytes.extend(header.into_bytes());
|
||||||
bytes.extend(&self.data);
|
bytes.extend(&self.data);
|
||||||
|
|
||||||
// Wrap result
|
// Wrap result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue