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

Method checkpoint_to_bytes

nodedb-spatial/src/persist.rs:142–167  ·  view source on GitHub ↗

Serialize the R-tree to bytes for checkpointing. When `kek` is `Some`, the inner rkyv payload is wrapped in an AES-256-GCM encrypted SEGV envelope. When `None`, the raw rkyv bytes (with `RKSPT\0` inner magic) are returned (existing plaintext format).

(
        &self,
        kek: Option<&nodedb_wal::crypto::WalEncryptionKey>,
    )

Source from the content-addressed store, hash-verified

140 /// encrypted SEGV envelope. When `None`, the raw rkyv bytes (with `RKSPT\0`
141 /// inner magic) are returned (existing plaintext format).
142 pub fn checkpoint_to_bytes(
143 &self,
144 kek: Option<&nodedb_wal::crypto::WalEncryptionKey>,
145 ) -> Result<Vec<u8>, RTreeCheckpointError> {
146 let snapshot = RTreeSnapshotRkyv {
147 entries: self.entries().into_iter().cloned().collect(),
148 };
149 let rkyv_bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&snapshot)
150 .map_err(|e| RTreeCheckpointError::RkyvSerialize(e.to_string()))?;
151
152 // Build inner plaintext: magic + version + rkyv payload.
153 let inner_len = RTREE_RKYV_MAGIC.len() + 1 + rkyv_bytes.len();
154 let _guard = self
155 .governor()
156 .and_then(|gov| gov.reserve(nodedb_mem::EngineId::Spatial, inner_len).ok());
157 let mut inner = Vec::with_capacity(inner_len);
158 inner.extend_from_slice(RTREE_RKYV_MAGIC);
159 inner.push(RTREE_FORMAT_VERSION);
160 inner.extend_from_slice(&rkyv_bytes);
161
162 if let Some(key) = kek {
163 return encrypt_payload(key, &inner);
164 }
165
166 Ok(inner)
167 }
168
169 /// Restore an R-tree from checkpoint bytes.
170 ///

Calls 9

encrypt_payloadFunction · 0.85
collectMethod · 0.80
to_stringMethod · 0.80
governorMethod · 0.80
entriesMethod · 0.45
lenMethod · 0.45
okMethod · 0.45
reserveMethod · 0.45
pushMethod · 0.45