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
pub fn apply_scale_factor(value: u16, scale_factor: u16) -> u16 {
return value * u16::pow(10, scale_factor as u32);
}
pub(crate) fn to_be_bytes(data: Vec<u16>) -> Vec<u8> {
return data
.iter()
.flat_map(|v| v.to_be_bytes())
.collect::<Vec<u8>>();
}
pub(crate) fn to_u16_vector(data: &[u8]) -> Vec<u16> {
let chunks = data.chunks_exact(2);
let remainder = chunks.remainder();
let mut result: Vec<u16> = chunks
.into_iter()
.map(|a| u16::from_be_bytes([a[0], a[1]]))
.collect();
if remainder.len() > 0 {
result.push(u16::from_be_bytes([remainder[0], 0]));
}
return result;
}