1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use core::marker::PhantomData;
use crate::{
receiver::{iter::BufferIterator, time::InfraMonotonic, DecoderFactory},
Protocol,
};
pub struct BufferInputReceiver<
Proto: DecoderFactory<Mono>,
Mono: InfraMonotonic = u32,
Cmd: From<<Proto as Protocol>::Cmd> = <Proto as Protocol>::Cmd,
> {
resolution: u32,
proto: PhantomData<Proto>,
mono: PhantomData<Mono>,
cmd: PhantomData<Cmd>,
}
impl<Proto, Mono, Cmd> Default for BufferInputReceiver<Proto, Mono, Cmd>
where
Proto: DecoderFactory<Mono>,
Mono: InfraMonotonic,
Cmd: From<<Proto as Protocol>::Cmd>,
{
fn default() -> Self {
Self::new()
}
}
impl<Proto, Mono, Cmd> BufferInputReceiver<Proto, Mono, Cmd>
where
Proto: DecoderFactory<Mono>,
Mono: InfraMonotonic,
Cmd: From<<Proto as Protocol>::Cmd>,
{
pub fn new() -> Self {
BufferInputReceiver {
resolution: 1_000_000,
proto: Default::default(),
mono: Default::default(),
cmd: Default::default(),
}
}
pub fn with_frequenzy(resolution: u32) -> Self {
Self {
resolution,
proto: Default::default(),
mono: Default::default(),
cmd: Default::default(),
}
}
pub fn iter<'a>(&'a mut self, buf: &'a [Mono::Duration]) -> BufferIterator<Proto, Mono, Cmd> {
BufferIterator::new(self.resolution, buf)
}
pub fn iter_with<'a, P, M, C>(
&'a mut self,
resolution: u32,
buf: &'a [M::Duration],
) -> BufferIterator<P, M, C>
where
P: DecoderFactory<M>,
M: InfraMonotonic,
C: From<<P as Protocol>::Cmd>,
{
BufferIterator::new(resolution, buf)
}
}