bep 47: serialize/deserialize new fields

This commit is contained in:
Igor Katson 2024-10-14 14:55:48 +01:00
parent 60cea68985
commit af0389de05
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
3 changed files with 39 additions and 1 deletions

View file

@ -124,7 +124,13 @@ async fn create_torrent_raw<'a>(
.components()
.map(|c| osstr_to_bytes(c.as_os_str()).into())
.collect();
output_files.push(TorrentMetaV1File { length, path });
output_files.push(TorrentMetaV1File {
length,
path,
attr: None,
sha1: None,
symlink_path: None,
});
continue 'outer;
}
@ -154,6 +160,9 @@ async fn create_torrent_raw<'a>(
} else {
Some(output_files)
},
attr: None,
sha1: None,
symlink_path: None,
})
}

View file

@ -402,9 +402,15 @@ mod tests {
.map(|f| TorrentMetaV1File {
length: 1,
path: f.split("/").map(|f| f.as_bytes().into()).collect(),
attr: None,
sha1: None,
symlink_path: None,
})
.collect(),
),
attr: None,
sha1: None,
symlink_path: None,
},
comment: None,
created_by: None,

View file

@ -99,6 +99,12 @@ pub struct TorrentMetaV1Info<BufType> {
// Single-file mode
#[serde(skip_serializing_if = "Option::is_none")]
pub length: Option<u64>,
#[serde(default = "none")]
pub attr: Option<BufType>,
#[serde(default = "none")]
pub sha1: Option<BufType>,
#[serde(default = "none", rename = "symlink path")]
pub symlink_path: Option<Vec<BufType>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub md5sum: Option<BufType>,
@ -253,10 +259,21 @@ impl<BufType: AsRef<[u8]>> TorrentMetaV1Info<BufType> {
}
}
const fn none<T>() -> Option<T> {
None
}
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct TorrentMetaV1File<BufType> {
pub length: u64,
pub path: Vec<BufType>,
#[serde(default = "none")]
pub attr: Option<BufType>,
#[serde(default = "none")]
pub sha1: Option<BufType>,
#[serde(default = "none", rename = "symlink path")]
pub symlink_path: Option<Vec<BufType>>,
}
impl<BufType> TorrentMetaV1File<BufType>
@ -282,6 +299,9 @@ where
TorrentMetaV1File {
length: self.length,
path: self.path.clone_to_owned(within_buffer),
attr: self.attr.clone_to_owned(within_buffer),
sha1: self.sha1.clone_to_owned(within_buffer),
symlink_path: self.symlink_path.clone_to_owned(within_buffer),
}
}
}
@ -300,6 +320,9 @@ where
length: self.length,
md5sum: self.md5sum.clone_to_owned(within_buffer),
files: self.files.clone_to_owned(within_buffer),
attr: self.attr.clone_to_owned(within_buffer),
sha1: self.sha1.clone_to_owned(within_buffer),
symlink_path: self.symlink_path.clone_to_owned(within_buffer),
}
}
}