use crate::{Descriptor, Result, Uuid};
#[derive(Debug, Clone)]
pub struct DescriptorImpl {
inner: bluer::gatt::remote::Descriptor,
}
impl PartialEq for DescriptorImpl {
fn eq(&self, other: &Self) -> bool {
self.inner.adapter_name() == other.inner.adapter_name()
&& self.inner.device_address() == other.inner.device_address()
&& self.inner.service_id() == other.inner.service_id()
&& self.inner.characteristic_id() == other.inner.characteristic_id()
&& self.inner.id() == other.inner.id()
}
}
impl Eq for DescriptorImpl {}
impl Descriptor {
pub(super) fn new(inner: bluer::gatt::remote::Descriptor) -> Descriptor {
Descriptor(DescriptorImpl { inner })
}
}
impl DescriptorImpl {
pub fn uuid(&self) -> Uuid {
match tokio::runtime::Handle::try_current() {
Ok(handle) => tokio::task::block_in_place(move || handle.block_on(self.uuid_async())),
Err(_) => tokio::runtime::Builder::new_current_thread()
.build()
.unwrap()
.block_on(self.uuid_async()),
}
.unwrap()
}
pub async fn uuid_async(&self) -> Result<Uuid> {
self.inner.uuid().await.map_err(Into::into)
}
pub async fn value(&self) -> Result<Vec<u8>> {
self.inner.cached_value().await.map_err(Into::into)
}
pub async fn read(&self) -> Result<Vec<u8>> {
self.inner.read().await.map_err(Into::into)
}
pub async fn write(&self, value: &[u8]) -> Result<()> {
self.inner.write(value).await.map_err(Into::into)
}
}