1use crate::error::Error;
8use alloc::vec::Vec;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct RStatR {
13 pub readers: Vec<u8>,
15}
16
17impl RStatR {
18 pub fn encode(&self) -> Result<Vec<u8>, Error> {
20 Ok(self.readers.clone())
21 }
22
23 pub fn decode(data: &[u8]) -> Result<Self, Error> {
25 Ok(Self {
26 readers: data.to_vec(),
27 })
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn roundtrip() {
37 let body = RStatR {
38 readers: alloc::vec![0, 1, 2],
39 };
40 let bytes = body.encode().unwrap();
41 assert_eq!(bytes, [0, 1, 2]);
42 assert_eq!(RStatR::decode(&bytes).unwrap(), body);
43 }
44
45 #[test]
46 fn empty_readers_is_valid() {
47 assert_eq!(
48 RStatR::decode(&[]).unwrap(),
49 RStatR {
50 readers: Vec::new()
51 }
52 );
53 }
54}