toku_protocol/
flags.rs

1pub enum Flags {
2    None = 0,
3    Compressed = 1,
4}
5
6pub fn is_compressed(flags: u8) -> bool {
7    (flags & Flags::Compressed as u8) != 0
8}
9
10/// Creates the u8 flags for a frame. We only have one flag right now, Flags::Compressed.
11pub fn make_flags(compressed: bool) -> u8 {
12    let flag = if compressed {
13        Flags::Compressed
14    } else {
15        Flags::None
16    };
17    flag as u8
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[test]
25    fn it_is_compressed() {
26        assert!(is_compressed(1))
27    }
28
29    #[test]
30    fn it_is_not_compressed() {
31        assert!(!is_compressed(0))
32    }
33
34    #[test]
35    fn it_is_compressed_and_other_flag() {
36        assert!(is_compressed(3))
37    }
38
39    #[test]
40    fn it_makes_flags_compressed() {
41        let flags = make_flags(true);
42        assert!(is_compressed(flags))
43    }
44
45    #[test]
46    fn it_makes_flags_not_compressed() {
47        let flags = make_flags(false);
48        assert!(!is_compressed(flags))
49    }
50}