tcp_request/response/response_binary/
impl.rs

1use crate::*;
2
3/// ResponseTrait implementation for binary TCP responses.
4impl ResponseTrait for TcpResponseBinary {
5    type OutputText = TcpResponseText;
6    type OutputBinary = TcpResponseBinary;
7
8    /// Creates a binary response from raw bytes.
9    ///
10    /// # Arguments
11    ///
12    /// - `&[u8]` - The raw response data.
13    ///
14    /// # Returns
15    ///
16    /// - `Self` - A new binary response instance.
17    #[inline]
18    fn from(response: &[u8]) -> Self
19    where
20        Self: Sized,
21    {
22        response.to_vec()
23    }
24
25    /// Gets the binary representation of the response.
26    ///
27    /// # Returns
28    ///
29    /// - `Self::OutputBinary` - The binary response data.
30    #[inline]
31    fn binary(&self) -> Self::OutputBinary {
32        self.clone()
33    }
34
35    /// Converts the binary response to text representation.
36    ///
37    /// # Returns
38    ///
39    /// - `TcpResponseText` - The text representation of the response.
40    #[inline]
41    fn text(&self) -> TcpResponseText {
42        let data: String = String::from_utf8_lossy(self).to_string();
43        data
44    }
45}