sftp_protocol/packet/
attrs.rs1use crate::common::FileAttributes;
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 Attrs {
10 pub id: u32,
11 pub attrs: FileAttributes
12}
13
14impl PayloadTrait for Attrs {
15 const Type: PacketType = PacketType::Attrs;
16 fn binsize(&self) -> u32 {
17 4 + self.attrs.binsize()
18 }
19}
20
21impl From<Attrs> for super::Payload {
22 fn from(p: Attrs) -> Self {
23 Self::Attrs(p)
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use test_strategy::proptest;
30 use crate::parser::encode;
31 use crate::parser::Parser;
32 use super::*;
33
34 #[proptest]
35 fn roundtrip_whole(input: Attrs) {
36 let mut stream = Parser::default();
37 let packet = input.into_packet();
38 stream.write(&encode(&packet)).unwrap();
39 assert_eq!(stream.get_packet(), Ok(Some(packet)));
40 assert_eq!(stream.get_packet(), Ok(None));
41 }
42}
43