embassy_socket/channel/
socket_msg.rs

1/// socket msg
2#[derive(Copy, Clone)]
3pub struct SocketMsg<const N: usize> {
4    /// send cache bytes
5    pub(crate) bytes: [u8; N],
6    /// real send bytes len
7    pub(crate) len: usize,
8}
9
10/// support default
11impl<const N: usize> Default for SocketMsg<N> {
12    #[inline]
13    fn default() -> Self {
14        Self::new([0; N], 0)
15    }
16}
17
18/// custom method
19impl<const N: usize> SocketMsg<N> {
20    /// create socket msg
21    #[inline]
22    pub const fn new(bytes: [u8; N], len: usize) -> Self {
23        Self { bytes, len }
24    }
25
26    /// get real bytes data
27    #[inline]
28    pub fn as_bytes(&self) -> &[u8] {
29        &self.bytes[..self.len]
30    }
31}