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

Function strip_envelope

nodedb-array/src/sync/schema_crdt.rs:217–228  ·  view source on GitHub ↗

Strip the one-byte version prefix from an enveloped snapshot buffer. Returns a slice into `bytes` starting after the version byte, or an error if the buffer is empty or the version does not match [`LORO_FORMAT_VERSION`].

(bytes: &[u8])

Source from the content-addressed store, hash-verified

215/// Returns a slice into `bytes` starting after the version byte, or an error
216/// if the buffer is empty or the version does not match [`LORO_FORMAT_VERSION`].
217fn strip_envelope(bytes: &[u8]) -> ArrayResult<&[u8]> {
218 match bytes.first() {
219 None => Err(ArrayError::SegmentCorruption {
220 detail: "loro snapshot envelope is empty".into(),
221 }),
222 Some(&v) if v != LORO_FORMAT_VERSION => Err(ArrayError::LoroSnapshotVersionMismatch {
223 expected: LORO_FORMAT_VERSION,
224 got: v,
225 }),
226 Some(_) => Ok(&bytes[1..]),
227 }
228}
229
230// ─── Tests ───────────────────────────────────────────────────────────────────
231

Callers 2

import_snapshotMethod · 0.85

Calls 1

firstMethod · 0.80

Tested by

no test coverage detected