| 132 | |
| 133 | impl<'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 |