1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::{
io::Read,
mem,
time::Duration,
};
use crate::Result;
pub type Id = [u8; 64];
pub const DEFAULT_IP: [u8; 4] = [127, 0, 0, 1];
pub const DEFAULT_RW_TIMEOUT: Duration = Duration::from_secs(3);
pub fn cmp_ids(a: &Id, b: &Id) -> bool {
for i in 0..a.len() {
if a[i] != b[i] {
return false;
}
}
true
}
pub fn read_id<T>(stream: &mut Read) -> Result<T> where T: From<Id> {
let mut buf = [0_u8; mem::size_of::<Id>()];
stream.read_exact(&mut buf)?;
Ok(buf.into())
}
#[test]
fn test_id() {
assert_eq!(mem::size_of::<Id>(), 64);
}