MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / extract_cell_bytes

Function extract_cell_bytes

nodedb-array/src/segment/reader.rs:32–102  ·  view source on GitHub ↗

Extract the encoded `CellPayload` bytes for a specific `coord` from a `SparseTile`. Returns `None` when the coord is not present in the tile. Encodes the matched row's attrs + valid-time bounds back into the `CellPayload` wire format so the bytes can be fed directly to [`crate::query::ceiling::ceiling_resolve_cell`]. The returned `Vec ` is always freshly allocated (no lifetime coupling to the

(tile: &SparseTile, coord: &[CoordValue])

Source from the content-addressed store, hash-verified

30/// The returned `Vec<u8>` is always freshly allocated (no lifetime coupling to
31/// the tile).
32pub fn extract_cell_bytes(tile: &SparseTile, coord: &[CoordValue]) -> ArrayResult<Option<Vec<u8>>> {
33 let n = tile.row_count();
34 'rows: for row in 0..n {
35 // Reconstruct the coordinate for this row.
36 for (dim_idx, c) in coord.iter().enumerate() {
37 let dict =
38 tile.dim_dicts
39 .get(dim_idx)
40 .ok_or_else(|| ArrayError::SegmentCorruption {
41 detail: format!("extract_cell_bytes: dim {dim_idx} out of range"),
42 })?;
43 let entry_idx = *dict
44 .indices
45 .get(row)
46 .ok_or_else(|| ArrayError::SegmentCorruption {
47 detail: format!("extract_cell_bytes: row {row} index out of range"),
48 })? as usize;
49 let stored =
50 dict.values
51 .get(entry_idx)
52 .ok_or_else(|| ArrayError::SegmentCorruption {
53 detail: format!("extract_cell_bytes: dict entry {entry_idx} out of range"),
54 })?;
55 if stored != c {
56 continue 'rows;
57 }
58 }
59 // Coord matched — check row kind before decoding payload.
60 let kind = tile.row_kind(row)?;
61 match kind {
62 RowKind::Tombstone => return Ok(Some(CELL_TOMBSTONE_SENTINEL.to_vec())),
63 RowKind::GdprErased => return Ok(Some(CELL_GDPR_ERASURE_SENTINEL.to_vec())),
64 RowKind::Live => {}
65 }
66 // Live row — build attrs from all attr columns.
67 let attrs: Vec<_> = tile
68 .attr_cols
69 .iter()
70 .map(|col| {
71 col.get(row)
72 .cloned()
73 .ok_or_else(|| ArrayError::SegmentCorruption {
74 detail: format!("extract_cell_bytes: attr col row {row} out of range"),
75 })
76 })
77 .collect::<ArrayResult<Vec<_>>>()?;
78 let surrogate = tile.surrogates.get(row).copied().unwrap_or(Surrogate::ZERO);
79 let valid_from_ms =
80 tile.valid_from_ms
81 .get(row)
82 .copied()
83 .ok_or_else(|| ArrayError::SegmentCorruption {
84 detail: format!("extract_cell_bytes: valid_from_ms row {row} out of range"),
85 })?;
86 let valid_until_ms =
87 tile.valid_until_ms
88 .get(row)
89 .copied()

Calls 6

row_kindMethod · 0.80
row_countMethod · 0.45
iterMethod · 0.45
getMethod · 0.45
to_vecMethod · 0.45
encodeMethod · 0.45