tcp_request/response/response_binary/
impl.rs

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
use super::r#type::TcpResponseBinary;
use crate::response::{r#trait::ResponseTrait, response_text::r#type::TcpResponseText};

impl ResponseTrait for TcpResponseBinary {
    type OutputText = TcpResponseText;
    type OutputBinary = TcpResponseBinary;

    fn from(response: &[u8]) -> Self
    where
        Self: Sized,
    {
        TcpResponseBinary {
            data: response.to_vec(),
        }
    }

    fn binary(&self) -> Self::OutputBinary {
        self.clone()
    }

    fn text(&self) -> TcpResponseText {
        let data: String = String::from_utf8_lossy(&self.data).to_string();
        TcpResponseText { data }
    }

    fn decode(&self) -> TcpResponseBinary {
        let data: Vec<u8> = self.data.clone();
        TcpResponseBinary { data }
    }
}

impl Default for TcpResponseBinary {
    fn default() -> Self {
        Self {
            data: Vec::default(),
        }
    }
}