perf_event_data/records/
throttle.rs1use crate::prelude::*;
2
3#[derive(Clone, Debug)]
15#[allow(missing_docs)]
16pub struct Throttle {
17 pub time: u64,
18 pub id: u64,
19 pub stream_id: u64,
20}
21
22impl<'p> Parse<'p> for Throttle {
23 fn parse<B, E>(p: &mut Parser<B, E>) -> ParseResult<Self>
24 where
25 E: Endian,
26 B: ParseBuf<'p>,
27 {
28 Ok(Self {
29 time: p.parse()?,
30 id: p.parse()?,
31 stream_id: p.parse()?,
32 })
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use crate::endian::Little;
39
40 use super::*;
41
42 #[test]
43 #[cfg_attr(not(target_endian = "little"), ignore)]
44 fn test_parse() {
45 #[rustfmt::skip]
46 let bytes: &[u8] = &[
47 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80,
48 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0, 0x00,
49 0xEF, 0xBE, 0xAD, 0xDE, 0xFE, 0xCA, 0xEF, 0xBE,
50 ];
51
52 let mut parser: Parser<_, Little> = Parser::new(bytes, ParseConfig::default());
53 let throttle: Throttle = parser.parse().unwrap();
54
55 assert_eq!(throttle.time, 0x8070605040302010);
56 assert_eq!(throttle.id, 0x00F0E0D0C0B0A090);
57 assert_eq!(throttle.stream_id, 0xBEEFCAFEDEADBEEF);
58 }
59}