1
use crate::packet::Packet;
2

            
3
/// This trait is used to implement Stream and Iterator feature.
4
/// This is almost like `map()`.
5
///
6
// This is needed cause we don't have GaTs
7
// Once GaTs are stable we could use them to implement better Iterator
8
pub trait PacketCodec {
9
    type Item;
10

            
11
    fn decode(&mut self, packet: Packet<'_>) -> Self::Item;
12
}
13

            
14
// GRCOV_EXCL_START
15
#[cfg(test)]
16
pub mod testmod {
17
    use crate::packet::PacketHeader;
18

            
19
    use super::*;
20

            
21
    pub struct Codec;
22

            
23
    #[derive(Debug, PartialEq, Eq)]
24
    pub struct PacketOwned {
25
        pub header: PacketHeader,
26
        pub data: Box<[u8]>,
27
    }
28

            
29
    impl PacketCodec for Codec {
30
        type Item = PacketOwned;
31

            
32
        fn decode(&mut self, pkt: Packet) -> Self::Item {
33
            PacketOwned {
34
                header: *pkt.header,
35
                data: pkt.data.into(),
36
            }
37
        }
38
    }
39
}
40
// GRCOV_EXCL_STOP