mod error; mod math; pub mod types; mod util; mod hamming; mod rs; use bitvec::prelude::*; use error::*; pub use hamming::Hamming; pub use math::*; pub use rs::ReedSolomon; use types::*; pub use util::{bitdump_bitslice, hexdump_bitslice, hexdump_slice}; pub trait Code { type Slice: ?Sized; type Vector; fn encode(&self, info: &Self::Slice, dev: &Self::Slice) -> Result>; fn decode(&self, data: &Self::Slice) -> Result>; } pub trait BitUnitCode: Code { fn code_bit_len(&self) -> usize; fn info_bit_len(&self) -> usize; } pub trait ByteUnitCode: Code { fn code_byte_len(&self) -> usize; fn info_byte_len(&self) -> usize; fn set_precoding(&mut self, pre: &[U8VRep]) -> Result<()>; } #[derive(Debug, Clone)] pub struct Decoded { pub base: T, pub deviation: T, } #[derive(Debug, Clone)] pub struct Encoded(pub T); pub trait BitDump { fn bitdump(&self) -> String; } impl BitDump for BitSlice { fn bitdump(&self) -> String { bitdump_bitslice(self) } } impl BitDump for BitVec { fn bitdump(&self) -> String { bitdump_bitslice(self) } } pub trait HexDump { fn hexdump(&self) -> Result; } impl HexDump for BitSlice { fn hexdump(&self) -> Result { hexdump_bitslice(self) } } impl HexDump for BitVec { fn hexdump(&self) -> Result { hexdump_bitslice(self.as_bitslice()) } } impl HexDump for &U8SRep { fn hexdump(&self) -> Result { hexdump_slice(self) } } impl HexDump for U8VRep { fn hexdump(&self) -> Result { hexdump_slice(self.as_slice()) } }