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

Function encode

atomic-core/src/change/format_v3/graph_fields/encode.rs:265–306  ·  view source on GitHub ↗

Encode a graph section with frozen v1 field roles. Returns a decompressed section payload; ordinary section framing supplies compression and hashing.

(graph: &GraphSectionPayload)

Source from the content-addressed store, hash-verified

263/// Encode a graph section with frozen v1 field roles. Returns a decompressed
264/// section payload; ordinary section framing supplies compression and hashing.
265pub fn encode(graph: &GraphSectionPayload) -> FormatResult<Vec<u8>> {
266 let mut e = Encoder {
267 control: vec![],
268 columns: BTreeMap::new(),
269 dictionary: vec![],
270 paths: HashMap::new(),
271 aux: vec![],
272 budget: ALLOC,
273 };
274 charge(&mut e.budget, 1, 512)?;
275 charge(&mut e.budget, graph.path.len(), 1)?;
276 charge(&mut e.budget, graph.ops.len(), 512)?;
277 put(&mut e.control, graph.ops.len() as u64);
278 for op in &graph.ops {
279 e.op(op)?;
280 }
281 let columns = e
282 .columns
283 .into_iter()
284 .map(|(role, (_, data, count, constant))| Column {
285 role: role as u16,
286 count,
287 constant,
288 data: if constant.is_some() { vec![] } else { data },
289 })
290 .collect();
291 let payload = Payload {
292 path: &graph.path,
293 start: graph.content_start,
294 end: graph.content_end,
295 control: e.control,
296 columns,
297 dictionary: e.dictionary,
298 aux: e.aux,
299 };
300 let mut out = MAGIC.to_vec();
301 out.extend(postcard::to_allocvec(&payload)?);
302 if out.len() > MAX {
303 return Err(FormatError::GraphFieldLimitExceeded);
304 }
305 Ok(out)
306}

Calls 7

extendMethod · 0.80
chargeFunction · 0.70
putFunction · 0.70
lenMethod · 0.45
opMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45