iosMain.dev.bluefalcon.BluetoothCharacteristic.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blue-falcon Show documentation
Show all versions of blue-falcon Show documentation
Bluetooth Multiplatform Library
package dev.bluefalcon
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.usePinned
import kotlinx.coroutines.flow.MutableStateFlow
import platform.CoreBluetooth.CBCharacteristic
import platform.CoreBluetooth.CBDescriptor
import platform.posix.memcpy
actual class BluetoothCharacteristic(val characteristic: CBCharacteristic) {
actual val name: String?
get() = characteristic.UUID.UUIDString
@OptIn(ExperimentalForeignApi::class)
actual val value: ByteArray?
get() = characteristic.value?.let { data ->
ByteArray(data.length.toInt()).apply {
usePinned {
memcpy(it.addressOf(0), data.bytes, data.length)
}
}
}
actual val descriptors: List
get() = characteristic.descriptors as List
internal actual val _descriptorsFlow = MutableStateFlow>(emptyList())
}
actual typealias BluetoothCharacteristicDescriptor = CBDescriptor