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
use crate::encoding::internal::autogen::{Ping, Pong};
use crate::message as msg;

impl From<msg::Ping> for Ping {
    fn from(p: msg::Ping) -> Self {
        Self {
            request_id: p.request_id.value(),
            ..Default::default()
        }
    }
}

impl From<Ping> for msg::Message {
    fn from(p: Ping) -> Self {
        let res: msg::Ping = p.into();
        res.into()
    }
}

impl From<Ping> for msg::Ping {
    fn from(p: Ping) -> Self {
        Self {
            request_id: p.request_id.into(),
        }
    }
}

impl From<msg::Pong> for Pong {
    fn from(p: msg::Pong) -> Self {
        Self {
            request_id: p.request_id.value(),
            ..Default::default()
        }
    }
}

impl From<Pong> for msg::Message {
    fn from(p: Pong) -> Self {
        let res: msg::Pong = p.into();
        res.into()
    }
}

impl From<Pong> for msg::Pong {
    fn from(p: Pong) -> Self {
        Self {
            request_id: p.request_id.into(),
        }
    }
}

#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn test_proto_from_to_ping() {
        let proto = Ping {
            request_id: 100,
            ..Default::default()
        };
        let msg = msg::Ping {
            request_id: 100.into(),
        };
        assert_eq!(msg, msg::Ping::from(proto.clone()));
        assert_eq!(Ping::from(msg), proto);
    }

    #[test]
    fn test_proto_from_to_pong() {
        let proto = Pong {
            request_id: 100,
            ..Default::default()
        };
        let msg = msg::Pong {
            request_id: 100.into(),
        };

        assert_eq!(msg::Pong::from(proto.clone()), msg);
        assert_eq!(proto, Pong::from(msg));
    }
}