Skip to main content

request_data_alloc/
request_data_alloc.rs

1//! Build and encode a standard meter-readout request into a vector.
2//!
3//! This is the allocating counterpart to `request_data_no_alloc`. It requires
4//! the crate's `alloc` feature.
5//!
6//! Run with:
7//!
8//! ```sh
9//! cargo run -p meterbus-wired-datalink --example request_data_alloc --features 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    let encoded = request.encode();
17
18    assert_eq!(encoded, [0x10, 0x5b, 0x01, 0x5c, 0x16]);
19    Ok(())
20}