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 fn from(response: &[u8]) -> Self
18 where
19 Self: Sized,
20 {
21 response.to_vec()
22 }
23
24 /// Gets the binary representation of the response.
25 ///
26 /// # Returns
27 ///
28 /// - `Self::OutputBinary` - The binary response data.
29 fn binary(&self) -> Self::OutputBinary {
30 self.clone()
31 }
32
33 /// Converts the binary response to text representation.
34 ///
35 /// # Returns
36 ///
37 /// - `TcpResponseText` - The text representation of the response.
38 fn text(&self) -> TcpResponseText {
39 let data: String = String::from_utf8_lossy(&self).to_string();
40 data
41 }
42}