sftp_protocol/packet/
rename.rs1use camino::Utf8PathBuf;
2
3use super::kind::PacketType;
4use super::PayloadTrait;
5
6#[derive(Debug, Eq, PartialEq, Nom, Serialize)]
7#[nom(BigEndian)]
8#[cfg_attr(test, derive(test_strategy::Arbitrary))]
9pub struct Rename {
10 pub id: u32,
11 #[nom(Parse(crate::util::parse_path))]
12 #[serde(serialize_with = "crate::util::path_with_u32_length")]
13 pub oldpath: Utf8PathBuf,
14 #[nom(Parse(crate::util::parse_path))]
15 #[serde(serialize_with = "crate::util::path_with_u32_length")]
16 pub newpath: Utf8PathBuf
17}
18
19impl PayloadTrait for Rename {
20 const Type: PacketType = PacketType::Rename;
21 fn binsize(&self) -> u32 {
22 4 + (4 + self.oldpath.as_str().len() as u32) + (4 + self.newpath.as_str().len() as u32)
23 }
24}
25
26impl From<Rename> for super::Payload {
27 fn from(p: Rename) -> Self {
28 Self::Rename(p)
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use test_strategy::proptest;
35 use crate::parser::encode;
36 use crate::parser::Parser;
37 use super::*;
38
39 #[proptest]
40 fn roundtrip_whole(input: Rename) {
41 let mut stream = Parser::default();
42 let packet = input.into_packet();
43 stream.write(&encode(&packet)).unwrap();
44 assert_eq!(stream.get_packet(), Ok(Some(packet)));
45 assert_eq!(stream.get_packet(), Ok(None));
46 }
47}
48