revm_primitives/bytecode/eof/
decode_helpers.rs

1use super::EofDecodeError;
2
3/// Consumes a u8 from the input.
4#[inline]
5pub(crate) fn consume_u8(input: &[u8]) -> Result<(&[u8], u8), EofDecodeError> {
6    if input.is_empty() {
7        return Err(EofDecodeError::MissingInput);
8    }
9    Ok((&input[1..], input[0]))
10}
11
12/// Consumes a u16 from the input.
13#[inline]
14pub(crate) fn consume_u16(input: &[u8]) -> Result<(&[u8], u16), EofDecodeError> {
15    if input.len() < 2 {
16        return Err(EofDecodeError::MissingInput);
17    }
18    let (int_bytes, rest) = input.split_at(2);
19    Ok((rest, u16::from_be_bytes([int_bytes[0], int_bytes[1]])))
20}