pub struct Characteristic {
pub uuid: BluetoothUuid,
pub properties: u32,
pub permissions: u32,
pub value: Option<Vec<u8>>,
pub descriptors: Vec<Descriptor>,
}Expand description
A characteristic to publish.
Fields§
§uuid: BluetoothUuidWhich characteristic this is.
properties: u32crate::CharacteristicProperties bits: what a central may do.
permissions: u32Permissions bits: what a central must have done to be allowed to.
value: Option<Vec<u8>>A fixed value, answered by the stack without waking the application.
CoreBluetooth requires a characteristic with one to be read-only, because a cached value can never change; the other platforms do not, and the check is applied where Apple publishes.
descriptors: Vec<Descriptor>Descriptors published alongside it.
Implementations§
Source§impl Characteristic
impl Characteristic
Sourcepub fn new(uuid: impl IntoUuid) -> Result<Self>
pub fn new(uuid: impl IntoUuid) -> Result<Self>
Begin defining a characteristic. It has no properties until you add some.
Sourcepub fn read(self) -> Self
pub fn read(self) -> Self
Allow reads. Answered by Request::Read unless a fixed
Characteristic::value is set.
Sourcepub fn write_without_response(self) -> Self
pub fn write_without_response(self) -> Self
Allow unacknowledged writes.
Sourcepub fn notify(self) -> Self
pub fn notify(self) -> Self
Allow subscription. CoreBluetooth adds the Client Characteristic Configuration descriptor for you.
Sourcepub fn require_encryption(self) -> Self
pub fn require_encryption(self) -> Self
Require an encrypted link for reads and writes.
Sourcepub fn value(self, value: impl Into<Vec<u8>>) -> Self
pub fn value(self, value: impl Into<Vec<u8>>) -> Self
Serve a fixed value from CoreBluetooth’s cache, with no read requests reaching your code.
Forces read-only: Peripheral::publish rejects a characteristic that
combines a fixed value with write, notify or indicate, because
CoreBluetooth raises on that.
Sourcepub fn descriptor(self, descriptor: Descriptor) -> Self
pub fn descriptor(self, descriptor: Descriptor) -> Self
Attach a descriptor. Publish a descriptor alongside this characteristic.