1use std::io::{Read, Result};
2
3pub fn read_u8<R: Read>(reader: &mut R) -> Result<u8> {
5 let mut buf = [0; 1];
6 reader.read_exact(&mut buf)?;
7
8 Ok(buf[0])
9}
10
11pub fn read_u16<R: Read>(reader: &mut R) -> Result<u16> {
15 let mut buf = [0; 2];
16 reader.read_exact(&mut buf)?;
17
18 let val = u16::from_le_bytes(buf);
19
20 Ok(val)
21}
22
23pub fn read_u32<R: Read>(reader: &mut R) -> Result<u32> {
27 let mut buf = [0; 4];
28 reader.read_exact(&mut buf)?;
29
30 let val = u32::from_le_bytes(buf);
31
32 Ok(val)
33}
34
35pub fn read_u128<R: Read>(reader: &mut R) -> Result<u128> {
39 let mut buf = [0; 16];
40 reader.read_exact(&mut buf)?;
41
42 let val = u128::from_le_bytes(buf);
43
44 Ok(val)
45}
46
47pub fn read_f32<R: Read>(reader: &mut R) -> Result<f32> {
51 let mut buf = [0; 4];
52 reader.read_exact(&mut buf)?;
53
54 let val = f32::from_bits(u32::from_le_bytes(buf));
55
56 Ok(val)
57}
58
59pub fn string_eq_ignore_case(a: &str, b: &str) -> bool {
61 a == b || a.to_lowercase() == b.to_lowercase()
62}