All Downloads are FREE. Search and download functionalities are using the official Maven repository.

iosMain.dev.bluefalcon.BluetoothCharacteristic.kt Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy