jerasure_sys/
lib.rs

1pub mod gf_complete;
2pub mod jerasure;
3
4#[cfg(test)]
5mod test {
6    use crate::{gf_complete, jerasure};
7
8    #[test]
9    fn test_jerasure() {
10        unsafe {
11            assert_eq!(jerasure::galois_single_multiply(48, 18, 8), 71_i32);
12        }
13    }
14
15    #[test]
16    fn test_gf() {
17        let mut gf_8: std::mem::MaybeUninit<gf_complete::gf_t> = std::mem::MaybeUninit::uninit();
18        unsafe {
19            if gf_complete::gf_init_easy(gf_8.as_mut_ptr(), 8) == 0 {
20                panic!("gf_init_easy failed");
21            }
22            let mut gf_8 = gf_8.assume_init();
23            let gf_8_ptr = &mut gf_8 as *mut gf_complete::gf_t;
24            let mult = &gf_8.multiply.w32.unwrap();
25            let res = mult(gf_8_ptr, 48, 18);
26            assert_eq!(res, 71_u32);
27        }
28    }
29
30    #[test]
31    fn test_transmute() {
32        // is it safe to transmute between mudule types
33        let mut gf_8: std::mem::MaybeUninit<gf_complete::gf_t> = std::mem::MaybeUninit::uninit();
34        unsafe {
35            // jerasure use gf_t from gf_complete
36            if gf_complete::gf_init_easy(gf_8.as_mut_ptr(), 8) == 0 {
37                panic!("gf_init_easy failed");
38            }
39            let gf_8 = gf_8.assume_init();
40            let mut jr_8_from_gf: jerasure::gf = std::mem::transmute(gf_8);
41            let mult = &jr_8_from_gf.multiply.w32.unwrap();
42            let ptr = &mut jr_8_from_gf as *mut jerasure::gf;
43            let res = mult(ptr, 48, 18);
44            assert_eq!(res, 71_u32);
45        }
46    }
47}