//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

pub mod accounts_parser;

pub mod instructions_parser;

pub mod proto_helpers;

/// Deserialize a Borsh-encoded account, checking that all significant bytes are read.
pub fn deserialize_checked<T: borsh::BorshDeserialize>(
    data: &[u8],
    discriminator: &[u8],
) -> Result<T, std::io::Error> {
    let mut data_bytes = data;
    let account = T::deserialize(&mut data_bytes)?;

    if !data_bytes.is_empty() && data_bytes.iter().any(|b| *b != 0) {
        #[cfg(feature = "tracing")]
        tracing::warn!(
            name: "non_zeroed_end_bytes",
            name = "non_zeroed_end_bytes",
            length = data_bytes.len(),
            program = crate::ID.to_string(),
            type_name = ?discriminator,
        );
    }

    Ok(account)
}
