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
72
73
74
75
76
77
78
79
80
81
82
use crate::prelude::*;
/// Drop samples.
///
/// # Inputs
///
/// `in`: Stream to drop
///
/// # Outputs
///
/// No outputs
///
/// # Usage
/// ```
/// use futuresdr::blocks::NullSink;
/// use futuresdr::runtime::Flowgraph;
/// use num_complex::Complex;
///
/// let mut fg = Flowgraph::new();
///
/// let sink = fg.add_block(NullSink::<Complex<f32>>::new());
/// ```
#[derive(Block)]
pub struct NullSink<T: CpuSample, I: CpuBufferReader<Item = T> = DefaultCpuReader<T>> {
n_received: usize,
#[input]
input: I,
}
impl<T, I> NullSink<T, I>
where
T: CpuSample,
I: CpuBufferReader<Item = T>,
{
/// Create NullSink block
pub fn new() -> Self {
Self {
n_received: 0,
input: I::default(),
}
}
/// Get number of received samples
pub fn n_received(&self) -> usize {
self.n_received
}
}
impl<T, I> Default for NullSink<T, I>
where
T: CpuSample,
I: CpuBufferReader<Item = T>,
{
fn default() -> Self {
Self::new()
}
}
#[doc(hidden)]
impl<T, I> Kernel for NullSink<T, I>
where
T: CpuSample,
I: CpuBufferReader<Item = T>,
{
async fn work(
&mut self,
io: &mut WorkIo,
_mio: &mut MessageOutputs,
_meta: &mut BlockMeta,
) -> Result<()> {
let n = self.input().slice().len();
if n > 0 {
self.n_received += n;
self.input().consume(n);
}
if self.input().finished() {
io.finished = true;
}
Ok(())
}
}