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

Function decode

atomic-core/src/change/format_v3/graph_fields/raw.rs:319–342  ·  view source on GitHub ↗

Budget the raw graph fallback used by schema 5; legacy schemas keep their established reader. The same conservative budget is checked before writing.

(payload: &[u8])

Source from the content-addressed store, hash-verified

317/// Budget the raw graph fallback used by schema 5; legacy schemas keep their
318/// established reader. The same conservative budget is checked before writing.
319pub fn decode(payload: &[u8]) -> FormatResult<GraphSectionPayload> {
320 if payload.len() > MAX {
321 return Err(FormatError::GraphFieldLimitExceeded);
322 }
323 let budget = Budget {
324 remaining: Cell::new(ALLOC - 512),
325 exceeded: Cell::new(false),
326 };
327 let mut decoder = postcard::Deserializer::from_bytes(payload);
328 let result = GraphSectionPayload::deserialize(Guard {
329 inner: &mut decoder,
330 b: &budget,
331 depth: 0,
332 });
333 let graph = match result {
334 Ok(g) => g,
335 Err(_) if budget.exceeded.get() => return Err(FormatError::GraphFieldLimitExceeded),
336 Err(e) => return Err(e.into()),
337 };
338 if !decoder.finalize()?.is_empty() {
339 return Err(invalid("trailing raw graph bytes"));
340 }
341 Ok(graph)
342}
343
344#[cfg(test)]
345mod tests {

Calls 6

invalidFunction · 0.70
getMethod · 0.65
deserializeFunction · 0.50
lenMethod · 0.45
is_emptyMethod · 0.45
finalizeMethod · 0.45