MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / decode_legacy

Function decode_legacy

atomic-core/src/pristine/git_closure.rs:146–163  ·  view source on GitHub ↗
(bytes: &[u8])

Source from the content-addressed store, hash-verified

144}
145
146fn decode_legacy(bytes: &[u8]) -> PristineResult<Vec<Hash>> {
147 let count_bytes = bytes
148 .get(..4)
149 .ok_or_else(|| invalid("Git commit closure is truncated"))?;
150 let count = u32::from_le_bytes(count_bytes.try_into().unwrap()) as u64;
151 if bytes.len() as u64 != 4 + count * 32 {
152 return Err(invalid(format!(
153 "Git commit closure claims {count} hashes but holds {} bytes",
154 bytes.len()
155 )));
156 }
157 Ok(bytes[4..]
158 .as_chunks::<32>()
159 .0
160 .iter()
161 .map(|hash| Hash::from_bytes(*hash))
162 .collect())
163}
164
165#[cfg(test)]
166mod tests {

Callers 1

decodeFunction · 0.85

Calls 6

invalidFunction · 0.70
getMethod · 0.65
unwrapMethod · 0.45
lenMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected