alice_protocol_reader/
scan_cdp.rs

1//! Contains the [ScanCDP] trait for reading CDPs from a file or stdin (readable instance)
2use crate::config::filter::FilterTarget;
3use crate::rdh::RDH;
4
5type CdpTuple<T> = (T, Vec<u8>, u64);
6
7/// Trait for a scanner that reads CDPs from a file or stdin
8pub trait ScanCDP {
9    /// Loads the next [RDH] from the input and returns it
10    fn load_rdh_cru<T: RDH>(&mut self) -> Result<T, std::io::Error>;
11
12    /// Loads the payload in the form of raw bytes from the input and returns it
13    ///
14    /// The size of the payload is given as an argument.
15    fn load_payload_raw(&mut self, payload_size: usize) -> Result<Vec<u8>, std::io::Error>;
16
17    /// Loads the next CDP ([RDH] and payload) from the input and returns it as a ([RDH], [`Vec<u8>`], [u64]) tuple.
18    #[inline]
19    fn load_cdp<T: RDH>(&mut self) -> Result<CdpTuple<T>, std::io::Error> {
20        let rdh: T = self.load_rdh_cru()?;
21        let payload = self.load_payload_raw(rdh.payload_size() as usize)?;
22        let mem_pos = self.current_mem_pos();
23
24        Ok((rdh, payload, mem_pos))
25    }
26
27    /// Loads the next [RDH] that matches the user specified filter target from the input and returns it
28    fn load_next_rdh_to_filter<T: RDH>(
29        &mut self,
30        offset_to_next: u16,
31        target: FilterTarget,
32    ) -> Result<T, std::io::Error>;
33
34    /// Convenience function to return the current memory position in the input stream
35    fn current_mem_pos(&self) -> u64;
36}