sftp_protocol/packet/
handle.rs

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