#![forbid(unsafe_code)]
use crate::IM_REVISION;
use matter_codec::{Tag, TlvWriter};
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn build_timed_request(timeout_ms: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(timeout_ms))
.expect("infallible: vec writer"); w.put_uint(Tag::Context(0xFF), u64::from(IM_REVISION))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)] use super::*;
use matter_codec::{Element, TlvReader, Value};
#[test]
fn timed_request_has_timeout_at_tag_0() {
let bytes = build_timed_request(10000);
let mut r = TlvReader::new(&bytes);
assert!(matches!(
r.next().unwrap(),
Some(Element::ContainerStart { .. })
));
assert!(matches!(
r.next().unwrap(),
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(10000)
})
));
}
}