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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::io::{Read, Result};
pub fn read_u8<R: Read>(reader: &mut R) -> Result<u8> {
let mut buf = [0; 1];
reader.read_exact(&mut buf)?;
Ok(buf[0])
}
pub fn read_u16<R: Read>(reader: &mut R) -> Result<u16> {
let mut buf = [0; 2];
reader.read_exact(&mut buf)?;
let val = u16::from_le_bytes(buf);
Ok(val)
}
pub fn read_u32<R: Read>(reader: &mut R) -> Result<u32> {
let mut buf = [0; 4];
reader.read_exact(&mut buf)?;
let val = u32::from_le_bytes(buf);
Ok(val)
}
pub fn read_u128<R: Read>(reader: &mut R) -> Result<u128> {
let mut buf = [0; 16];
reader.read_exact(&mut buf)?;
let val = u128::from_le_bytes(buf);
Ok(val)
}
pub fn read_f32<R: Read>(reader: &mut R) -> Result<f32> {
let mut buf = [0; 4];
reader.read_exact(&mut buf)?;
let val = f32::from_bits(u32::from_le_bytes(buf));
Ok(val)
}
pub fn string_eq_ignore_case(a: &str, b: &str) -> bool {
a == b || a.to_lowercase() == b.to_lowercase()
}