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

Method import_v3_bytes

atomic-repository/src/redb_change_store/mod.rs:245–379  ·  view source on GitHub ↗

Import V3 change data from a byte slice. This is the core import method — used by both `import_v3_file` and by the network layer when receiving change data during pull.

(&self, data: &[u8])

Source from the content-addressed store, hash-verified

243 /// This is the core import method — used by both `import_v3_file` and
244 /// by the network layer when receiving change data during pull.
245 pub fn import_v3_bytes(&self, data: &[u8]) -> RedbStoreResult<[u8; 32]> {
246 let mut cursor = Cursor::new(data);
247 let mut reader = ChangeReader::open(&mut cursor)?;
248
249 let _file_header = *reader.file_header();
250 let hash_table = reader.hash_table().clone();
251
252 // Read all sections
253 let mut meta_header: Option<ChangeHeader> = None;
254 let mut meta_deps: Vec<u16> = Vec::new();
255 let mut provenance_payload: Option<Vec<u8>> = None;
256 let mut graph_sections: Vec<(u32, Vec<u8>)> = Vec::new();
257 let mut semantic_sections: Vec<(u32, Vec<u8>)> = Vec::new();
258 let mut content_chunks: Vec<(u32, [u8; 32], Vec<u8>)> = Vec::new();
259 let mut unhashed_payload: Option<Vec<u8>> = None;
260
261 let mut graph_idx = 0u32;
262 let mut semantic_idx = 0u32;
263
264 while let Some(section) = reader.next_section()? {
265 match section.section_type {
266 SectionType::Header => {
267 meta_header = Some(
268 postcard::from_bytes(&section.payload)
269 .map_err(|e| RedbStoreError::Serialization(e.to_string()))?,
270 );
271 }
272 SectionType::Dependencies => {
273 meta_deps = postcard::from_bytes(&section.payload)
274 .map_err(|e| RedbStoreError::Serialization(e.to_string()))?;
275 }
276 SectionType::Provenance => {
277 provenance_payload = Some(section.payload.clone());
278 }
279 SectionType::Graph => {
280 graph_sections.push((graph_idx, section.payload.clone()));
281 graph_idx += 1;
282 }
283 SectionType::Semantic => {
284 semantic_sections.push((semantic_idx, section.payload.clone()));
285 semantic_idx += 1;
286 }
287 SectionType::Content => {
288 if let Some(info) = &section.content_chunk_info {
289 content_chunks.push((
290 info.chunk_index,
291 info.chunk_hash,
292 section.payload.clone(),
293 ));
294 }
295 }
296 SectionType::Unhashed => {
297 unhashed_payload = Some(section.payload.clone());
298 }
299 }
300 }
301
302 // Verify hash

Callers 2

import_v3_fileMethod · 0.80
save_changeMethod · 0.80

Calls 14

encode_change_file_keyFunction · 0.85
file_headerMethod · 0.80
hash_tableMethod · 0.80
next_sectionMethod · 0.80
is_noneMethod · 0.80
commitMethod · 0.80
getMethod · 0.65
cloneMethod · 0.45
pushMethod · 0.45
verifyMethod · 0.45
hashesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected