use crate::decode::__peek_marker;
use crate::{Error, Marker, ReadBuffer, ReadBufferBorrowed};

/// Decode a boolean value.
#[inline(always)]
pub fn read_bool(buf: &mut ReadBuffer) -> Result<bool, Error> {
    __read_bool(&buf.borrow())
}

pub(crate) fn __read_bool(buf: &ReadBufferBorrowed) -> Result<bool, Error> {
    match __peek_marker(buf)? {
        Marker::Bool { value } => {
            // Discard the marker.
            buf.discard(1)?;

            Ok(value)
        }
        _ => Err(Error::Unexpected),
    }
}
