decode_exact_no_alloc/
decode_exact_no_alloc.rs1use meterbus_wired_datalink::{
13 CommunicationType, Frame, LongFrame,
14 decoder::exact::{DecodeError, decode},
15};
16
17fn main() -> Result<(), DecodeError> {
18 let frame = decode(&[0x10, 0x5b, 0x01, 0x5c, 0x16])?;
19
20 if let Frame::Short(short) = &frame {
21 assert_eq!(
22 short.control().communication_type(),
23 CommunicationType::ReqUd2
24 );
25 assert_eq!(short.address().value(), 1);
26 }
27
28 let mut output = [0_u8; LongFrame::MAX_LEN];
29 assert_eq!(
30 frame
31 .encode_into(&mut output)
32 .expect("maximum frame buffer is large enough"),
33 [0x10, 0x5b, 0x01, 0x5c, 0x16]
34 );
35
36 Ok(())
37}