bt_rfcomm/frame/mux_commands/
flow_control.rsuse packet_encoding::{Decodable, Encodable};
use crate::frame::FrameParseError;
const FLOW_CONTROL_COMMAND_LENGTH: usize = 0;
#[derive(Clone, Debug, PartialEq)]
pub struct FlowControlParams {}
impl Decodable for FlowControlParams {
type Error = FrameParseError;
fn decode(buf: &[u8]) -> Result<Self, FrameParseError> {
if buf.len() != FLOW_CONTROL_COMMAND_LENGTH {
return Err(FrameParseError::InvalidBufferLength(
FLOW_CONTROL_COMMAND_LENGTH,
buf.len(),
));
}
Ok(Self {})
}
}
impl Encodable for FlowControlParams {
type Error = FrameParseError;
fn encoded_len(&self) -> usize {
FLOW_CONTROL_COMMAND_LENGTH
}
fn encode(&self, buf: &mut [u8]) -> Result<(), FrameParseError> {
if buf.len() < self.encoded_len() {
return Err(FrameParseError::BufferTooSmall);
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use assert_matches::assert_matches;
#[test]
fn test_decode_flow_control_invalid_buf() {
let buf = [0x00, 0x01, 0x02];
assert_matches!(
FlowControlParams::decode(&buf[..]),
Err(FrameParseError::InvalidBufferLength(FLOW_CONTROL_COMMAND_LENGTH, 3))
);
}
#[test]
fn test_decode_flow_control() {
let buf = [];
assert_eq!(FlowControlParams::decode(&buf[..]).unwrap(), FlowControlParams {});
}
#[test]
fn test_encode_flow_control() {
let mut buf = [];
let expected: [u8; 0] = [];
let command = FlowControlParams {};
assert!(command.encode(&mut buf[..]).is_ok());
assert_eq!(buf, expected);
}
}