Package-level declarations

Types

Link copied to clipboard
interface BleCodec<T> : BleEncoder<T> , BleDecoder<T>

Bidirectional codec combining BleEncoder and BleDecoder.

Link copied to clipboard
fun interface BleDataDecoder<out T>

Decodes a BleData into a value of type T without copying.

Link copied to clipboard
fun interface BleDataEncoder<in T>

Encodes a value of type T directly into BleData.

Link copied to clipboard
fun interface BleDecoder<out T>

Decodes a ByteArray into a value of type T.

Link copied to clipboard
fun interface BleEncoder<in T>

Encodes a value of type T into a ByteArray for BLE transmission.

Link copied to clipboard
sealed interface DecodedObservation<out T>

Typed equivalent of com.atruedev.kmpble.gatt.Observation.

Functions

Link copied to clipboard

Bridge a BleDecoder to work with BleData input.

Link copied to clipboard

Bridge a BleEncoder to produce BleData via BleData factory.

Link copied to clipboard

Bridge a BleDataDecoder to work with ByteArray input.

Link copied to clipboard

Bridge a BleDataEncoder to produce ByteArray via BleData.toByteArray.

Link copied to clipboard
fun <A, B> BleCodec<A>.bimap(encode: (B) -> A, decode: (A) -> B): BleCodec<B>

Transform both directions of this codec.

Link copied to clipboard
fun <T> bleCodec(encoder: BleEncoder<T>, decoder: BleDecoder<T>): BleCodec<T>

Combine a standalone BleEncoder and BleDecoder into a BleCodec.

Link copied to clipboard
fun <A, B> BleDataEncoder<B>.contramap(transform: (A) -> B): BleDataEncoder<A>

Transform the input of this BleData encoder.

fun <A, B> BleEncoder<B>.contramap(transform: (A) -> B): BleEncoder<A>

Transform the input of this encoder.

Link copied to clipboard
fun <T> Advertisement.decodeManufacturerData(companyId: Int, decoder: BleDataDecoder<T>): T?

Decode manufacturer-specific data. Zero-copy on iOS.

Link copied to clipboard
fun <T> Advertisement.decodeServiceData(serviceUuid: Uuid, decoder: BleDataDecoder<T>): T?

Decode service-specific data. Zero-copy on iOS.

Link copied to clipboard
inline fun <T, R> DecodedObservation<T>.fold(onValue: (T) -> R, onDisconnected: () -> R): R

Eliminate a DecodedObservation by applying the matching function.

Link copied to clipboard
fun <T> L2capChannel.incoming(decoder: BleDecoder<T>): Flow<T>

Decode each incoming L2CAP packet into a typed value.

Link copied to clipboard
suspend fun <T> GattServer.indicate(characteristicUuid: Uuid, device: Identifier, value: T, encoder: BleDataEncoder<T>)

Encode a value directly to BleData and send it as an indication.

suspend fun <T> GattServer.indicate(characteristicUuid: Uuid, device: Identifier, value: T, encoder: BleEncoder<T>)

Encode a value and send it as an indication.

Link copied to clipboard
fun <A, B> BleDataDecoder<A>.map(transform: (A) -> B): BleDataDecoder<B>

Transform the output of this BleData decoder.

fun <A, B> BleDecoder<A>.map(transform: (A) -> B): BleDecoder<B>

Transform the output of this decoder.

Link copied to clipboard
suspend fun <T> GattServer.notify(characteristicUuid: Uuid, device: Identifier?, value: T, encoder: BleDataEncoder<T>)

Encode a value directly to BleData and send it as a notification.

suspend fun <T> GattServer.notify(characteristicUuid: Uuid, device: Identifier?, value: T, encoder: BleEncoder<T>)

Encode a value and send it as a notification.

Link copied to clipboard
fun <T> Peripheral.observe(characteristic: Characteristic, decoder: BleDecoder<T>, backpressure: BackpressureStrategy = BackpressureStrategy.Latest): Flow<DecodedObservation<T>>

Observe decoded observations, including disconnect events.

Link copied to clipboard
fun <T> Peripheral.observeValues(characteristic: Characteristic, decoder: BleDecoder<T>, backpressure: BackpressureStrategy = BackpressureStrategy.Latest): Flow<T>

Observe decoded values with transparent reconnection.

Link copied to clipboard
suspend fun <T> Peripheral.read(characteristic: Characteristic, decoder: BleDecoder<T>): T

Read a characteristic and decode the result.

Link copied to clipboard
suspend fun <T> L2capChannel.write(value: T, encoder: BleEncoder<T>)

Encode a value and write it to the L2CAP channel.

suspend fun <T> Peripheral.write(characteristic: Characteristic, value: T, encoder: BleEncoder<T>, writeType: WriteType = WriteType.WithResponse)

Encode a value and write it to a characteristic.