writable

abstract fun writable(encrypted: Boolean = false, onWrite: suspend LocalDescriptor.(ConnectedDevice, ByteArray, Int) -> GattResponse.WriteResponse)

Makes this LocalDescriptor writable by a com.splendo.kaluga.bluetooth.ConnectedDevice Cannot be called if writable has been called before

Parameters

encrypted

true if reading from the descriptor should be encrypted. This will result in LocalCharacteristic.Permission.WRITE_ENCRYPTION_REQUIRED. Otherwise will add LocalCharacteristic.Permission.WRITABLE

onWrite

the function to call when reading from the descriptor. This contains the com.splendo.kaluga.bluetooth.ConnectedDevice, the ByteArray to write and the offset of the data to write and should return a GattResponse.WriteResponse


open fun <T> writable(encrypted: Boolean = false, deserializationStrategy: DeserializationStrategy<T>, bluetoothFormat: BluetoothFormat = BluetoothFormat, onFailedToWrite: suspend LocalDescriptor.(ConnectedDevice, Exception) -> GattResponse.WriteResponse = { _, _ -> GattResponse.ApplicationError(0x80) }, onWrite: suspend LocalDescriptor.(ConnectedDevice, T) -> GattResponse.WriteResponse)

Makes this LocalDescriptor writable by a com.splendo.kaluga.bluetooth.ConnectedDevice Cannot be called if writable has been called before

Parameters

encrypted

true if reading from the descriptor should be encrypted. This will result in LocalCharacteristic.Permission.WRITE_ENCRYPTION_REQUIRED. Otherwise will add LocalCharacteristic.Permission.WRITABLE

deserializationStrategy

the DeserializationStrategy to use to decode the ByteArray being written to an instance of T

onFailedToWrite

the function to call when writing to the descriptor fails. This contains the com.splendo.kaluga.bluetooth.ConnectedDevice and the exception that caused deserialization to fail and should return a GattResponse.WriteResponse

onWrite

the function to call when reading from the descriptor. This contains the com.splendo.kaluga.bluetooth.ConnectedDevice, and the T to write and should return a GattResponse.WriteResponse. If the data being written is split over multiple offsets, this will only be called when the data can be fully deserialized

Type Parameters

T

the type of the data being written