esp32_nimble/l2cap/
utilities.rs1use core::fmt::Debug;
2
3use crate::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 data(&self) -> &[u8] {
21 OsMBuf(self.0.sdu_rx).as_slice()
22 }
23}
24
25impl Debug for ReceivedData {
26 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
27 write!(f, "{:X?}", self.data())
28 }
29}
30
31impl Drop for ReceivedData {
32 fn drop(&mut self) {
33 unsafe { super::os_mbuf_free(self.0.sdu_rx) };
34 }
35}