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

Method open

nodedb-array/src/segment/reader.rs:134–155  ·  view source on GitHub ↗
(bytes: &'a [u8])

Source from the content-addressed store, hash-verified

132
133impl<'a> SegmentReader<'a> {
134 pub fn open(bytes: &'a [u8]) -> ArrayResult<Self> {
135 if bytes.len() < HEADER_SIZE {
136 return Err(ArrayError::SegmentCorruption {
137 detail: format!("segment too small: {} bytes", bytes.len()),
138 });
139 }
140 let header = SegmentHeader::decode(&bytes[..HEADER_SIZE])?;
141 let footer = SegmentFooter::decode(bytes)?;
142 if header.schema_hash != footer.schema_hash {
143 return Err(ArrayError::SegmentCorruption {
144 detail: format!(
145 "header/footer schema_hash mismatch: header={:x} footer={:x}",
146 header.schema_hash, footer.schema_hash
147 ),
148 });
149 }
150 Ok(Self {
151 bytes,
152 header,
153 footer,
154 })
155 }
156
157 pub fn header(&self) -> &SegmentHeader {
158 &self.header

Callers

nothing calls this directly

Calls 2

decodeFunction · 0.50
lenMethod · 0.45

Tested by

no test coverage detected