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

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

    fn from(response: &[u8]) -> Self::OutputText
    where
        Self: Sized,
    {
        <TcpResponseBinary as ResponseTrait>::from(response).text()
    }

    fn text(&self) -> Self::OutputText {
        self.clone()
    }

    fn binary(&self) -> TcpResponseBinary {
        TcpResponseBinary {
            data: self.data.clone().into_bytes(),
        }
    }

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

impl Default for TcpResponseText {
    fn default() -> Self {
        Self {
            data: String::new(),
        }
    }
}