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

Method write_raw_section

atomic-core/src/change/format_v3/writer/helpers.rs:133–164  ·  view source on GitHub ↗

Compress raw bytes with zstd, hash, and write as a section. Used for GRAPH and SEMANTIC sections where the caller provides pre-serialized (but uncompressed) postcard bytes.

(
        &mut self,
        section_type: SectionType,
        uncompressed: &[u8],
    )

Source from the content-addressed store, hash-verified

131 /// Used for GRAPH and SEMANTIC sections where the caller provides
132 /// pre-serialized (but uncompressed) postcard bytes.
133 pub(super) fn write_raw_section(
134 &mut self,
135 section_type: SectionType,
136 uncompressed: &[u8],
137 ) -> FormatResult<()> {
138 // Compress with zstd
139 let compressed = zstd::encode_all(uncompressed, self.options.compression_level())
140 .map_err(|e| FormatError::Compress(e.to_string()))?;
141
142 // Write section header
143 let section_header = SectionHeader::new(section_type, compressed.len() as u32);
144 let header_bytes = section_header.to_bytes();
145 self.writer.write_all(&header_bytes)?;
146
147 // Write compressed payload
148 self.writer.write_all(&compressed)?;
149
150 // Feed through hasher
151 if section_type.is_hashed() {
152 self.hasher.update(&header_bytes);
153 self.hasher.update(&compressed);
154 }
155
156 // Update stats
157 self.stats.sections_written += 1;
158 self.stats.total_uncompressed += uncompressed.len() as u64;
159 self.stats.total_compressed += compressed.len() as u64;
160 self.stats.total_bytes_written += (SectionHeader::SIZE + compressed.len()) as u64;
161
162 self.last_section_ordering = Some(section_type.ordering());
163 Ok(())
164 }
165}

Callers 2

write_graph_sectionMethod · 0.80

Calls 6

updateMethod · 0.80
orderingMethod · 0.80
compression_levelMethod · 0.45
lenMethod · 0.45
to_bytesMethod · 0.45
is_hashedMethod · 0.45

Tested by

no test coverage detected