use camino::Utf8PathBuf;
use super::kind::PacketType;
use super::PayloadTrait;
#[derive(Debug, Eq, PartialEq, Nom, Serialize)]
#[nom(BigEndian)]
#[cfg_attr(test, derive(test_strategy::Arbitrary))]
pub struct Rename {
pub id: u32,
#[nom(Parse(crate::util::parse_path))]
#[serde(serialize_with = "crate::util::path_with_u32_length")]
pub oldpath: Utf8PathBuf,
#[nom(Parse(crate::util::parse_path))]
#[serde(serialize_with = "crate::util::path_with_u32_length")]
pub newpath: Utf8PathBuf
}
impl PayloadTrait for Rename {
const Type: PacketType = PacketType::Rename;
fn binsize(&self) -> u32 {
4 + (4 + self.oldpath.as_str().len() as u32) + (4 + self.newpath.as_str().len() as u32)
}
}
impl From<Rename> for super::Payload {
fn from(p: Rename) -> Self {
Self::Rename(p)
}
}
#[cfg(test)]
mod tests {
use test_strategy::proptest;
use crate::parser::encode;
use crate::parser::Parser;
use super::*;
#[proptest]
fn roundtrip_whole(input: Rename) {
let mut stream = Parser::default();
let packet = input.into_packet();
stream.write(&encode(&packet)).unwrap();
assert_eq!(stream.get_packet(), Ok(Some(packet)));
assert_eq!(stream.get_packet(), Ok(None));
}
}