readAs

suspend fun <T> Peripheral.readAs(serviceUuid: Uuid, characteristicUuid: Uuid, decoder: BleDecoder<T>): Result<T>

Reads a characteristic by service+characteristic UUID and decodes the value.

Failure cases:

  • PeripheralNotReadyException: the peripheral is not ready to resolve the characteristic (discovery incomplete, service change pending, or peripheral disconnecting/disconnected). Retry after State.Connected.Ready, reconnecting first if necessary.

  • CharacteristicNotFoundException: the peripheral was ready to resolve and the characteristic is absent from the device's GATT database.

  • DecodeFailureException: read succeeded but decoder threw on the raw bytes.

  • any other exception thrown by the underlying read.

kotlin.coroutines.cancellation.CancellationException is always propagated to the caller, never wrapped into Result.failure.

Use the Peripheral.read overload that takes a com.atruedev.kmpble.gatt.Characteristic directly when you already hold a reference and prefer raw exception propagation.