1mod core;
7mod decode;
8
9use crate::header::Header;
10#[cfg(not(feature = "std"))]
11use alloc::vec::Vec;
12
13#[derive(Default)]
15pub struct Record {
16 pub header: Header,
18 pub data: Vec<u8>,
20 pub context: Context,
22}
23
24#[derive(Clone, Default)]
26pub struct Context {
27 pub parent_header: Option<Header>,
29}
30
31impl Record {
32 pub fn payload(&self) -> &[u8] {
33 let begin = self.header.header_size();
34 let end = if self.header.version.cldic {
35 self.data.len() - 4
37 } else {
38 self.data.len()
39 };
40 &self.data[begin..end]
41 }
42
43 pub fn checksum(&self) -> Option<bool> {
44 if !self.header.version.cldic {
45 return None;
46 }
47
48 let checksum = self
49 .data
50 .chunks(4)
51 .map(|dword_slice| u32::from_le_bytes(dword_slice.try_into().unwrap_or([0; 4])))
52 .fold(0, |acc: u32, dword| acc.wrapping_add(dword));
53
54 Some(checksum == 0)
55 }
56}