//! Low-level primitives for data decoding.
//!
//! These primitives work directly with [`ReadBuffer`](crate::ReadBuffer) instances.
//! Data decoding using these primitives is typed, i.e. each decode function expects specific marker variants, except for [`read_marker`] and [`peek_marker`].
//! These last two functions may be used for arbitrary data decoding.
//! The rest of the functions try to match the next marker in the buffer to their expected data type.
//! In the case that the marker is not matching their respective data type, the decoding fails with the [`Unexpected`](crate::Error::Unexpected) error variant.
mod array;
mod ascii;
mod bin;
mod boolean;
mod float;
mod map;
mod marker;
mod signed;
mod unsigned;

pub use array::*;
pub use ascii::*;
pub use bin::*;
pub use boolean::*;
pub use float::*;
pub use map::*;
pub use marker::*;
pub use signed::*;
pub use unsigned::*;

macro_rules! read_arg {
    ($buf:ident as $type:ty) => {{
        $buf.read(core::mem::size_of::<$type>(), |buf| {
            // Safety: size_of::<$type> bytes available in buf.
            unsafe { <$type>::from_be_bytes(buf.try_into().unwrap_unchecked()) }
        })
    }};
}

pub(crate) use read_arg;

#[cfg(test)]
mod tests;
