1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use serde::{Deserialize, Serialize};

#[derive(Serialize)]
pub struct Request {
    pub jsonrpc: String,
    pub id: String,
    pub method: String,
    pub params: Params,
}

#[derive(Serialize)]
#[serde(untagged)]
pub enum Params {
    V(Vec<String>),
    SV(String, Vec<String>),
    SSV(String, String, Vec<String>),
    SOptions(String, Options),
    SUU(String, usize, usize),
}

#[derive(Serialize)]
pub struct Options {
    #[serde(rename = "max-overall-download-limit")]
    pub max_overall_download_limit: String,
    #[serde(rename = "max-overall-upload-limit")]
    pub max_overall_upload_limit: String,
    pub dir: String,
}

#[derive(Deserialize)]
pub struct Response {
    pub jsonrpc: String,
    pub id: String,
    pub result: JsonResult,
}

#[derive(Deserialize)]
#[serde(untagged)]
pub enum JsonResult {
    S(String),
    Status(Status),
    StatusList(Vec<Status>),
    Statistics(Statistics),
}

#[derive(Deserialize, Debug)]
pub struct Status {
    pub bitfield: String,
    pub bittorrent: Option<Bittorrent>,
    #[serde(rename = "completedLength")]
    pub completed_length: String,
    pub connections: String,
    pub dir: String,
    #[serde(rename = "downloadSpeed")]
    pub download_speed: String,
    pub files: Vec<File>,
    pub gid: String,
    #[serde(rename = "infoHash")]
    pub info_hash: Option<String>,
    #[serde(rename = "numPieces")]
    pub num_pieces: String,
    #[serde(rename = "numSeeders")]
    pub num_seeders: Option<String>,
    #[serde(rename = "pieceLength")]
    pub piece_length: String,
    pub seeder: Option<String>,
    pub status: String,
    #[serde(rename = "totalLength")]
    pub total_length: String,
    #[serde(rename = "uploadLength")]
    pub upload_length: String,
    #[serde(rename = "uploadSpeed")]
    pub upload_speed: String,
}

#[derive(Deserialize, Debug)]
pub struct Bittorrent {
    #[serde(rename = "announceList")]
    pub announce_list: Vec<Vec<String>>,
    pub comment: String,
    #[serde(rename = "creationDate")]
    pub creation_date: u32,
    pub info: Info,
    pub mode: String,
}

#[derive(Deserialize, Debug)]
pub struct Info {
    pub name: String,
}

#[derive(Deserialize, Debug)]
pub struct File {
    #[serde(rename = "completedLength")]
    pub completed_length: String,
    pub index: String,
    pub length: String,
    pub path: String,
    pub selected: String,
    pub uris: Vec<Uri>,
}

#[derive(Deserialize, Debug)]
pub struct Uri {
    pub status: String,
    pub uri: String,
}

#[derive(Deserialize, Debug)]
pub struct Statistics {
    #[serde(rename = "downloadSpeed")]
    pub download_speed: String,
    #[serde(rename = "numActive")]
    pub num_active: String,
    #[serde(rename = "numStopped")]
    pub num_stopped: String,
    #[serde(rename = "numStoppedTotal")]
    pub num_stopped_total: String,
    #[serde(rename = "numWaiting")]
    pub num_waiting: String,
    #[serde(rename = "uploadSpeed")]
    pub upload_speed: String,
}