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

Function token_bytes

atomic-core/examples/semantic_codec_lab/context.rs:62–95  ·  view source on GitHub ↗
(
    view: &View<'_>,
    content: &[u8],
    mut visit: impl FnMut(&[u8]) -> Result<()>,
)

Source from the content-addressed store, hash-verified

60}
61
62fn token_bytes(
63 view: &View<'_>,
64 content: &[u8],
65 mut visit: impl FnMut(&[u8]) -> Result<()>,
66) -> Result<()> {
67 ensure!(
68 view.content_hash == *blake3::hash(content).as_bytes(),
69 "predictor content binding mismatch"
70 );
71 let mut input = view.references;
72 let mut previous = 0;
73 let mut cursor = 0usize;
74 control::visit_bytes(view.control, |has_kind, tag, len| {
75 let at = if tag == 0 {
76 cursor
77 } else {
78 usize::try_from(undelta(&mut input, &mut previous)?)?
79 };
80 let end = at
81 .checked_add(usize::try_from(len)?)
82 .context("token range overflow")?;
83 let pool = if tag == 2 { view.literals } else { content };
84 let bytes = pool.get(at..end).context("predictor byte range")?;
85 if tag != 2 {
86 cursor = end;
87 }
88 if has_kind {
89 visit(bytes)?;
90 }
91 Ok(())
92 })?;
93 ensure!(input.is_empty(), "trailing predictor references");
94 Ok(())
95}
96
97// Frozen experimental predictor: boundaries and IDs are never inferred. Every
98// classification that differs from the author's value is stored explicitly.

Callers 2

predict_kindsFunction · 0.85
restore_kindsFunction · 0.85

Calls 5

visit_bytesFunction · 0.85
undeltaFunction · 0.70
getMethod · 0.65
visitFunction · 0.50
contextMethod · 0.45

Tested by

no test coverage detected