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

Function join

atomic-core/examples/semantic_codec_lab/lengths.rs:186–233  ·  view source on GitHub ↗
(data: &[u8], view: &View<'_>, content: &[u8], raw_len: usize)

Source from the content-addressed store, hash-verified

184 }
185}
186pub fn join(data: &[u8], view: &View<'_>, content: &[u8], raw_len: usize) -> Result<Vec<u8>> {
187 ensure!(raw_len <= transforms::LIMIT, "predicted control limit");
188 ensure!(
189 view.content_hash == *blake3::hash(content).as_bytes(),
190 "length content mismatch"
191 );
192 let (frame, rest): (Borrowed<'_>, _) = postcard::take_from_bytes(data)?;
193 ensure!(
194 rest.is_empty() && frame.predictor == predictor_id(),
195 "length predictor implementation mismatch or trailing data"
196 );
197 let count = frame.count as usize;
198 ensure!(
199 count <= raw_len
200 && frame.mask.len() == count.div_ceil(8)
201 && frame.fields[control::LENGTH].is_empty(),
202 "invalid length prediction frame"
203 );
204 if !count.is_multiple_of(8) {
205 ensure!(
206 frame.mask.last().is_some_and(|b| b >> (count % 8) == 0),
207 "length mask padding"
208 );
209 }
210 let mut values = Join {
211 frame,
212 view,
213 content,
214 refs: view.references,
215 previous: 0,
216 cursor: 0,
217 n: 0,
218 tag: None,
219 output: vec![],
220 limit: raw_len,
221 };
222 control::walk(&mut values, raw_len, &mut |_, _, _| Ok(()))?;
223 ensure!(
224 values.frame.fields.iter().all(|c| c.is_empty())
225 && values.frame.exceptions.is_empty()
226 && values.refs.is_empty()
227 && values.n == count
228 && values.tag.is_none()
229 && values.output.len() == raw_len,
230 "unconsumed predicted control"
231 );
232 Ok(values.output)
233}
234
235#[cfg(test)]
236mod tests {

Callers 10

AtomicHooksPluginFunction · 0.50
createCompactionHandlerFunction · 0.50
freshDirFunction · 0.50
makeGraphDirFunction · 0.50
writeGraphFunction · 0.50
compaction.test.tsFile · 0.50
decode_frameFunction · 0.50
fixtureFunction · 0.50

Calls 1

walkFunction · 0.70

Tested by 4

freshDirFunction · 0.40
makeGraphDirFunction · 0.40
writeGraphFunction · 0.40
fixtureFunction · 0.40