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

Method serialize

atomic-core/src/change/change.rs:396–688  ·  view source on GitHub ↗

Serialize this change to a writer using the V3 format. Writes the complete V3 change file (header, hash table, sections, trailer) to the given writer. The content hash is computed incrementally as sections are written. # Arguments `writer` - Where to write the serialized change # Returns The blake3 content hash of the change (its identity). # Errors Returns an error if serialization, compre

(&self, writer: &mut W)

Source from the content-addressed store, hash-verified

394 ///
395 /// Returns an error if serialization, compression, or I/O fails.
396 pub fn serialize<W: Write>(&self, writer: &mut W) -> Result<Hash, ChangeError> {
397 use format_v3::*;
398
399 self.validate_v2()?;
400
401 // 1. Build the hash dedup table from all referenced hashes
402 // Use a placeholder self-hash (we'll know the real one after finalize)
403 let placeholder_hash = [0u8; 32];
404 let mut hash_table = HashDedupTable::new(placeholder_hash);
405
406 // Collect all unique hashes from dependencies
407 for dep in &self.hashed.dependencies {
408 hash_table.insert(*dep.as_bytes())?;
409 }
410 for known in &self.hashed.extra_known {
411 hash_table.insert(*known.as_bytes())?;
412 }
413 if let Some(supersedes) = self.hashed.supersedes {
414 hash_table.insert(*supersedes.as_bytes())?;
415 }
416 for root in self.hashed.causal_frontier.roots() {
417 hash_table.insert(*root.as_bytes())?;
418 }
419
420 // Collect all unique hashes from hunks
421 self.collect_hunk_hashes(&mut hash_table)?;
422
423 // 2. Compute section counts
424 let has_provenance = !self.hashed.provenance.is_empty();
425 let has_unhashed = self.unhashed.is_some();
426 let has_signature = self.signature.is_some();
427 let has_content = !self.contents.is_empty();
428
429 // Chunk content with FastCDC for delta transfer + parallel compression
430 let content_chunks = if has_content {
431 format_v3::chunk_content(&self.contents, &format_v3::ChunkingOptions::default())
432 } else {
433 Vec::new()
434 };
435
436 // For now, we write all hunks in a single GRAPH section (per-file splitting is future work)
437 let graph_section_count = if self.hashed.hunks.is_empty() {
438 0u32
439 } else {
440 1
441 };
442 let semantic_section_count = if self.hashed.file_ops.is_empty() {
443 0u32
444 } else {
445 1
446 };
447 let contents_chunks_count = content_chunks.len() as u32;
448 let mut graph = if self.hashed.hunks.is_empty() {
449 None
450 } else {
451 let compactor = compact::Compactor::new(&hash_table);
452 let ops = self
453 .hashed

Calls 15

chunk_contentFunction · 0.85
wire_limitFunction · 0.85
encode_change_header_v2Function · 0.85
validate_v2Method · 0.80
rootsMethod · 0.80
collect_hunk_hashesMethod · 0.80
compact_graph_opMethod · 0.80
as_refMethod · 0.80
is_noneMethod · 0.80
contents_chunksMethod · 0.80
graph_section_countMethod · 0.80