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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use crateCRC_TABLE;
/// This function updates the CRC32 checksum with the next 4 bytes from the buffer.
///
/// # Arguments
/// * `c` - a mutable reference to the current CRC32 checksum
/// * `buf4` - a slice containing the next 4 bytes from the input buffer
/// * `buf4pos` - a mutable reference to the index into the `buf4` slice
///
/// # Examples
/// ```
/// use crc32_v2::byfour::dolit4;
///
/// let mut crc = 0u32;
/// let buf = [0u8, 1u8, 2u8, 3u8];
/// let buf4 = unsafe { std::slice::from_raw_parts(buf.as_ptr() as *const u32, 1) };
/// let mut buf4pos = 0;
/// dolit4(&mut crc, buf4, &mut buf4pos);
/// assert_eq!(crc, 0xAAFD590F);
/// ```
/// This function updates the CRC32 checksum with the next 32 bytes from the buffer.
///
/// # Arguments
/// * `c` - a mutable reference to the current CRC32 checksum
/// * `buf4` - a slice containing the next 32 bytes from the input buffer
/// * `buf4pos` - a mutable reference to the index into the `buf4` slice
///
/// # Examples
/// ```
/// use crc32_v2::byfour::dolit32;
///
/// let mut crc = 0u32;
/// let buf = [0u8; 32];
/// let buf4 = unsafe { std::slice::from_raw_parts(buf.as_ptr() as *const u32, 8) };
/// let mut buf4pos = 0;
/// dolit32(&mut crc, buf4, &mut buf4pos);
/// assert_eq!(crc, 0);
/// ```
/// This function converts a slice of u8 into a slice of u32.
///
/// # Arguments
/// * `s8` - a slice of u8 bytes
///
/// # Returns
/// (`&[u32]`): a slice of u32 corresponding to the input slice of u8
///
/// # Safety
/// The function uses unsafe code to reinterpret the memory layout of the u8 slice as u32.
///
/// # Examples
/// ```
/// use crc32_v2::byfour::slice_u8_as_u32;
///
/// let bytes = [0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8];
/// let u32_slice = slice_u8_as_u32(&bytes);
/// assert_eq!(u32_slice, &[50462976u32, 117835012u32]);
/// ```
/// This function calculates the CRC32 checksum of a byte buffer in little-endian format.
///
/// # Arguments
/// * `crc` - the initial CRC32 value (usually 0)
/// * `buf` - a slice containing the input bytes
///
/// # Returns
/// (`u32`): the CRC32 checksum of the input buffer
///
/// # Examples
/// ```
/// use crc32_v2::byfour::crc32_little;
///
/// let crc = crc32_little(0, &[0u8, 1u8, 2u8, 3u8]);
/// assert_eq!(crc, 0x55BC80E2);
/// ```