Skip to main content

dope_session/
framer.rs

1pub trait Framer {
2    type Head<'buf>;
3
4    fn parse<'buf>(&mut self, buf: &'buf [u8]) -> Option<(Self::Head<'buf>, usize)>;
5
6    fn body_len(head: &Self::Head<'_>) -> u32;
7}
8
9pub struct PassthroughFramer;
10
11impl Framer for PassthroughFramer {
12    type Head<'buf> = ();
13
14    fn parse(&mut self, buf: &[u8]) -> Option<((), usize)> {
15        if buf.is_empty() {
16            None
17        } else {
18            Some(((), buf.len()))
19        }
20    }
21
22    fn body_len(_: &()) -> u32 {
23        0
24    }
25}