use io::{Read, Write};
use crate::consensus::{encode, Decodable, Encodable, ReadExt};
use crate::internal_macros::impl_consensus_encoding;
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FilterLoad {
pub filter: Vec<u8>,
pub hash_funcs: u32,
pub tweak: u32,
pub flags: BloomFlags,
}
impl_consensus_encoding!(FilterLoad, filter, hash_funcs, tweak, flags);
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum BloomFlags {
None,
All,
PubkeyOnly,
}
impl Encodable for BloomFlags {
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
w.write_all(&[match self {
BloomFlags::None => 0,
BloomFlags::All => 1,
BloomFlags::PubkeyOnly => 2,
}])?;
Ok(1)
}
}
impl Decodable for BloomFlags {
fn consensus_decode<R: Read + ?Sized>(r: &mut R) -> Result<Self, encode::Error> {
Ok(match r.read_u8()? {
0 => BloomFlags::None,
1 => BloomFlags::All,
2 => BloomFlags::PubkeyOnly,
_ => return Err(encode::Error::ParseFailed("unknown bloom flag")),
})
}
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FilterAdd {
pub data: Vec<u8>,
}
impl_consensus_encoding!(FilterAdd, data);