parse

Function parse 

Source
pub fn parse<ByteStream: IntoIterator<Item = u8>>(
    byte_stream: ByteStream,
) -> impl Iterator<Item = ReportItem>
Expand description

Parse a byte stream into a report item iterator.

Items that cannot be recognized will be treated as Reserved. If you want to fail on unknown items, use parse_strict() instead.

ยงExample

use hid_report::parse;

let bytes = [
    0x05, 0x0C, 0x09, 0x01, 0xA1, 0x01, 0x85, 0x02, 0x19,
    0x00, 0x2A, 0x3C, 0x02, 0x15, 0x00, 0x26, 0x3C, 0x02,
    0x95, 0x01, 0x75, 0x10, 0x81, 0x00, 0xC0,
];
let mut items = parse(bytes);
assert_eq!(items.next().unwrap().to_string(), "Usage Page (Consumer)");
assert_eq!(items.next().unwrap().to_string(), "Usage (Consumer Control)");
assert_eq!(items.next().unwrap().to_string(), "Collection (Application)");
assert_eq!(items.next().unwrap().to_string(), "Report ID (2)");
assert_eq!(items.next().unwrap().to_string(), "Usage Minimum (Undefined)");
assert_eq!(items.next().unwrap().to_string(), "Usage Maximum (AC Format)");
assert_eq!(items.next().unwrap().to_string(), "Logical Minimum (0)");
assert_eq!(items.next().unwrap().to_string(), "Logical Maximum (572)");
assert_eq!(items.next().unwrap().to_string(), "Report Count (1)");
assert_eq!(items.next().unwrap().to_string(), "Report Size (16)");
assert_eq!(
    items.next().unwrap().to_string(),
    "Input (Data, Array, Absolute, No Wrap, Linear, Preferred State, No Null Position)"
);
assert_eq!(items.next().unwrap().to_string(), "End Collection");
assert_eq!(items.next(), None);