1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use core::cell::RefCell;
use crate::protocol::prelude::*;
use crate::RequestHeader;
pub struct UnknownRequest<'a> {
header: &'a fuse_kernel::fuse_in_header,
body: RefCell<UnknownBody<'a>>,
}
enum UnknownBody<'a> {
Raw(fuse_io::RequestDecoder<'a>),
Parsed(Result<&'a [u8], Error>),
}
impl<'a> UnknownRequest<'a> {
pub fn header(&self) -> &RequestHeader {
RequestHeader::new_ref(&self.header)
}
pub fn body(&self) -> Result<&'a [u8], Error> {
let mut result: Result<&'a [u8], Error> = Ok(&[]);
self.body.replace_with(|body| match body {
UnknownBody::Raw(dec) => {
let body_offset =
size_of::<fuse_kernel::fuse_in_header>() as u32;
result = dec.next_bytes(self.header.len - body_offset);
UnknownBody::Parsed(result)
},
UnknownBody::Parsed(r) => {
result = *r;
UnknownBody::Parsed(*r)
},
});
result
}
}
impl fmt::Debug for UnknownRequest<'_> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("UnknownRequest")
.field("header", &self.header())
.field("body", &format_args!("{:?}", self.body()))
.finish()
}
}
impl<'a> fuse_io::DecodeRequest<'a> for UnknownRequest<'a> {
fn decode_request(dec: fuse_io::RequestDecoder<'a>) -> Result<Self, Error> {
Ok(Self {
header: dec.header(),
body: RefCell::new(UnknownBody::Raw(dec)),
})
}
}