esp32_nimble/l2cap/
utilities.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use core::fmt::Debug;

use crate::utilities::OsMBuf;
use esp_idf_svc::sys;

pub struct ReceivedData(sys::ble_l2cap_event__bindgen_ty_1__bindgen_ty_4);

impl ReceivedData {
  #[inline]
  pub(crate) fn from_raw(raw: sys::ble_l2cap_event__bindgen_ty_1__bindgen_ty_4) -> Self {
    Self(raw)
  }

  #[inline]
  pub fn conn_handle(&self) -> u16 {
    self.0.conn_handle
  }

  #[inline]
  pub fn data(&self) -> &[u8] {
    OsMBuf(self.0.sdu_rx).as_slice()
  }
}

impl Debug for ReceivedData {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    write!(f, "{:X?}", self.data())
  }
}

impl Drop for ReceivedData {
  fn drop(&mut self) {
    unsafe { super::os_mbuf_free(self.0.sdu_rx) };
  }
}