ipmi_rs_core/connection/
response.rs

1use super::{Message, NetFn};
2
3/// An IPMI response.
4#[derive(Debug, Clone, PartialEq)]
5pub struct Response {
6    seq: i64,
7    message: Message,
8}
9
10impl Response {
11    /// Create a new IPMI request message.
12    ///
13    /// The netfn for `request` should be of the `request` variant, see [`Message::new_response`].
14    pub fn new(message: Message, seq: i64) -> Option<Self> {
15        if !message.data().is_empty() {
16            Some(Self { message, seq })
17        } else {
18            None
19        }
20    }
21    /// Get the netfn for the request.
22    pub fn netfn(&self) -> NetFn {
23        self.message.netfn()
24    }
25
26    /// Get the raw value of the netfn for the request.
27    pub fn netfn_raw(&self) -> u8 {
28        self.message.netfn_raw()
29    }
30
31    /// Get the command value for the request.
32    pub fn cmd(&self) -> u8 {
33        self.message.cmd
34    }
35
36    /// Get the sequence number for the response.
37    pub fn seq(&self) -> i64 {
38        self.seq
39    }
40
41    /// Get the completion code for the response.
42    pub fn cc(&self) -> u8 {
43        self.message.data[0]
44    }
45
46    /// Get a shared reference to the data of the request (does not include netfn or command).
47    pub fn data(&self) -> &[u8] {
48        &self.message.data[1..]
49    }
50}