• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 4284179721

pending completion
4284179721

push

github

GitHub
fix: select * wildcard (#1080)

27683 of 39180 relevant lines covered (70.66%)

52493.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/dozer-types/src/node.rs
1
use std::{
2
    collections::HashMap,
3
    fmt::{Display, Formatter},
4
    str::from_utf8,
5
};
6

7
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
29,641✔
8
pub struct NodeHandle {
9
    pub ns: Option<u16>,
10
    pub id: String,
11
}
12

13
impl NodeHandle {
14
    pub fn new(ns: Option<u16>, id: String) -> Self {
16,044✔
15
        Self { ns, id }
16,044✔
16
    }
16,044✔
17
}
18

19
impl NodeHandle {
20
    pub fn to_bytes(&self) -> Vec<u8> {
45,502✔
21
        let mut r = Vec::<u8>::with_capacity(5);
45,502✔
22
        match self.ns {
45,502✔
23
            Some(ns) => {
7,091✔
24
                r.push(1_u8);
7,091✔
25
                r.extend(ns.to_le_bytes());
7,091✔
26
            }
7,091✔
27
            None => r.push(0_u8),
38,411✔
28
        }
29
        let id_buf = self.id.as_bytes();
45,502✔
30
        r.extend((id_buf.len() as u16).to_le_bytes());
45,502✔
31
        r.extend(id_buf);
45,502✔
32
        r
45,502✔
33
    }
45,502✔
34

35
    pub fn from_bytes(buffer: &[u8]) -> NodeHandle {
352✔
36
        match buffer[0] {
352✔
37
            1_u8 => {
38
                let ns = u16::from_le_bytes(buffer[1..3].try_into().unwrap());
301✔
39
                let id_len: u16 = u16::from_le_bytes(buffer[3..5].try_into().unwrap());
301✔
40
                let id = from_utf8(&buffer[5..5 + id_len as usize]).unwrap();
301✔
41
                NodeHandle::new(Some(ns), id.to_string())
301✔
42
            }
43
            _ => {
44
                let id_len: u16 = u16::from_le_bytes(buffer[1..3].try_into().unwrap());
51✔
45
                let id = from_utf8(&buffer[3..3 + id_len as usize]).unwrap();
51✔
46
                NodeHandle::new(None, id.to_string())
51✔
47
            }
48
        }
49
    }
352✔
50
}
51

52
impl Display for NodeHandle {
53
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
11,780✔
54
        let ns_str = match self.ns {
11,780✔
55
            Some(ns) => ns.to_string(),
8,670✔
56
            None => "r".to_string(),
3,110✔
57
        };
58
        f.write_str(&format!("{}_{}", ns_str, self.id))
11,780✔
59
    }
11,780✔
60
}
61

62
#[derive(Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
5,442✔
63
pub struct OpIdentifier {
64
    pub txid: u64,
65
    pub seq_in_tx: u64,
66
}
67

68
impl OpIdentifier {
69
    pub fn new(txid: u64, seq_in_tx: u64) -> Self {
13,020✔
70
        Self { txid, seq_in_tx }
13,020✔
71
    }
13,020✔
72

73
    pub fn to_bytes(&self) -> [u8; 16] {
45,500✔
74
        let mut result = [0_u8; 16];
45,500✔
75
        result[0..8].copy_from_slice(&self.txid.to_be_bytes());
45,500✔
76
        result[8..16].copy_from_slice(&self.seq_in_tx.to_be_bytes());
45,500✔
77
        result
45,500✔
78
    }
45,500✔
79

×
80
    pub fn from_bytes(bytes: [u8; 16]) -> Self {
340✔
81
        let txid = u64::from_be_bytes(bytes[0..8].try_into().unwrap());
340✔
82
        let seq_in_tx = u64::from_be_bytes(bytes[8..16].try_into().unwrap());
340✔
83
        Self::new(txid, seq_in_tx)
340✔
84
    }
340✔
85
}
×
86

×
87
pub type SourceStates = HashMap<NodeHandle, OpIdentifier>;
×
88

89
#[test]
1✔
90
fn test_handle_to_from_bytes() {
1✔
91
    let original = NodeHandle::new(Some(10), 100.to_string());
1✔
92
    let sz = original.to_bytes();
1✔
93
    let _decoded = NodeHandle::from_bytes(sz.as_slice());
1✔
94

1✔
95
    let original = NodeHandle::new(None, 100.to_string());
1✔
96
    let sz = original.to_bytes();
1✔
97
    let decoded = NodeHandle::from_bytes(sz.as_slice());
1✔
98

1✔
99
    assert_eq!(original, decoded)
1✔
100
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc