pub const fn parse_data_records(data: &[u8]) -> DataRecords<'_> ⓘExpand description
Parses DIF/VIF data records after any CI and transport headers were removed.
The returned iterator yields one result per record and does not allocate.
Examples found in repository?
examples/parse_data_records.rs (line 10)
3fn main() -> Result<(), DataRecordError> {
4 // Application-layer records only: no wired/wireless frame or CI/TPL header.
5 let data = [
6 0x03, 0x13, 0x15, 0x31, 0x00, // Volume: 12_565 x 10^-3 m³
7 0x02, 0x5A, 0xD7, 0x04, // Flow temperature: 1_239 x 10^-1 °C
8 ];
9
10 for (index, record) in parse_data_records(&data).enumerate() {
11 let record = record?;
12
13 println!("Record {}", index + 1);
14 println!(" value: {:?}", record.value());
15 if let Some(value_information) = record.value_information() {
16 println!(" labels: {:?}", value_information.labels);
17 println!(" scale: 10^{}", value_information.decimal_scale_exponent);
18 println!(" units: {:?}", value_information.units);
19 }
20 println!(" raw bytes: {:02X?}", record.raw_bytes());
21 }
22
23 Ok(())
24}