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

Function decode_optional_hash

atomic-core/src/pristine/traits/working_copy.rs:152–169  ·  view source on GitHub ↗
(tag: u8, bytes: &[u8], field: &str)

Source from the content-addressed store, hash-verified

150}
151
152fn decode_optional_hash(tag: u8, bytes: &[u8], field: &str) -> PristineResult<Option<Hash>> {
153 match tag {
154 0 => {
155 if bytes.iter().any(|byte| *byte != 0) {
156 return Err(working_copy_serialization_error(format!(
157 "absent {field} contains non-zero bytes"
158 )));
159 }
160 Ok(None)
161 }
162 1 => Ok(Some(Hash::from_bytes(bytes.try_into().map_err(|_| {
163 working_copy_serialization_error(format!("invalid {field} bytes"))
164 })?))),
165 other => Err(working_copy_serialization_error(format!(
166 "invalid {field} presence tag {other}"
167 ))),
168 }
169}
170
171fn working_copy_serialization_error(message: impl Into<String>) -> PristineError {
172 PristineError::Serialization {

Callers 1

Calls 2

iterMethod · 0.45

Tested by

no test coverage detected