| 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, |