Skip to main content

ebcc_sys/
lib.rs

1//! [![CI Status]][workflow] [![MSRV]][repo] [![Latest Version]][crates.io]
2//! [![Rust Doc Crate]][docs.rs] [![Rust Doc Main]][docs]
3//!
4//! [CI Status]: https://img.shields.io/github/actions/workflow/status/juntyr/ebcc-rs/ci.yml?branch=main
5//! [workflow]: https://github.com/juntyr/ebcc-rs/actions/workflows/ci.yml?query=branch%3Amain
6//!
7//! [MSRV]: https://img.shields.io/badge/MSRV-1.82.0-blue
8//! [repo]: https://github.com/juntyr/ebcc-rs
9//!
10//! [Latest Version]: https://img.shields.io/crates/v/ebcc-sys
11//! [crates.io]: https://crates.io/crates/ebcc-sys
12//!
13//! [Rust Doc Crate]: https://img.shields.io/docsrs/ebcc-sys
14//! [docs.rs]: https://docs.rs/ebcc-sys/
15//!
16//! [Rust Doc Main]: https://img.shields.io/badge/docs-main-blue
17//! [docs]: https://juntyr.github.io/ebcc-rs/ebcc_sys
18//!
19//! Low-level bindigs to the [EBCC] compressor.
20//!
21//! [EBCC]: https://github.com/spcl/EBCC
22
23#![allow(missing_docs)] // bindgen
24
25use std::ffi::c_uint;
26
27#[allow(unsafe_code)] // sys-crate
28#[allow(clippy::indexing_slicing)] // bindgen tests
29mod bindings {
30    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
31}
32
33pub use bindings::{
34    codec_config_t, ebcc_decode, ebcc_decode_chunking, ebcc_encode, ebcc_encode_chunking,
35    ebcc_encode_chunking_compat, free_buffer, residual_t,
36};
37
38pub const EBCC_CHUNKING_HEADER_MAGIC: &[u8] = const {
39    let magic: &[u8] = bindings::EBCC_CHUNKING_HEADER_MAGIC;
40
41    let [magic @ .., b'\0'] = magic else {
42        panic!("EBCC_CHUNKING_HEADER_MAGIC is not a null-terminated cstr");
43    };
44
45    magic
46};
47
48#[expect(clippy::manual_assert)]
49pub const EBCC_CHUNKING_HEADER_VERSION: u32 = const {
50    let _: c_uint = bindings::EBCC_CHUNKING_HEADER_VERSION;
51
52    if size_of::<c_uint>() > size_of::<u32>() {
53        panic!("EBCC_CHUNKING_HEADER_VERSION might not fit into u32");
54    }
55
56    #[allow(clippy::unnecessary_cast)]
57    {
58        bindings::EBCC_CHUNKING_HEADER_VERSION as u32
59    }
60};
61
62#[expect(clippy::manual_assert)]
63pub const EBCC_MAX_INTERNAL_IMAGE_DIM: usize = const {
64    let _: c_uint = bindings::EBCC_MAX_INTERNAL_IMAGE_DIM;
65
66    if size_of::<c_uint>() > size_of::<usize>() {
67        panic!("EBCC_MAX_INTERNAL_IMAGE_DIM might not fit into usize");
68    }
69
70    bindings::EBCC_MAX_INTERNAL_IMAGE_DIM as usize
71};
72
73#[expect(clippy::manual_assert)]
74pub const EBCC_MIN_INTERNAL_IMAGE_DIM: usize = const {
75    let _: c_uint = bindings::EBCC_MIN_INTERNAL_IMAGE_DIM;
76
77    if size_of::<c_uint>() > size_of::<usize>() {
78        panic!("EBCC_MIN_INTERNAL_IMAGE_DIM might not fit into usize");
79    }
80
81    bindings::EBCC_MIN_INTERNAL_IMAGE_DIM as usize
82};
83
84#[expect(clippy::manual_assert)]
85pub const EBCC_NDIMS: usize = const {
86    let _: c_uint = bindings::NDIMS;
87
88    if size_of::<c_uint>() > size_of::<usize>() {
89        panic!("NDIMS might not fit into usize");
90    }
91
92    bindings::NDIMS as usize
93};