pub struct Message {
pub service: Service,
pub subsystem: u32,
pub command: u32,
pub args: Vec<u8>,
/* private fields */
}Expand description
One protocol message, decoded.
Fields§
§service: Service§subsystem: u32§command: u32§args: Vec<u8>Everything between the command word and the CRC. Ordinary responses include
their leading status word; cmd::CHANGED does not.
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(
service: Service,
subsystem: u32,
command: u32,
args: Vec<u8>,
) -> Self
pub fn new( service: Service, subsystem: u32, command: u32, args: Vec<u8>, ) -> Self
A request, to send to the device.
Sourcepub fn is_response(&self) -> bool
pub fn is_response(&self) -> bool
Whether this message was decoded as a device response.
Direction, not parity. Parity invites the guess and does not support it: the
“select in instrument” command is 0x2f (odd) with response 0x30 (even),
exactly inverting it. The response == request + 1 rule does hold — only the
parity of the request does not. Getting this backwards silently misaligns
Self::payload by four bytes and hides device errors, so it is recorded at
decode time by the side that knows.
Sourcepub fn status(&self) -> Option<u32>
pub fn status(&self) -> Option<u32>
The status word an ordinary response leads with. Some(0) is success.
Sourcepub fn payload(&self) -> &[u8] ⓘ
pub fn payload(&self) -> &[u8] ⓘ
Arguments with an ordinary response’s status stripped. Notifications are unchanged.
pub fn encode(&self) -> Vec<u8> ⓘ
Sourcepub fn decode_response(buf: &[u8]) -> Result<Self>
pub fn decode_response(buf: &[u8]) -> Result<Self>
Decode bytes received from the device.
Sourcepub fn decode_probe(buf: &[u8]) -> Result<Self>
pub fn decode_probe(buf: &[u8]) -> Result<Self>
Decode an exploratory reply without requiring the ordinary status word. A short frame is an observation, not a typed operation failure.
Sourcepub fn decode(buf: &[u8]) -> Result<Self>
pub fn decode(buf: &[u8]) -> Result<Self>
Decode bytes without asserting a direction; treated as a request.
Prefer Self::decode_response for anything read off the wire.