MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / read_header

Function read_header

nodedb-codec/src/lz4.rs:171–202  ·  view source on GitHub ↗
(data: &[u8])

Source from the content-addressed store, hash-verified

169}
170
171fn read_header(data: &[u8]) -> Result<Lz4Header, CodecError> {
172 if data.len() < 12 {
173 return Err(CodecError::Truncated {
174 expected: 12,
175 actual: data.len(),
176 });
177 }
178
179 let uncompressed_size = u32::from_le_bytes([data[0], data[1], data[2], data[3]]) as usize;
180 let _block_size = u32::from_le_bytes([data[4], data[5], data[6], data[7]]) as usize;
181 let block_count = u32::from_le_bytes([data[8], data[9], data[10], data[11]]) as usize;
182
183 let lengths_end = 12 + block_count * 4;
184 if data.len() < lengths_end {
185 return Err(CodecError::Truncated {
186 expected: lengths_end,
187 actual: data.len(),
188 });
189 }
190
191 let block_lengths: Vec<usize> = data[12..lengths_end]
192 .chunks_exact(4)
193 .map(|c| u32::from_le_bytes([c[0], c[1], c[2], c[3]]) as usize)
194 .collect();
195
196 Ok(Lz4Header {
197 uncompressed_size,
198 block_count,
199 block_lengths,
200 data_offset: lengths_end,
201 })
202}
203
204// ---------------------------------------------------------------------------
205// Streaming encoder / decoder types

Callers 3

decodeFunction · 0.70
decode_blockFunction · 0.70
block_countMethod · 0.70

Calls 2

collectMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected