2019-05-24 01:25:55 -07:00
|
|
|
use crate::common::*;
|
|
|
|
|
2020-02-14 00:12:49 -08:00
|
|
|
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
|
2020-02-04 08:51:56 -08:00
|
|
|
pub(crate) struct Info {
|
2020-02-14 00:12:49 -08:00
|
|
|
#[serde(
|
|
|
|
skip_serializing_if = "Option::is_none",
|
|
|
|
default,
|
|
|
|
with = "unwrap_or_skip"
|
|
|
|
)]
|
|
|
|
pub(crate) private: Option<bool>,
|
2019-05-24 01:25:55 -07:00
|
|
|
#[serde(rename = "piece length")]
|
2020-02-14 00:12:49 -08:00
|
|
|
pub(crate) piece_length: Bytes,
|
2020-02-04 08:51:56 -08:00
|
|
|
pub(crate) name: String,
|
2020-02-14 00:12:49 -08:00
|
|
|
#[serde(
|
|
|
|
skip_serializing_if = "Option::is_none",
|
|
|
|
default,
|
|
|
|
with = "unwrap_or_skip"
|
|
|
|
)]
|
2020-02-04 08:51:56 -08:00
|
|
|
pub(crate) source: Option<String>,
|
2020-02-15 18:08:36 -08:00
|
|
|
pub(crate) pieces: PieceList,
|
2019-05-24 01:25:55 -07:00
|
|
|
#[serde(flatten)]
|
2020-02-04 08:51:56 -08:00
|
|
|
pub(crate) mode: Mode,
|
2020-04-27 17:03:58 -07:00
|
|
|
#[serde(
|
|
|
|
skip_serializing_if = "Option::is_none",
|
|
|
|
default,
|
|
|
|
with = "unwrap_or_skip",
|
|
|
|
rename = "update-url"
|
|
|
|
)]
|
|
|
|
pub(crate) update_url: Option<String>,
|
2019-05-24 01:25:55 -07:00
|
|
|
}
|
2020-03-12 22:05:49 -07:00
|
|
|
|
|
|
|
impl Info {
|
|
|
|
pub(crate) fn content_size(&self) -> Bytes {
|
|
|
|
self.mode.content_size()
|
|
|
|
}
|
2020-03-17 03:02:02 -07:00
|
|
|
|
|
|
|
pub(crate) fn infohash(&self) -> Result<Infohash> {
|
|
|
|
let encoded = bendy::serde::ser::to_bytes(self).context(error::InfoSerialize)?;
|
|
|
|
Ok(Infohash::from_bencoded_info_dict(&encoded))
|
|
|
|
}
|
2020-03-12 22:05:49 -07:00
|
|
|
}
|