udp_request/response/response_binary/
impl.rs

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