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
use crate::{Message, RosMsg, ServicePair};
use std::io;

#[derive(Clone, Debug, Default, PartialEq)]
pub struct RawMessage(pub Vec<u8>);

#[derive(Clone, Debug, PartialEq)]
pub struct RawMessageDescription {
    pub msg_definition: String,
    pub md5sum: String,
    pub msg_type: String,
}

impl RawMessageDescription {
    pub fn from_message<T: Message>() -> Self {
        Self {
            msg_definition: T::msg_definition(),
            md5sum: T::md5sum(),
            msg_type: T::msg_type(),
        }
    }
}

impl Message for RawMessage {
    fn msg_definition() -> String {
        "*".into()
    }

    fn md5sum() -> String {
        "*".into()
    }

    fn msg_type() -> String {
        "*".into()
    }
}

impl RosMsg for RawMessage {
    fn encode<W: io::Write>(&self, mut w: W) -> io::Result<()> {
        w.write_all(&self.0)
    }

    fn decode<R: io::Read>(mut r: R) -> io::Result<Self> {
        let mut data = vec![];
        r.read_to_end(&mut data)?;
        Ok(Self(data))
    }
}

impl ServicePair for RawMessage {
    type Request = RawMessage;
    type Response = RawMessage;
}