aboutsummaryrefslogtreecommitdiffstats
path: root/src/multipart.rs
blob: d9facf1a8ee4c47c4c8b74489a0b27ed3e3fad4d (plain)
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
use bytes::Bytes;

#[derive(PartialEq, Debug, Clone)]
pub struct MultiPart {
    payload: Bytes,
}

impl From<Bytes> for MultiPart {
    fn from(value: Bytes) -> Self {
        MultiPart { payload: value }
    }
}

impl core::fmt::Display for MultiPart {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.write_fmt(format_args!("Multipart isn't defined."))
    }
}

// Tests for std operations
#[cfg(test)]
mod tests {
    use crate::{packet::*, packet_content::PacketContent};
    use core::str::FromStr;
    use hex::decode;
    use tinyvec::ArrayVec;

    use super::*;

    #[test]
    fn multipart() {
        let sample = "2A0013E8C59624";

        let lhs_packet = Packet {
            route_type: RouteType::Direct,
            version: PayloadVersion::VersionOne,
            path: ArrayVec::new(),
            transport: [0, 0],
            raw_content: Bytes::copy_from_slice(&decode("13E8C59624").unwrap()),
            content: PacketContent::Multipart(MultiPart {
                payload: Bytes::copy_from_slice(&decode("13E8C59624").unwrap()),
            }),
            incomplete: false,
        };

        let rhs_packet = Packet::from_str(sample).unwrap();
        assert_eq!(lhs_packet, rhs_packet);

        #[cfg(feature = "std")]
        assert_eq!(
            format!("{}", lhs_packet),
            "  Direct | v1 |            |          []          |   |  MULTIPART | Multipart isn't defined."
        );
    }
}