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
use super::lib::*;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgUserData {
#[cfg_attr(feature = "serde", serde(skip_serializing))]
pub sender_id: Option<u16>,
#[cfg_attr(feature = "serde", serde(rename(serialize = "contents")))]
pub contents: Vec<u8>,
}
impl ConcreteMessage for MsgUserData {
const MESSAGE_TYPE: u16 = 2048;
const MESSAGE_NAME: &'static str = "MSG_USER_DATA";
}
impl SbpMessage for MsgUserData {
fn message_name(&self) -> &'static str {
<Self as ConcreteMessage>::MESSAGE_NAME
}
fn message_type(&self) -> u16 {
<Self as ConcreteMessage>::MESSAGE_TYPE
}
fn sender_id(&self) -> Option<u16> {
self.sender_id
}
fn set_sender_id(&mut self, new_id: u16) {
self.sender_id = Some(new_id);
}
fn encoded_len(&self) -> usize {
WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
}
}
impl TryFrom<Sbp> for MsgUserData {
type Error = TryFromSbpError;
fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
match msg {
Sbp::MsgUserData(m) => Ok(m),
_ => Err(TryFromSbpError),
}
}
}
impl WireFormat for MsgUserData {
const MIN_LEN: usize = <Vec<u8> as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.contents)
}
fn write<B: BufMut>(&self, buf: &mut B) {
WireFormat::write(&self.contents, buf);
}
fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
MsgUserData {
sender_id: None,
contents: WireFormat::parse_unchecked(buf),
}
}
}