rosrust/
raw_message.rs
1use crate::{Message, RosMsg, ServicePair};
2use std::io;
3
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct RawMessage(pub Vec<u8>);
6
7#[derive(Clone, Debug, PartialEq)]
8pub struct RawMessageDescription {
9 pub msg_definition: String,
10 pub md5sum: String,
11 pub msg_type: String,
12}
13
14impl RawMessageDescription {
15 pub fn from_message<T: Message>() -> Self {
16 Self {
17 msg_definition: T::msg_definition(),
18 md5sum: T::md5sum(),
19 msg_type: T::msg_type(),
20 }
21 }
22}
23
24impl Message for RawMessage {
25 fn msg_definition() -> String {
26 "*".into()
27 }
28
29 fn md5sum() -> String {
30 "*".into()
31 }
32
33 fn msg_type() -> String {
34 "*".into()
35 }
36}
37
38impl RosMsg for RawMessage {
39 fn encode<W: io::Write>(&self, mut w: W) -> io::Result<()> {
40 w.write_all(&self.0)
41 }
42
43 fn decode<R: io::Read>(mut r: R) -> io::Result<Self> {
44 let mut data = vec![];
45 r.read_to_end(&mut data)?;
46 Ok(Self(data))
47 }
48}
49
50impl ServicePair for RawMessage {
51 type Request = RawMessage;
52 type Response = RawMessage;
53}