2019-05-24 10:25:55 +02:00
|
|
|
use crate::common::*;
|
|
|
|
|
2020-02-11 12:08:57 +01:00
|
|
|
#[skip_serializing_none]
|
2019-05-24 10:25:55 +02:00
|
|
|
#[serde(untagged)]
|
2020-02-11 12:08:57 +01:00
|
|
|
#[derive(Deserialize, Serialize, Debug, PartialEq)]
|
2020-02-06 01:01:44 +01:00
|
|
|
pub(crate) enum Mode {
|
2020-02-11 12:08:57 +01:00
|
|
|
Single {
|
|
|
|
length: u64,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none", default, with = "inner")]
|
|
|
|
md5sum: Option<String>,
|
|
|
|
},
|
|
|
|
Multiple {
|
|
|
|
files: Vec<FileInfo>,
|
|
|
|
},
|
2019-05-24 10:25:55 +02:00
|
|
|
}
|
2020-02-04 16:55:50 +01:00
|
|
|
|
|
|
|
impl Mode {
|
|
|
|
pub(crate) fn total_size(&self) -> Bytes {
|
|
|
|
match self {
|
|
|
|
Self::Single { length, .. } => Bytes::from(*length),
|
|
|
|
Self::Multiple { files } => Bytes::from(files.iter().map(|file| file.length).sum::<u64>()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|