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
use std::fmt;

use serde_bytes;

use proto::request::Notification;
use proto::{Request, Response};
use {ImageId, VPath, MachineId};


#[derive(Serialize, Deserialize, Debug)]
pub struct PublishImage {
    pub id: ImageId,
}

impl Notification for PublishImage {
    fn type_name(&self) -> &'static str {
        "PublishImage"
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReceivedImage {
    pub id: ImageId,
    pub path: VPath,
    pub machine_id: MachineId,
    pub hostname: String,
    pub forwarded: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AbortedImage {
    pub id: ImageId,
    pub path: VPath,
    pub machine_id: MachineId,
    pub hostname: String,
    pub forwarded: bool,
    pub reason: String,
}

impl Notification for ReceivedImage {
    fn type_name(&self) -> &'static str {
        "ReceivedImage"
    }
}

impl Notification for AbortedImage {
    fn type_name(&self) -> &'static str {
        "AbortedImage"
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetIndex {
    pub id: ImageId,
    pub hint: Option<VPath>,
}

#[derive(Serialize, Deserialize)]
pub struct GetIndexResponse {
    #[serde(with="serde_bytes")]
    pub data: Vec<u8>,
}


impl Request for GetIndex {
    type Response = GetIndexResponse;
    fn type_name(&self) -> &'static str {
        return "GetIndex";
    }
}

impl Response for GetIndexResponse {
    fn type_name(&self) -> &'static str {
        return "GetIndex";
    }
    fn static_type_name() -> &'static str {
        return "GetIndex";
    }
}

impl fmt::Debug for GetIndexResponse {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("GetIndexResponse")
        .field("data", &format!("<{} bytes>", self.data.len()))
        .finish()
    }
}