Skip to main content

esp32_nimble/l2cap/
utilities.rs

1use core::fmt::Debug;
2
3use crate::{l2cap::L2capChannel, utilities::OsMBuf};
4use esp_idf_svc::sys;
5
6pub struct ReceivedData(sys::ble_l2cap_event__bindgen_ty_1__bindgen_ty_4);
7
8impl ReceivedData {
9    #[inline]
10    pub(crate) fn from_raw(raw: sys::ble_l2cap_event__bindgen_ty_1__bindgen_ty_4) -> Self {
11        Self(raw)
12    }
13
14    #[inline]
15    pub fn conn_handle(&self) -> u16 {
16        self.0.conn_handle
17    }
18
19    #[inline]
20    pub fn channel(&self) -> L2capChannel {
21        L2capChannel(self.0.chan)
22    }
23
24    #[inline]
25    pub fn data(&self) -> &[u8] {
26        OsMBuf(self.0.sdu_rx).as_slice()
27    }
28}
29
30impl Debug for ReceivedData {
31    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
32        write!(f, "{:X?}", self.data())
33    }
34}
35
36impl Drop for ReceivedData {
37    fn drop(&mut self) {
38        unsafe { super::os_mbuf_free(self.0.sdu_rx) };
39    }
40}