sftp_protocol/packet/
mkdir.rs

1use camino::Utf8PathBuf;
2
3use crate::common::FileAttributes;
4
5use super::kind::PacketType;
6use super::PayloadTrait;
7
8#[derive(Debug, Eq, PartialEq, Nom, Serialize)]
9#[nom(BigEndian)]
10#[cfg_attr(test, derive(test_strategy::Arbitrary))]
11pub struct MkDir {
12	pub id: u32,
13	#[nom(Parse(crate::util::parse_path))]
14	#[serde(serialize_with = "crate::util::path_with_u32_length")]
15	pub path: Utf8PathBuf,
16	pub attrs: FileAttributes
17}
18
19impl PayloadTrait for MkDir {
20	const Type: PacketType = PacketType::MkDir;
21	fn binsize(&self) -> u32 {
22		4 + (4 + self.path.as_str().len() as u32) + self.attrs.binsize()
23	}
24}
25
26impl From<MkDir> for super::Payload {
27	fn from(p: MkDir) -> Self {
28		Self::MkDir(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: MkDir) {
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