pub const SNAPSHOT_INTERVAL: usize = 50;

pub mod dtob_wire;
pub mod html;
pub mod xanadoc;
pub mod maps;
pub mod serve;
pub mod table;
pub mod remove;
pub mod daemon;
pub mod shared;

#[allow(non_upper_case_globals, non_camel_case_types, non_snake_case, improper_ctypes)]
pub mod dtob_ffi {
    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}

use std::path::Path;

/// Decode a full DTOB document from bytes (`ffi_decode_dif`).
pub fn decode_dtob_bytes(data: &[u8]) -> Option<*mut dtob_ffi::DtobValue> {
    let root = unsafe { dtob_ffi::ffi_decode_dif(data.as_ptr(), data.len()) };
    if root.is_null() {
        None
    } else {
        Some(root)
    }
}

/// Read a file and decode as DTOB (`ffi_decode_dif`).
pub(crate) fn decode_dtob_file(path: &Path) -> Option<*mut dtob_ffi::DtobValue> {
    let data = std::fs::read(path).ok()?;
    decode_dtob_bytes(&data)
}
