cat_dev/fsemul/pcfs/sata_proto/
stat_file.rs1use crate::errors::NetworkParseError;
8use bytes::{Buf, Bytes};
9use valuable::{Fields, NamedField, NamedValues, StructDef, Structable, Valuable, Value, Visit};
10
11#[derive(Clone, Debug, PartialEq, Eq)]
16pub struct SataStatFilePacketBody {
17 file_descriptor: i32,
18}
19
20impl SataStatFilePacketBody {
21 #[must_use]
22 pub const fn file_descriptor(&self) -> i32 {
23 self.file_descriptor
24 }
25}
26
27impl TryFrom<Bytes> for SataStatFilePacketBody {
28 type Error = NetworkParseError;
29
30 fn try_from(mut value: Bytes) -> Result<Self, Self::Error> {
31 if value.len() < 0x4 {
32 return Err(NetworkParseError::FieldNotLongEnough(
33 "SataStatFile",
34 "Body",
35 0x4,
36 value.len(),
37 value,
38 ));
39 }
40 if value.len() > 0x4 {
41 return Err(NetworkParseError::UnexpectedTrailer(
42 "SataStatFile",
43 value.slice(0x4..),
44 ));
45 }
46
47 let fd = value.get_i32();
48
49 Ok(Self {
50 file_descriptor: fd,
51 })
52 }
53}
54
55const SATA_STAT_FILE_PACKET_BODY_FIELDS: &[NamedField<'static>] = &[NamedField::new("fd")];
56
57impl Structable for SataStatFilePacketBody {
58 fn definition(&self) -> StructDef<'_> {
59 StructDef::new_static(
60 "SataStatFilePacketBody",
61 Fields::Named(SATA_STAT_FILE_PACKET_BODY_FIELDS),
62 )
63 }
64}
65
66impl Valuable for SataStatFilePacketBody {
67 fn as_value(&self) -> Value<'_> {
68 Value::Structable(self)
69 }
70
71 fn visit(&self, visitor: &mut dyn Visit) {
72 visitor.visit_named_fields(&NamedValues::new(
73 SATA_STAT_FILE_PACKET_BODY_FIELDS,
74 &[Valuable::as_value(&self.file_descriptor)],
75 ));
76 }
77}