request_data_no_alloc/request_data_no_alloc.rs
1//! Build and encode a standard meter-readout request without allocation.
2//!
3//! The example creates a `REQ-UD2` short frame for slave address 1 and writes
4//! it into a fixed-size caller-owned buffer.
5//!
6//! Run with:
7//!
8//! ```sh
9//! cargo run -p meterbus-wired-datalink --example request_data_no_alloc
10//! ```
11
12use meterbus_wired_datalink::{Address, Control, ShortFrame, ShortFrameError};
13
14fn main() -> Result<(), ShortFrameError> {
15 let request = ShortFrame::new(Control::req_ud2(false), Address::new(1))?;
16
17 let mut output = [0_u8; ShortFrame::LEN];
18 let encoded = request.encode_into(&mut output)?;
19
20 assert_eq!(encoded, [0x10, 0x5b, 0x01, 0x5c, 0x16]);
21 Ok(())
22}