(
view: &View<'_>,
content: &[u8],
mut visit: impl FnMut(&[u8]) -> Result<()>,
)
| 60 | } |
| 61 | |
| 62 | fn 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. |
no test coverage detected