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

Function replay

atomic-core/examples/graph_codec_lab/codec.rs:542–646  ·  view source on GitHub ↗
(mut c: Borrowed<'_>, content: Option<&[u8]>, limit: usize)

Source from the content-addressed store, hash-verified

540 undelta(&mut c.numbers[id], &mut previous[id])
541}
542fn replay(mut c: Borrowed<'_>, content: Option<&[u8]>, limit: usize) -> Result<Vec<u8>> {
543 if let Some(hash) = c.content_hash {
544 let bytes = content.context("authored content resolver required")?;
545 ensure!(bytes.len() <= LIMIT, "authored content limit");
546 ensure!(
547 hash == *blake3::hash(bytes).as_bytes(),
548 "authored content binding mismatch"
549 );
550 }
551 ensure!(
552 c.numbers.len() <= 4096 && c.dictionary.len() <= c.control.len(),
553 "graph column/dictionary limit"
554 );
555 let mut previous = vec![0; c.numbers.len()];
556 let mut reference = 0;
557 let mut out = vec![];
558 let mut dictionary_end = 0;
559 let mut numbers_end = 0;
560 let mut source_cursor = 0usize;
561 while !c.control.is_empty() {
562 let tag = c.control[0];
563 c.control = &c.control[1..];
564 match tag {
565 0..=15 => out.push(tag),
566 16 => {
567 put(&mut out, numeric(&mut c, &mut previous, &mut numbers_end)?);
568 }
569 17 => {
570 let (&byte, rest) = c
571 .bytes
572 .split_first()
573 .context("graph byte stream exhausted")?;
574 c.bytes = rest;
575 out.push(byte);
576 }
577 18 | 19 => {
578 let id = usize::try_from(undelta(&mut c.references, &mut reference)?)?;
579 let bytes = c.dictionary.get(id).context("graph dictionary index")?;
580 ensure!(id <= dictionary_end, "graph dictionary gap");
581 if id == dictionary_end {
582 dictionary_end += 1;
583 }
584 if tag == 18 {
585 put(&mut out, bytes.len() as u64);
586 }
587 ensure!(
588 out.len()
589 .checked_add(bytes.len())
590 .is_some_and(|n| n <= limit),
591 "graph expanded limit"
592 );
593 out.extend(*bytes);
594 }
595 20 => {
596 ensure!(c.content_hash.is_some(), "unbound authored reference");
597 let at = usize::try_from(numeric(&mut c, &mut previous, &mut numbers_end)?)?;
598 let len = usize::try_from(numeric(&mut c, &mut previous, &mut numbers_end)?)?;
599 let end = at.checked_add(len).context("authored range overflow")?;

Callers 2

decode_contextFunction · 0.70
runMethod · 0.50

Calls 9

extendMethod · 0.80
putFunction · 0.70
numericFunction · 0.70
undeltaFunction · 0.70
getMethod · 0.65
contextMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected