| 56 | } |
| 57 | |
| 58 | fn decode_v0<R: Read>(mut reader: R) -> io::Result<Option<Self>> { |
| 59 | let mut hdr = [0; Self::LEN - 8]; |
| 60 | if let Err(e) = reader.read_exact(&mut hdr) { |
| 61 | if e.kind() == io::ErrorKind::UnexpectedEof { |
| 62 | return Ok(None); |
| 63 | } |
| 64 | |
| 65 | return Err(e); |
| 66 | } |
| 67 | match &mut hdr.as_slice() { |
| 68 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] => Ok(None), |
| 69 | buf => { |
| 70 | let min_tx_offset = buf.get_u64().map_err(|e| decode_header_error(e, "min_tx_offset"))?; |
| 71 | let n = buf.get_u16().map_err(|e| decode_header_error(e, "n"))?; |
| 72 | let len = buf.get_u32().map_err(|e| decode_header_error(e, "len"))?; |
| 73 | |
| 74 | Ok(Some(Self { |
| 75 | min_tx_offset, |
| 76 | epoch: Commit::DEFAULT_EPOCH, |
| 77 | n, |
| 78 | len, |
| 79 | })) |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | fn decode_v1<R: Read>(mut reader: R) -> io::Result<Option<Self>> { |
| 85 | let mut hdr = [0; Self::LEN]; |