MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / decode

Method decode

crates/commitlog/src/segment.rs:47–71  ·  view source on GitHub ↗
(mut read: R)

Source from the content-addressed store, hash-verified

45 }
46
47 pub fn decode<R: io::Read>(mut read: R) -> io::Result<Self> {
48 let mut buf = [0; Self::LEN];
49 read.read_exact(&mut buf).map_err(|e| {
50 io::Error::new(
51 e.kind(),
52 format!("failed to read segment header ({} bytes): {}", Self::LEN, e),
53 )
54 })?;
55
56 if !buf.starts_with(&MAGIC) {
57 return Err(io::Error::new(
58 io::ErrorKind::InvalidData,
59 format!(
60 "segment header does not start with magic: expected {:02x?}, got {:02x?}",
61 MAGIC,
62 &buf[..MAGIC.len()]
63 ),
64 ));
65 }
66
67 Ok(Self {
68 log_format_version: buf[MAGIC.len()],
69 checksum_algorithm: buf[MAGIC.len() + 1],
70 })
71 }
72
73 pub fn ensure_compatible(&self, max_log_format_version: u8, checksum_algorithm: u8) -> Result<(), String> {
74 if self.log_format_version > max_log_format_version {

Callers

nothing calls this directly

Calls 5

newFunction · 0.50
ErrFunction · 0.50
OkFunction · 0.50
kindMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected