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

Method decode

atomic-repository/src/repository/conflict_object.rs:290–311  ·  view source on GitHub ↗

Decode canonical bytes, failing closed on unknown versions.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

288
289 /// Decode canonical bytes, failing closed on unknown versions.
290 pub fn decode(bytes: &[u8]) -> Result<Self, ConflictObjectError> {
291 if bytes.len() < 8 {
292 return Err(ConflictObjectError::Truncated);
293 }
294 let mut magic = [0u8; 4];
295 magic.copy_from_slice(&bytes[..4]);
296 if magic != *CONFLICT_SET_MAGIC {
297 return Err(ConflictObjectError::Magic {
298 expected: *CONFLICT_SET_MAGIC,
299 found: magic,
300 });
301 }
302 let version = u32::from_le_bytes(bytes[4..8].try_into().expect("version slice"));
303 if version != CONFLICT_SET_VERSION {
304 return Err(ConflictObjectError::Version {
305 found: version,
306 supported: CONFLICT_SET_VERSION,
307 });
308 }
309 postcard::from_bytes(&bytes[8..])
310 .map_err(|error| ConflictObjectError::Decode(error.to_string()))
311 }
312
313 /// The conflict-set identity: Blake3 over the domain-separated canonical
314 /// bytes. This is the `<conflict-set-hash>` of the `atomic-conflict`

Callers 2

deserializeFunction · 0.45
deserializeFunction · 0.45

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected