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

Method decode

atomic-core/src/change/envelope.rs:277–308  ·  view source on GitHub ↗

Decode a `SessionEnvelope` from `HashedChange.metadata` bytes. Validates the magic prefix and schema version before deserializing. # Errors Returns `SessionEnvelopeError` if: - The data is too short - The magic prefix doesn't match - The schema version is unsupported - Postcard deserialization fails

(data: &[u8])

Source from the content-addressed store, hash-verified

275 /// - The schema version is unsupported
276 /// - Postcard deserialization fails
277 pub fn decode(data: &[u8]) -> EnvelopeResult<Self> {
278 if data.len() < MAGIC.len() + 1 {
279 return Err(codec_error(format!(
280 "data too short: {} bytes (minimum {})",
281 data.len(),
282 MAGIC.len() + 1
283 )));
284 }
285
286 // Check magic
287 if &data[..4] != MAGIC {
288 return Err(codec_error(format!(
289 "invalid magic: expected {:?}, got {:?}",
290 MAGIC,
291 &data[..4]
292 )));
293 }
294
295 // Deserialize payload (includes schema_version field)
296 let envelope: Self = postcard::from_bytes(&data[4..])
297 .map_err(|e| codec_error(format!("postcard deserialize failed: {}", e)))?;
298
299 // Check version from the deserialized struct
300 if envelope.schema_version > SCHEMA_VERSION {
301 return Err(codec_error(format!(
302 "unsupported schema version: {} (max supported: {})",
303 envelope.schema_version, SCHEMA_VERSION
304 )));
305 }
306
307 Ok(envelope)
308 }
309
310 /// Check whether a byte slice looks like a `SessionEnvelope`.
311 ///

Callers 9

referenceFunction · 0.45
targetFunction · 0.45
did_atomicFunction · 0.45
runMethod · 0.45
sign_elsewhereFunction · 0.45
verify_with_didMethod · 0.45
strict_base32Function · 0.45
decode_from_transportFunction · 0.45
is_canonical_change_iriFunction · 0.45

Calls 2

codec_errorFunction · 0.70
lenMethod · 0.45

Tested by 2

sign_elsewhereFunction · 0.36
verify_with_didMethod · 0.36