summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2019-05-27 10:29:21 +0300
committerYuval Adam <_@yuv.al>2019-05-27 10:29:21 +0300
commitf56ab9e66f4226ce9541db31416f2bcb942f5c12 (patch)
tree248c68debcceb9f9b176db0af4b40fb4bf350c1b /src
parent69baab2ed04d280393a29d650e08a42f17228520 (diff)
Move all bchlib files into bchlib/
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs76
1 files changed, 0 insertions, 76 deletions
diff --git a/src/lib.rs b/src/lib.rs
deleted file mode 100644
index 1575efb..0000000
--- a/src/lib.rs
+++ /dev/null
@@ -1,76 +0,0 @@
-extern crate bchlib_sys as ffi;
-
-use std::ptr;
-
-#[derive(Debug)]
-pub struct BCH(ffi::bch_control);
-
-impl BCH {
- pub fn init(m: i32, t: i32) -> Result<BCH, &'static str> {
- BCH::init_with_poly(m, t, 0)
- }
-
- pub fn init_with_poly(m: i32, t: i32, poly: u32) -> Result<BCH, &'static str> {
- unsafe {
- let bch = ffi::init_bch(m, t, poly);
- if bch == ptr::null_mut() {
- Err("Invalid BCH params")
- }
- else {
- Ok(BCH(*bch))
- }
- }
- }
-
- pub fn decode(&mut self, msg: &[u8], ecc: &[u8], errloc: &mut[u32]) -> i32 {
- let err = unsafe {
- ffi::decodebits_bch(&mut self.0, msg.as_ptr(), ecc.as_ptr(), errloc.as_mut_ptr())
- };
- err
- }
-}
-
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn test_decode() {
- let mut bch = BCH::init(5, 2).unwrap();
- let msg: [u8; 21] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
- let ecc: [u8; 10] = [1, 1, 1, 0, 1, 1, 0, 1, 0, 0];
- let mut errloc: [u32; 2] = [0, 0];
- bch.decode(&msg, &ecc, &mut errloc);
- assert_eq!(errloc[0], 0);
- assert_eq!(errloc[1], 0);
- }
-
- #[test]
- fn test_decode_err() {
- let mut bch = BCH::init(5, 2).unwrap();
- let msg: [u8; 21] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
- let ecc: [u8; 10] = [1, 1, 1, 0, 1, 1, 0, 1, 0, 0];
- let mut errloc: [u32; 2] = [0, 0];
- bch.decode(&msg, &ecc, &mut errloc);
- assert_eq!(errloc[0], 9);
- assert_eq!(errloc[1], 0);
- }
-
- #[test]
- fn test_sync_codeword() {
- let mut bch = BCH::init(5, 2).unwrap();
- let msg: [u8; 21] = [0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0];
- let ecc: [u8; 10] = [1, 0, 1, 1, 1, 0, 1, 1, 0, 0];
- let mut errloc: [u32; 2] = [0, 0];
- bch.decode(&msg, &ecc, &mut errloc);
- assert_eq!(errloc[0], 0);
- assert_eq!(errloc[1], 0);
- }
-
- #[test]
- fn test_init_fail() {
- let bch = BCH::init_with_poly(5, 2, 1897);
- assert_eq!(bch.is_err(), true);
- }
-}