use toxcore::binary_io::*;
use toxcore::crypto_core::*;
use nom::rest;
#[derive(Debug, PartialEq, Clone)]
pub struct OobSend {
pub destination_pk: PublicKey,
pub data: Vec<u8>
}
impl FromBytes for OobSend {
named!(from_bytes<OobSend>, do_parse!(
tag!("\x06") >>
destination_pk: call!(PublicKey::from_bytes) >>
data: rest >>
(OobSend { destination_pk, data: data.to_vec() })
));
}
impl ToBytes for OobSend {
fn to_bytes<'a>(&self, buf: (&'a mut [u8], usize)) -> Result<(&'a mut [u8], usize), GenError> {
do_gen!(buf,
gen_be_u8!(0x06) >>
gen_slice!(self.destination_pk.as_ref()) >>
gen_slice!(self.data)
)
}
}
#[cfg(test)]
mod test {
use super::*;
encode_decode_test!(
oob_send_encode_decode,
OobSend {
destination_pk: gen_keypair().0,
data: vec![42; 123]
}
);
}