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

Method get_contents

atomic-core/src/change/store.rs:464–505  ·  view source on GitHub ↗
(
        &self,
        hash_fn: F,
        node: GraphNode<NodeId>,
        buf: &mut [u8],
    )

Source from the content-addressed store, hash-verified

462 }
463
464 fn get_contents<F>(
465 &self,
466 hash_fn: F,
467 node: GraphNode<NodeId>,
468 buf: &mut [u8],
469 ) -> Result<usize, Self::Error>
470 where
471 F: Fn(NodeId) -> Option<Hash>,
472 {
473 // Handle empty vertices
474 if node.end <= node.start || node.is_root() {
475 return Ok(0);
476 }
477
478 // Get the hash for this change
479 let hash = hash_fn(node.change)
480 .ok_or_else(|| MemoryStoreError::NotFound(format!("NodeId({})", node.change.0)))?;
481
482 // Load the change
483 let changes = self.changes.read().unwrap();
484 let change = changes
485 .get(&hash)
486 .ok_or_else(|| MemoryStoreError::NotFound(hash.to_base32()))?;
487
488 // Extract the content range
489 let start = node.start.0.as_u64() as usize;
490 let end = node.end.0.as_u64() as usize;
491
492 if end > change.contents.len() {
493 return Err(MemoryStoreError::OutOfBounds {
494 start: start as u64,
495 end: end as u64,
496 len: change.contents.len(),
497 });
498 }
499
500 let content = &change.contents[start..end];
501 let len = content.len().min(buf.len());
502 buf[..len].copy_from_slice(&content[..len]);
503
504 Ok(len)
505 }
506
507 fn get_contents_ext(
508 &self,

Callers 12

get_vertex_contentMethod · 0.45
output_trunk_via_crdtFunction · 0.45
output_vertex_contentFunction · 0.45
test_get_contents_basicFunction · 0.45
test_single_byte_contentFunction · 0.45
test_unicode_contentFunction · 0.45
test_binary_contentFunction · 0.45

Calls 7

as_u64Method · 0.80
getMethod · 0.65
is_rootMethod · 0.45
unwrapMethod · 0.45
readMethod · 0.45
to_base32Method · 0.45
lenMethod · 0.45