1
1
# HID report descriptor item parser
2
2
3
- ## Example
3
+ ## Examples
4
4
5
- ### Using items directly
6
-
7
- ``` rs
8
- const QEMU_USB_TABLET : & [u8 ] = & [
9
- 0x05 , 0x01 , 0x09 , 0x02 , 0xa1 , 0x01 , 0x09 , 0x01 , 0xa1 , 0x00 , 0x05 , 0x09 , 0x19 , 0x01 , 0x29 ,
10
- 0x03 , 0x15 , 0x00 , 0x25 , 0x01 , 0x95 , 0x03 , 0x75 , 0x01 , 0x81 , 0x02 , 0x95 , 0x01 , 0x75 , 0x05 ,
11
- 0x81 , 0x01 , 0x05 , 0x01 , 0x09 , 0x30 , 0x09 , 0x31 , 0x15 , 0x00 , 0x26 , 0xff , 0x7f , 0x35 , 0x00 ,
12
- 0x46 , 0xff , 0x7f , 0x75 , 0x10 , 0x95 , 0x02 , 0x81 , 0x02 , 0x05 , 0x01 , 0x09 , 0x38 , 0x15 , 0x81 ,
13
- 0x25 , 0x7f , 0x35 , 0x00 , 0x45 , 0x00 , 0x75 , 0x08 , 0x95 , 0x01 , 0x81 , 0x06 , 0xc0 , 0xc0 ,
14
- ];
15
-
16
- dbg! (usb_hid_item :: parse (QEMU_USB_TABLET ). collect :: <Vec <_ >>());
17
- ```
18
-
19
- ### Using the tree parser
5
+ ### Using the default stateful parser
20
6
21
7
``` rs
22
8
const QEMU_USB_TABLET : & [u8 ] = & [
@@ -39,21 +25,33 @@ let mut usages = Usages::new();
39
25
40
26
fn f (val : Value , fields : & mut Vec <(Usages , Field )>, usages : & mut Usages ) {
41
27
match val {
42
- Value :: Collection (c ) => {
43
- usages . clear ();
44
- c . for_each (| c | f (val . unwrap (), fields , usages ));
45
- }
28
+ Value :: Collection (_ ) | Value :: EndCollection => usages . clear (),
46
29
Value :: Usage { page , ids } => usages . push ((page , ids )),
47
30
Value :: Field (f ) => fields . push ((mem :: take (usages ), f )),
31
+ Value :: StackFrame (s ) => s . for_each (| s | f (val . unwrap (), fields , usages )),
48
32
}
49
33
}
50
- usb_hid_item :: tree :: parse (data )
34
+ usb_hid_item :: parse (data )
51
35
. iter ()
52
- . for_each (| c | f (c . unwrap (), & mut fields , & mut usages ));
36
+ . for_each (| e | f (e . unwrap (), & mut fields , & mut usages ));
53
37
54
38
dbg! (fields );
55
39
```
56
40
41
+ ### Using items directly
42
+
43
+ ``` rs
44
+ const QEMU_USB_TABLET : & [u8 ] = & [
45
+ 0x05 , 0x01 , 0x09 , 0x02 , 0xa1 , 0x01 , 0x09 , 0x01 , 0xa1 , 0x00 , 0x05 , 0x09 , 0x19 , 0x01 , 0x29 ,
46
+ 0x03 , 0x15 , 0x00 , 0x25 , 0x01 , 0x95 , 0x03 , 0x75 , 0x01 , 0x81 , 0x02 , 0x95 , 0x01 , 0x75 , 0x05 ,
47
+ 0x81 , 0x01 , 0x05 , 0x01 , 0x09 , 0x30 , 0x09 , 0x31 , 0x15 , 0x00 , 0x26 , 0xff , 0x7f , 0x35 , 0x00 ,
48
+ 0x46 , 0xff , 0x7f , 0x75 , 0x10 , 0x95 , 0x02 , 0x81 , 0x02 , 0x05 , 0x01 , 0x09 , 0x38 , 0x15 , 0x81 ,
49
+ 0x25 , 0x7f , 0x35 , 0x00 , 0x45 , 0x00 , 0x75 , 0x08 , 0x95 , 0x01 , 0x81 , 0x06 , 0xc0 , 0xc0 ,
50
+ ];
51
+
52
+ dbg! (usb_hid_item :: item :: parse (QEMU_USB_TABLET ). collect :: <Vec <_ >>());
53
+ ```
54
+
57
55
## References
58
56
59
57
* < https://www.usb.org/sites/default/files/hid1_11.pdf >
0 commit comments