esp32_nimble/server/
on_write_args.rs

1use crate::BLEConnDesc;
2
3pub struct OnWriteArgs<'a> {
4    pub(crate) current_data: &'a [u8],
5    pub(crate) recv_data: &'a [u8],
6    pub(crate) desc: &'a BLEConnDesc,
7    pub(crate) reject: bool,
8    pub(crate) error_code: u8,
9    pub(crate) notify: bool,
10}
11
12impl OnWriteArgs<'_> {
13    pub fn current_data(&self) -> &[u8] {
14        self.current_data
15    }
16
17    pub fn recv_data(&self) -> &[u8] {
18        self.recv_data
19    }
20
21    pub fn desc(&self) -> &BLEConnDesc {
22        self.desc
23    }
24
25    /// If the reject is called, no value is written to BLECharacteristic or BLEDescriptor.
26    /// A write error (0xFF) is sent to the sender.
27    pub fn reject(&mut self) {
28        self.reject_with_error_code(0xFF);
29    }
30
31    /// If the reject is called, no value is written to BLECharacteristic or BLEDescriptor.
32    /// The argument error code is sent to the sender.
33    pub fn reject_with_error_code(&mut self, error_code: u8) {
34        self.reject = true;
35        self.error_code = error_code;
36    }
37
38    pub fn notify(&mut self) {
39        self.notify = true;
40    }
41}
42
43pub struct OnWriteDescriptorArgs<'a> {
44    pub(crate) current_data: &'a [u8],
45    pub(crate) recv_data: &'a [u8],
46    pub(crate) desc: &'a BLEConnDesc,
47    pub(crate) reject: bool,
48    pub(crate) error_code: u8,
49}
50
51impl OnWriteDescriptorArgs<'_> {
52    pub fn current_data(&self) -> &[u8] {
53        self.current_data
54    }
55
56    pub fn recv_data(&self) -> &[u8] {
57        self.recv_data
58    }
59
60    pub fn desc(&self) -> &BLEConnDesc {
61        self.desc
62    }
63
64    /// If the reject is called, no value is written to BLECharacteristic or BLEDescriptor.
65    /// A write error (0xFF) is sent to the sender.
66    pub fn reject(&mut self) {
67        self.reject_with_error_code(0xFF);
68    }
69
70    /// If the reject is called, no value is written to BLECharacteristic or BLEDescriptor.
71    /// The argument error code is sent to the sender.
72    pub fn reject_with_error_code(&mut self, error_code: u8) {
73        self.reject = true;
74        self.error_code = error_code;
75    }
76}