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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use super::Status;
use crate::error::cip_error_reply;
use rseip_core::{codec::Encode, Error};
#[derive(Debug, Default, PartialEq, Eq)]
pub struct MessageRequest<P, D> {
pub service_code: u8,
pub path: P,
pub data: D,
}
impl<P, D> MessageRequest<P, D>
where
P: Encode,
D: Encode,
{
#[inline]
pub fn new(service_code: u8, path: P, data: D) -> Self {
Self {
service_code,
path,
data,
}
}
}
#[derive(Debug)]
pub struct MessageReply<D> {
pub reply_service: u8,
pub status: Status,
pub remaining_path_size: Option<u8>,
pub data: D,
}
impl<D> MessageReply<D> {
#[inline]
pub fn new(reply_service: u8, status: Status, data: D) -> Self {
Self {
reply_service,
status,
remaining_path_size: None,
data,
}
}
}
impl<D> MessageReplyInterface for MessageReply<D> {
type Value = D;
#[inline]
fn reply_service(&self) -> u8 {
self.reply_service
}
#[inline]
fn status(&self) -> &Status {
&self.status
}
#[inline]
fn value(&self) -> &Self::Value {
&self.data
}
#[inline]
fn into_value(self) -> Self::Value {
self.data
}
}
pub trait MessageReplyInterface {
type Value;
fn reply_service(&self) -> u8;
fn status(&self) -> &Status;
fn value(&self) -> &Self::Value;
fn into_value(self) -> Self::Value;
#[inline]
fn expect_service<E: Error>(&self, expected_service: u8) -> Result<(), E> {
if self.reply_service() != expected_service {
Err(cip_error_reply(self.reply_service(), expected_service))
} else {
Ok(())
}
}
}