do-riblt 1.0.2

An implementation of rateless invertable bloom lookup tables
Documentation
use riblt::{Decoder, Encoder, Symbol};

#[derive(Debug, Clone, Copy)]
struct SimpleData(u8, u8);

impl Symbol<2> for SimpleData {
    fn to_bytes(&self) -> [u8; 2] {
        [self.0, self.1]
    }

    fn from_bytes(bytes: &[u8; 2]) -> Self {
        Self(bytes[0], bytes[1])
    }
}

macro_rules! s {
    ($($a:expr, $b:expr),*) => {
        [$(SimpleData($a, $b)),*]
    };
}

fn main() {
    let local = s!(1, 2, 3, 4, 5, 6);
    let remote = s!(1, 2, 6, 7, 3, 4);

    //  Result should be:
    //    MissingRemote(SimpleData(5, 6))
    //    MissingLocal(SimpleData(6, 7))

    let mut remote_encoder = Encoder::new(remote.into_iter());
    let mut local_decoder = Decoder::new(local.into_iter());

    let mut peeled = Vec::new();

    let mut sent_symbols = 0u64;

    loop {
        //  This will always return Some, because the encoder is rateless (infinite)
        let symbol = remote_encoder.next().unwrap();

        //  Here we would send the symbol from remote to local
        sent_symbols += 1;

        //  Decoding the symbol, we get the new peeled values
        let (done, peeled_) = local_decoder.next_symbol(symbol);
        peeled.extend(peeled_);
        //  Check if we are done
        if done {
            break;
        }
    }

    //  Print result and number of sent symbols (aka efficiency, the lower the better)
    dbg!(peeled, sent_symbols);
}