use pyo3::{prelude::*, sync::PyOnceLock, types::PyDict};
#[expect(unused_imports)] use crate::PyCodecClassMethods;
use crate::{PyCodec, PyCodecClass};
pub struct PyCodecRegistry {
_private: (),
}
impl PyCodecRegistry {
pub fn get_codec<'py>(config: Borrowed<'_, 'py, PyDict>) -> Result<Bound<'py, PyCodec>, PyErr> {
static GET_CODEC: PyOnceLock<Py<PyAny>> = PyOnceLock::new();
let py = config.py();
let get_codec = GET_CODEC.import(py, "numcodecs.registry", "get_codec")?;
get_codec.call1((config,))?.extract()
}
pub fn register_codec(
class: Borrowed<PyCodecClass>,
codec_id: Option<&str>,
) -> Result<(), PyErr> {
static REGISTER_CODEC: PyOnceLock<Py<PyAny>> = PyOnceLock::new();
let py = class.py();
let register_codec = REGISTER_CODEC.import(py, "numcodecs.registry", "register_codec")?;
register_codec.call1((class, codec_id))?;
Ok(())
}
}