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

use proto::{Request, Response};
use std::fmt;
use {Hash, VPath};

use serde_bytes;

#[derive(Serialize, Deserialize, Debug)]
pub struct GetBlock {
    pub hash: Hash,
    pub hint: Option<(VPath, PathBuf, u64)>,
}

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

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

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

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