use super::*;
use tox_binary_io::*;
use crate::relay::connection_id::ConnectionId;
#[derive(Debug, PartialEq, Clone)]
pub struct DisconnectNotification {
pub connection_id: ConnectionId
}
impl FromBytes for DisconnectNotification {
named!(from_bytes<DisconnectNotification>, do_parse!(
tag!("\x03") >>
connection_id: call!(ConnectionId::from_bytes) >>
(DisconnectNotification { connection_id })
));
}
impl ToBytes for DisconnectNotification {
fn to_bytes<'a>(&self, buf: (&'a mut [u8], usize)) -> Result<(&'a mut [u8], usize), GenError> {
do_gen!(buf,
gen_be_u8!(0x03) >>
gen_call!(|buf, connection_id| ConnectionId::to_bytes(connection_id, buf), &self.connection_id)
)
}
}
#[cfg(test)]
mod test {
use super::*;
encode_decode_test!(
tox_crypto::crypto_init().unwrap(),
disconnect_notification_encode_decode,
DisconnectNotification {
connection_id: ConnectionId::from_index(1)
}
);
}