#![allow(internal_features)]
#![feature(core_intrinsics)]

pub mod cdc_file_name;
pub mod codec;
pub mod config;
pub mod index;
pub mod keyspace;
pub mod logger;
pub mod metrics;
pub mod s3_keys;
pub mod security;

use anyhow::{Result, ensure};

// TiCDC use ISO8859_1 encoding for binary columns.
pub fn encode_binary_for_canal_json(bytes: &[u8]) -> String {
    bytes.iter().map(|&b| b as char).collect()
}

pub fn decode_binary_from_canal_json(s: &str) -> Result<Vec<u8>> {
    let mut res = Vec::with_capacity(s.len());
    for c in s.chars() {
        // Make sure the character is in the ISO-8859-1 range
        ensure!(
            c as u32 <= 0xFF,
            "Invalid character U+{:04X} found in binary column",
            c as u32
        );
        res.push(c as u8);
    }
    Ok(res)
}
