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

Function deserialize

atomic-remote/src/streaming/types.rs:183–204  ·  view source on GitHub ↗
(deserializer: D)

Source from the content-addressed store, hash-verified

181 }
182
183 pub fn deserialize<'de, D>(deserializer: D) -> Result<[u8; 32], D::Error>
184 where
185 D: Deserializer<'de>,
186 {
187 let s = String::deserialize(deserializer)?;
188 if s.len() != 64 {
189 return Err(serde::de::Error::custom(format!(
190 "expected 64 hex chars, got {}",
191 s.len()
192 )));
193 }
194
195 let mut hash = [0u8; 32];
196 for (i, chunk) in s.as_bytes().chunks(2).enumerate() {
197 let hex_str =
198 std::str::from_utf8(chunk).map_err(|_| serde::de::Error::custom("invalid utf8"))?;
199 hash[i] = u8::from_str_radix(hex_str, 16)
200 .map_err(|_| serde::de::Error::custom(format!("invalid hex: {}", hex_str)))?;
201 }
202
203 Ok(hash)
204 }
205}
206
207// ═══════════════════════════════════════════════════════════════════════

Callers 15

save_downloaded_changeFunction · 0.85
save_downloaded_changeFunction · 0.85
deserializeMethod · 0.85
visit_newtype_structMethod · 0.85
deserializeMethod · 0.85
read_fromMethod · 0.85
test_hash_deterministicFunction · 0.85

Calls 2

lenMethod · 0.45
as_bytesMethod · 0.45