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

Function split

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

Source from the content-addressed store, hash-verified

78}
79
80pub fn split(view: &View<'_>, content: &[u8]) -> Result<Vec<u8>> {
81 ensure!(
82 view.content_hash == *blake3::hash(content).as_bytes(),
83 "length content mismatch"
84 );
85 let mut fields = control::fields(view.control)?;
86 let mut lengths = fields[control::LENGTH].as_slice();
87 let mut tags = fields[control::REFERENCE].as_slice();
88 let mut refs = view.references;
89 let mut previous = 0;
90 let mut cursor = 0usize;
91 let mut n = 0usize;
92 let mut mask: Vec<u8> = vec![];
93 let mut exceptions = vec![];
94 while !lengths.is_empty() {
95 let len = usize::try_from(control::get(&mut lengths)?)?;
96 let tag = control::get(&mut tags)?;
97 ensure!(tag <= 2, "length reference tag");
98 let at = offset(tag, &mut refs, &mut previous, cursor)?;
99 let bytes = pool(view, content, tag);
100 let tail = bytes.get(at..).context("length predictor offset")?;
101 if n.is_multiple_of(8) {
102 mask.push(0);
103 }
104 if len != predict(tail) {
105 mask[n / 8] |= 1 << (n % 8);
106 transforms::put(&mut exceptions, len as u64);
107 }
108 let end = at.checked_add(len).context("length overflow")?;
109 ensure!(end <= bytes.len(), "length outside pool");
110 if tag != 2 {
111 cursor = end;
112 }
113 n += 1;
114 }
115 ensure!(
116 tags.is_empty() && refs.is_empty(),
117 "unconsumed length contexts"
118 );
119 fields[control::LENGTH].clear();
120 Ok(postcard::to_allocvec(&Frame {
121 predictor: predictor_id(),
122 fields,
123 count: n.try_into()?,
124 mask,
125 exceptions,
126 })?)
127}
128
129struct Join<'a> {
130 frame: Borrowed<'a>,

Calls 13

fieldsFunction · 0.85
offsetFunction · 0.85
poolFunction · 0.85
predictor_idFunction · 0.85
getFunction · 0.70
predictFunction · 0.70
putFunction · 0.70
getMethod · 0.65
clearMethod · 0.65
as_sliceMethod · 0.45
is_emptyMethod · 0.45
contextMethod · 0.45