| 880 | } |
| 881 | |
| 882 | fn read_exact<const N: usize>(&mut self) -> Result<[u8; N], OperationCodecError> { |
| 883 | let end = self |
| 884 | .offset |
| 885 | .checked_add(N) |
| 886 | .ok_or_else(|| OperationCodecError::new("canonical object offset overflow"))?; |
| 887 | let bytes = self.bytes.get(self.offset..end).ok_or_else(|| { |
| 888 | OperationCodecError::new(format!( |
| 889 | "canonical object is truncated at byte {} while reading {N} bytes", |
| 890 | self.offset |
| 891 | )) |
| 892 | })?; |
| 893 | self.offset = end; |
| 894 | bytes |
| 895 | .try_into() |
| 896 | .map_err(|_| OperationCodecError::new("invalid fixed-width canonical field")) |
| 897 | } |
| 898 | |
| 899 | fn read_u8(&mut self) -> Result<u8, OperationCodecError> { |
| 900 | Ok(self.read_exact::<1>()?[0]) |