// This file was autogenerated by some hot garbage in the `uniffi` crate.
// Trust me, you don't want to mess with it!
@file:Suppress("NAME_SHADOWING")
package uniffi.peat_btle
// Common helper code.
//
// Ideally this would live in a separate .kt file where it can be unittested etc
// in isolation, and perhaps even published as a re-useable package.
//
// However, it's important that the details of how this helper code works (e.g. the
// way that different builtin types are passed across the FFI) exactly match what's
// expected by the Rust code on the other side of the interface. In practice right
// now that means coming from the exact some version of `uniffi` that was used to
// compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
// helpers directly inline like we're doing here.
import com.sun.jna.Library
import com.sun.jna.IntegerType
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure
import com.sun.jna.Callback
import com.sun.jna.ptr.*
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.nio.CharBuffer
import java.nio.charset.CodingErrorAction
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean
// This is a helper for safely working with byte buffers returned from the Rust code.
// A rust-owned buffer is represented by its capacity, its current length, and a
// pointer to the underlying data.
/**
* @suppress
*/
@Structure.FieldOrder("capacity", "len", "data")
open class RustBuffer : Structure() {
// Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
// When dealing with these fields, make sure to call `toULong()`.
@JvmField var capacity: Long = 0
@JvmField var len: Long = 0
@JvmField var data: Pointer? = null
class ByValue: RustBuffer(), Structure.ByValue
class ByReference: RustBuffer(), Structure.ByReference
internal fun setValue(other: RustBuffer) {
capacity = other.capacity
len = other.len
data = other.data
}
companion object {
internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
// Note: need to convert the size to a `Long` value to make this work with JVM.
UniffiLib.ffi_peat_btle_rustbuffer_alloc(size.toLong(), status)
}.also {
if(it.data == null) {
throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
}
}
internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
var buf = RustBuffer.ByValue()
buf.capacity = capacity.toLong()
buf.len = len.toLong()
buf.data = data
return buf
}
internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
UniffiLib.ffi_peat_btle_rustbuffer_free(buf, status)
}
}
@Suppress("TooGenericExceptionThrown")
fun asByteBuffer() =
this.data?.getByteBuffer(0, this.len)?.also {
it.order(ByteOrder.BIG_ENDIAN)
}
}
// This is a helper for safely passing byte references into the rust code.
// It's not actually used at the moment, because there aren't many things that you
// can take a direct pointer to in the JVM, and if we're going to copy something
// then we might as well copy it into a `RustBuffer`. But it's here for API
// completeness.
@Structure.FieldOrder("len", "data")
internal open class ForeignBytes : Structure() {
@JvmField var len: Int = 0
@JvmField var data: Pointer? = null
class ByValue : ForeignBytes(), Structure.ByValue
}
/**
* The FfiConverter interface handles converter types to and from the FFI
*
* All implementing objects should be public to support external types. When a
* type is external we need to import it's FfiConverter.
*
* @suppress
*/
public interface FfiConverter<KotlinType, FfiType> {
// Convert an FFI type to a Kotlin type
fun lift(value: FfiType): KotlinType
// Convert an Kotlin type to an FFI type
fun lower(value: KotlinType): FfiType
// Read a Kotlin type from a `ByteBuffer`
fun read(buf: ByteBuffer): KotlinType
// Calculate bytes to allocate when creating a `RustBuffer`
//
// This must return at least as many bytes as the write() function will
// write. It can return more bytes than needed, for example when writing
// Strings we can't know the exact bytes needed until we the UTF-8
// encoding, so we pessimistically allocate the largest size possible (3
// bytes per codepoint). Allocating extra bytes is not really a big deal
// because the `RustBuffer` is short-lived.
fun allocationSize(value: KotlinType): ULong
// Write a Kotlin type to a `ByteBuffer`
fun write(value: KotlinType, buf: ByteBuffer)
// Lower a value into a `RustBuffer`
//
// This method lowers a value into a `RustBuffer` rather than the normal
// FfiType. It's used by the callback interface code. Callback interface
// returns are always serialized into a `RustBuffer` regardless of their
// normal FFI type.
fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
val rbuf = RustBuffer.alloc(allocationSize(value))
try {
val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
it.order(ByteOrder.BIG_ENDIAN)
}
write(value, bbuf)
rbuf.writeField("len", bbuf.position().toLong())
return rbuf
} catch (e: Throwable) {
RustBuffer.free(rbuf)
throw e
}
}
// Lift a value from a `RustBuffer`.
//
// This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
// It's currently only used by the `FfiConverterRustBuffer` class below.
fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
val byteBuf = rbuf.asByteBuffer()!!
try {
val item = read(byteBuf)
if (byteBuf.hasRemaining()) {
throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
}
return item
} finally {
RustBuffer.free(rbuf)
}
}
}
/**
* FfiConverter that uses `RustBuffer` as the FfiType
*
* @suppress
*/
public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
}
// A handful of classes and functions to support the generated data structures.
// This would be a good candidate for isolating in its own ffi-support lib.
internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
internal const val UNIFFI_CALL_ERROR = 1.toByte()
internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
@Structure.FieldOrder("code", "error_buf")
internal open class UniffiRustCallStatus : Structure() {
@JvmField var code: Byte = 0
@JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
class ByValue: UniffiRustCallStatus(), Structure.ByValue
fun isSuccess(): Boolean {
return code == UNIFFI_CALL_SUCCESS
}
fun isError(): Boolean {
return code == UNIFFI_CALL_ERROR
}
fun isPanic(): Boolean {
return code == UNIFFI_CALL_UNEXPECTED_ERROR
}
companion object {
fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
val callStatus = UniffiRustCallStatus.ByValue()
callStatus.code = code
callStatus.error_buf = errorBuf
return callStatus
}
}
}
class InternalException(message: String) : kotlin.Exception(message)
/**
* Each top-level error class has a companion object that can lift the error from the call status's rust buffer
*
* @suppress
*/
interface UniffiRustCallStatusErrorHandler<E> {
fun lift(error_buf: RustBuffer.ByValue): E;
}
// Helpers for calling Rust
// In practice we usually need to be synchronized to call this safely, so it doesn't
// synchronize itself
// Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
var status = UniffiRustCallStatus()
val return_value = callback(status)
uniffiCheckCallStatus(errorHandler, status)
return return_value
}
// Check UniffiRustCallStatus and throw an error if the call wasn't successful
private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
if (status.isSuccess()) {
return
} else if (status.isError()) {
throw errorHandler.lift(status.error_buf)
} else if (status.isPanic()) {
// when the rust code sees a panic, it tries to construct a rustbuffer
// with the message. but if that code panics, then it just sends back
// an empty buffer.
if (status.error_buf.len > 0) {
throw InternalException(FfiConverterString.lift(status.error_buf))
} else {
throw InternalException("Rust panic")
}
} else {
throw InternalException("Unknown rust call status: $status.code")
}
}
/**
* UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
*
* @suppress
*/
object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
override fun lift(error_buf: RustBuffer.ByValue): InternalException {
RustBuffer.free(error_buf)
return InternalException("Unexpected CALL_ERROR")
}
}
// Call a rust function that returns a plain value
private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
}
internal inline fun<T> uniffiTraitInterfaceCall(
callStatus: UniffiRustCallStatus,
makeCall: () -> T,
writeReturn: (T) -> Unit,
) {
try {
writeReturn(makeCall())
} catch(e: kotlin.Exception) {
val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
callStatus.error_buf = FfiConverterString.lower(err)
}
}
internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
callStatus: UniffiRustCallStatus,
makeCall: () -> T,
writeReturn: (T) -> Unit,
lowerError: (E) -> RustBuffer.ByValue
) {
try {
writeReturn(makeCall())
} catch(e: kotlin.Exception) {
if (e is E) {
callStatus.code = UNIFFI_CALL_ERROR
callStatus.error_buf = lowerError(e)
} else {
val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
callStatus.error_buf = FfiConverterString.lower(err)
}
}
}
// Initial value and increment amount for handles.
// These ensure that Kotlin-generated handles always have the lowest bit set
private const val UNIFFI_HANDLEMAP_INITIAL = 1.toLong()
private const val UNIFFI_HANDLEMAP_DELTA = 2.toLong()
// Map handles to objects
//
// This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
internal class UniffiHandleMap<T: Any> {
private val map = ConcurrentHashMap<Long, T>()
// Start
private val counter = java.util.concurrent.atomic.AtomicLong(UNIFFI_HANDLEMAP_INITIAL)
val size: Int
get() = map.size
// Insert a new object into the handle map and get a handle for it
fun insert(obj: T): Long {
val handle = counter.getAndAdd(UNIFFI_HANDLEMAP_DELTA)
map.put(handle, obj)
return handle
}
// Clone a handle, creating a new one
fun clone(handle: Long): Long {
val obj = map.get(handle) ?: throw InternalException("UniffiHandleMap.clone: Invalid handle")
return insert(obj)
}
// Get an object from the handle map
fun get(handle: Long): T {
return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
}
// Remove an entry from the handlemap and get the Kotlin object back
fun remove(handle: Long): T {
return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
}
}
// Contains loading, initialization code,
// and the FFI Function declarations in a com.sun.jna.Library.
@Synchronized
private fun findLibraryName(componentName: String): String {
val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
if (libOverride != null) {
return libOverride
}
return "peat_btle"
}
// Define FFI callback types
internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
fun callback(`data`: Long,`pollResult`: Byte,)
}
internal interface UniffiForeignFutureDroppedCallback : com.sun.jna.Callback {
fun callback(`handle`: Long,)
}
internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
fun callback(`handle`: Long,)
}
internal interface UniffiCallbackInterfaceClone : com.sun.jna.Callback {
fun callback(`handle`: Long,)
: Long
}
@Structure.FieldOrder("handle", "free")
internal open class UniffiForeignFutureDroppedCallbackStruct(
@JvmField internal var `handle`: Long = 0.toLong(),
@JvmField internal var `free`: UniffiForeignFutureDroppedCallback? = null,
) : Structure() {
class UniffiByValue(
`handle`: Long = 0.toLong(),
`free`: UniffiForeignFutureDroppedCallback? = null,
): UniffiForeignFutureDroppedCallbackStruct(`handle`,`free`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureDroppedCallbackStruct) {
`handle` = other.`handle`
`free` = other.`free`
}
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU8(
@JvmField internal var `returnValue`: Byte = 0.toByte(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Byte = 0.toByte(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultU8(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultU8) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU8.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI8(
@JvmField internal var `returnValue`: Byte = 0.toByte(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Byte = 0.toByte(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultI8(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultI8) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI8.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU16(
@JvmField internal var `returnValue`: Short = 0.toShort(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Short = 0.toShort(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultU16(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultU16) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU16.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI16(
@JvmField internal var `returnValue`: Short = 0.toShort(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Short = 0.toShort(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultI16(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultI16) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI16.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU32(
@JvmField internal var `returnValue`: Int = 0,
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Int = 0,
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultU32(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultU32) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI32(
@JvmField internal var `returnValue`: Int = 0,
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Int = 0,
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultI32(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultI32) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU64(
@JvmField internal var `returnValue`: Long = 0.toLong(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Long = 0.toLong(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultU64(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultU64) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI64(
@JvmField internal var `returnValue`: Long = 0.toLong(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Long = 0.toLong(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultI64(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultI64) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultF32(
@JvmField internal var `returnValue`: Float = 0.0f,
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Float = 0.0f,
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultF32(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultF32) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultF64(
@JvmField internal var `returnValue`: Double = 0.0,
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Double = 0.0,
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultF64(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultF64) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultRustBuffer(
@JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultRustBuffer) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultRustBuffer.UniffiByValue,)
}
@Structure.FieldOrder("callStatus")
internal open class UniffiForeignFutureResultVoid(
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultVoid(`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultVoid) {
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultVoid.UniffiByValue,)
}
// A JNA Library to expose the extern-C FFI definitions.
// This is an implementation detail which will be called internally by the public API.
// For large crates we prevent `MethodTooLargeException` (see #2340)
// N.B. the name of the extension is very misleading, since it is
// rather `InterfaceTooLargeException`, caused by too many methods
// in the interface for large crates.
//
// By splitting the otherwise huge interface into two parts
// * UniffiLib (this)
// * IntegrityCheckingUniffiLib
// And all checksum methods are put into `IntegrityCheckingUniffiLib`
// we allow for ~2x as many methods in the UniffiLib interface.
//
// Note: above all written when we used JNA's `loadIndirect` etc.
// We now use JNA's "direct mapping" - unclear if same considerations apply exactly.
internal object IntegrityCheckingUniffiLib {
init {
Native.register(IntegrityCheckingUniffiLib::class.java, findLibraryName(componentName = "peat_btle"))
uniffiCheckContractApiVersion(this)
uniffiCheckApiChecksums(this)
}
external fun uniffi_peat_btle_checksum_func_create_peat_mesh_with_encryption(
): Short
external fun uniffi_peat_btle_checksum_func_decode_identity_attestation(
): Short
external fun uniffi_peat_btle_checksum_func_decode_mesh_genesis(
): Short
external fun uniffi_peat_btle_checksum_func_derive_node_id_from_mac(
): Short
external fun uniffi_peat_btle_checksum_func_detect_device_pattern(
): Short
external fun uniffi_peat_btle_checksum_func_device_pattern_rotates_addresses(
): Short
external fun uniffi_peat_btle_checksum_func_is_weartak_device(
): Short
external fun uniffi_peat_btle_checksum_func_normalize_weartak_name(
): Short
external fun uniffi_peat_btle_checksum_func_restore_device_identity(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_clear(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_device_count(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_get_address(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_get_name(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_lookup_by_address(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_lookup_by_name(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_on_device_discovered(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_register_device(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_remove_device(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_stats(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_update_address(
): Short
external fun uniffi_peat_btle_checksum_method_addressrotationhandler_update_name(
): Short
external fun uniffi_peat_btle_checksum_method_deviceidentity_create_attestation(
): Short
external fun uniffi_peat_btle_checksum_method_deviceidentity_get_node_id(
): Short
external fun uniffi_peat_btle_checksum_method_deviceidentity_get_private_key(
): Short
external fun uniffi_peat_btle_checksum_method_deviceidentity_get_public_key(
): Short
external fun uniffi_peat_btle_checksum_method_deviceidentity_sign(
): Short
external fun uniffi_peat_btle_checksum_method_identityattestation_get_node_id(
): Short
external fun uniffi_peat_btle_checksum_method_identityattestation_get_public_key(
): Short
external fun uniffi_peat_btle_checksum_method_identityattestation_verify(
): Short
external fun uniffi_peat_btle_checksum_method_meshgenesis_encode(
): Short
external fun uniffi_peat_btle_checksum_method_meshgenesis_get_encryption_secret(
): Short
external fun uniffi_peat_btle_checksum_method_meshgenesis_get_mesh_id(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_app_document_count(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_broadcast_bytes(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_build_delta_document_for_peer(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_build_document(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_build_full_delta_document(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_check_canned_message(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_clear_location(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_clear_peripheral_event(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_connected_count(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_create_attestation(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_decrypt_only(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_degraded_peer_count(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_connected_peer_identifiers(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_connected_peers(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_connection_state_counts(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_degraded_peers(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_full_state_counts(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_indirect_peers(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_lost_peers(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_peer_callsign(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_peer_connection_state(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_get_public_key(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_has_identity(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_is_ack_active(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_is_emergency_active(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_is_encryption_enabled(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_is_peer_identity_known(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_is_peer_known(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_is_relay_enabled(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_known_identity_count(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_lost_peer_count(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_mark_canned_message_seen(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_matches_mesh(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_on_ble_connected(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_on_ble_data_received(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_on_ble_data_received_anonymous(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_on_ble_disconnected(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_on_ble_discovered(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_on_incoming_connection(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_peer_count(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_recently_disconnected_count(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_send_ack(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_send_emergency(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_set_peripheral_event(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_sign(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_tick(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_total_count(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_update_callsign(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_update_heart_rate(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_update_location(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_update_peripheral_state(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_verify_peer_identity(
): Short
external fun uniffi_peat_btle_checksum_method_peatmesh_verify_peer_signature(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_cleanup_interval_ms(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_cleanup_stale_peers(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_clear(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_get_peer_info(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_get_stale_peer_addresses(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_get_stale_peers(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_is_connected(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_is_tracked(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_on_peer_activity(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_on_peer_disconnected(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_remove_peer(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_stats(
): Short
external fun uniffi_peat_btle_checksum_method_peerlifetimemanager_tracked_count(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_check_interval_ms(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_clear(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_get_peer_stats(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_get_peers_to_reconnect(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_get_status(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_is_tracked(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_on_connection_success(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_record_attempt(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_stop_tracking(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_track_disconnection(
): Short
external fun uniffi_peat_btle_checksum_method_reconnectionmanager_tracked_count(
): Short
external fun uniffi_peat_btle_checksum_constructor_addressrotationhandler_new(
): Short
external fun uniffi_peat_btle_checksum_constructor_deviceidentity_generate(
): Short
external fun uniffi_peat_btle_checksum_constructor_meshgenesis_create(
): Short
external fun uniffi_peat_btle_checksum_constructor_peatmesh_new(
): Short
external fun uniffi_peat_btle_checksum_constructor_peatmesh_new_from_genesis(
): Short
external fun uniffi_peat_btle_checksum_constructor_peatmesh_new_with_peripheral(
): Short
external fun uniffi_peat_btle_checksum_constructor_peerlifetimemanager_new(
): Short
external fun uniffi_peat_btle_checksum_constructor_peerlifetimemanager_with_defaults(
): Short
external fun uniffi_peat_btle_checksum_constructor_reconnectionmanager_new(
): Short
external fun uniffi_peat_btle_checksum_constructor_reconnectionmanager_with_defaults(
): Short
external fun ffi_peat_btle_uniffi_contract_version(
): Int
}
internal object UniffiLib {
// The Cleaner for the whole library
internal val CLEANER: UniffiCleaner by lazy {
UniffiCleaner.create()
}
init {
Native.register(UniffiLib::class.java, findLibraryName(componentName = "peat_btle"))
}
external fun uniffi_peat_btle_fn_clone_addressrotationhandler(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_free_addressrotationhandler(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_constructor_addressrotationhandler_new(uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_method_addressrotationhandler_clear(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_addressrotationhandler_device_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_addressrotationhandler_get_address(`ptr`: Long,`nodeId`: Int,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_addressrotationhandler_get_name(`ptr`: Long,`nodeId`: Int,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_addressrotationhandler_lookup_by_address(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_addressrotationhandler_lookup_by_name(`ptr`: Long,`name`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_addressrotationhandler_on_device_discovered(`ptr`: Long,`name`: RustBuffer.ByValue,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_addressrotationhandler_register_device(`ptr`: Long,`name`: RustBuffer.ByValue,`address`: RustBuffer.ByValue,`nodeId`: Int,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_addressrotationhandler_remove_device(`ptr`: Long,`nodeId`: Int,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_addressrotationhandler_stats(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_addressrotationhandler_update_address(`ptr`: Long,`name`: RustBuffer.ByValue,`newAddress`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_addressrotationhandler_update_name(`ptr`: Long,`nodeId`: Int,`newName`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_clone_deviceidentity(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_free_deviceidentity(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_constructor_deviceidentity_generate(uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_method_deviceidentity_create_attestation(`ptr`: Long,`timestampMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_deviceidentity_get_node_id(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_deviceidentity_get_private_key(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_deviceidentity_get_public_key(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_deviceidentity_sign(`ptr`: Long,`message`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_clone_identityattestation(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_free_identityattestation(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_identityattestation_get_node_id(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_identityattestation_get_public_key(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_identityattestation_verify(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_clone_meshgenesis(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_free_meshgenesis(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_constructor_meshgenesis_create(`meshName`: RustBuffer.ByValue,`founderIdentity`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_method_meshgenesis_encode(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_meshgenesis_get_encryption_secret(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_meshgenesis_get_mesh_id(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_clone_peatmesh(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_free_peatmesh(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_constructor_peatmesh_new(`nodeId`: Int,`callsign`: RustBuffer.ByValue,`meshId`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_constructor_peatmesh_new_from_genesis(`callsign`: RustBuffer.ByValue,`identity`: Long,`genesis`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_constructor_peatmesh_new_with_peripheral(`nodeId`: Int,`callsign`: RustBuffer.ByValue,`meshId`: RustBuffer.ByValue,`peripheralType`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_method_peatmesh_app_document_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_peatmesh_broadcast_bytes(`ptr`: Long,`payload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_build_delta_document_for_peer(`ptr`: Long,`peerId`: Int,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_build_document(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_build_full_delta_document(`ptr`: Long,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_check_canned_message(`ptr`: Long,`sourceNode`: Int,`timestamp`: Long,`ttlMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_clear_location(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_clear_peripheral_event(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_connected_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_peatmesh_create_attestation(`ptr`: Long,`timestampMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_decrypt_only(`ptr`: Long,`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_degraded_peer_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_peatmesh_get_connected_peer_identifiers(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_connected_peers(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_connection_state_counts(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_degraded_peers(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_full_state_counts(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_indirect_peers(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_lost_peers(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_peer_callsign(`ptr`: Long,`nodeId`: Int,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_peer_connection_state(`ptr`: Long,`nodeId`: Int,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_get_public_key(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_has_identity(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_is_ack_active(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_is_emergency_active(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_is_encryption_enabled(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_is_peer_identity_known(`ptr`: Long,`nodeId`: Int,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_is_peer_known(`ptr`: Long,`nodeId`: Int,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_is_relay_enabled(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_known_identity_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_peatmesh_lost_peer_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_peatmesh_mark_canned_message_seen(`ptr`: Long,`sourceNode`: Int,`timestamp`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_matches_mesh(`ptr`: Long,`deviceMeshId`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_on_ble_connected(`ptr`: Long,`identifier`: RustBuffer.ByValue,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_on_ble_data_received(`ptr`: Long,`identifier`: RustBuffer.ByValue,`data`: RustBuffer.ByValue,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_on_ble_data_received_anonymous(`ptr`: Long,`identifier`: RustBuffer.ByValue,`data`: RustBuffer.ByValue,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_on_ble_disconnected(`ptr`: Long,`identifier`: RustBuffer.ByValue,`reason`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_on_ble_discovered(`ptr`: Long,`identifier`: RustBuffer.ByValue,`name`: RustBuffer.ByValue,`rssi`: Byte,`meshId`: RustBuffer.ByValue,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_on_incoming_connection(`ptr`: Long,`identifier`: RustBuffer.ByValue,`nodeId`: Int,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_peer_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_peatmesh_recently_disconnected_count(`ptr`: Long,`withinMs`: Long,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_peatmesh_send_ack(`ptr`: Long,`timestampMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_send_emergency(`ptr`: Long,`timestampMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_set_peripheral_event(`ptr`: Long,`eventType`: RustBuffer.ByValue,`timestampMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_sign(`ptr`: Long,`message`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_tick(`ptr`: Long,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peatmesh_total_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_method_peatmesh_update_callsign(`ptr`: Long,`callsign`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_update_heart_rate(`ptr`: Long,`bpm`: Byte,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_update_location(`ptr`: Long,`latitude`: Float,`longitude`: Float,`altitude`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_update_peripheral_state(`ptr`: Long,`callsign`: RustBuffer.ByValue,`batteryPercent`: Byte,`heartRate`: RustBuffer.ByValue,`latitude`: RustBuffer.ByValue,`longitude`: RustBuffer.ByValue,`altitude`: RustBuffer.ByValue,`eventType`: RustBuffer.ByValue,`timestampMs`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peatmesh_verify_peer_identity(`ptr`: Long,`attestationBytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peatmesh_verify_peer_signature(`ptr`: Long,`nodeId`: Int,`message`: RustBuffer.ByValue,`signature`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_clone_peerlifetimemanager(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_free_peerlifetimemanager(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_constructor_peerlifetimemanager_new(`config`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_constructor_peerlifetimemanager_with_defaults(uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_cleanup_interval_ms(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_cleanup_stale_peers(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_clear(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_get_peer_info(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_get_stale_peer_addresses(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_get_stale_peers(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_is_connected(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_is_tracked(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_on_peer_activity(`ptr`: Long,`address`: RustBuffer.ByValue,`connected`: Byte,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_on_peer_disconnected(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_remove_peer(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_stats(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_peerlifetimemanager_tracked_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_clone_reconnectionmanager(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_free_reconnectionmanager(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_constructor_reconnectionmanager_new(`config`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_constructor_reconnectionmanager_with_defaults(uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_method_reconnectionmanager_check_interval_ms(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_peat_btle_fn_method_reconnectionmanager_clear(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_reconnectionmanager_get_peer_stats(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_reconnectionmanager_get_peers_to_reconnect(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_reconnectionmanager_get_status(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_method_reconnectionmanager_is_tracked(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_method_reconnectionmanager_on_connection_success(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_reconnectionmanager_record_attempt(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_reconnectionmanager_stop_tracking(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_reconnectionmanager_track_disconnection(`ptr`: Long,`address`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_peat_btle_fn_method_reconnectionmanager_tracked_count(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_func_create_peat_mesh_with_encryption(`nodeId`: Int,`callsign`: RustBuffer.ByValue,`meshId`: RustBuffer.ByValue,`encryptionSecret`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_func_decode_identity_attestation(`encoded`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_func_decode_mesh_genesis(`encoded`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_func_derive_node_id_from_mac(`macAddress`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun uniffi_peat_btle_fn_func_detect_device_pattern(`name`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_func_device_pattern_rotates_addresses(`pattern`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_func_is_weartak_device(`name`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_peat_btle_fn_func_normalize_weartak_name(`name`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_peat_btle_fn_func_restore_device_identity(`privateKey`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_peat_btle_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_peat_btle_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_peat_btle_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun ffi_peat_btle_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_peat_btle_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_u8(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_u8(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun ffi_peat_btle_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_i8(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_i8(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun ffi_peat_btle_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_u16(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_u16(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Short
external fun ffi_peat_btle_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_i16(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_i16(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Short
external fun ffi_peat_btle_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_u32(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_u32(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun ffi_peat_btle_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_i32(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_i32(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun ffi_peat_btle_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_u64(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_u64(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun ffi_peat_btle_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_i64(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_i64(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun ffi_peat_btle_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_f32(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_f32(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Float
external fun ffi_peat_btle_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_f64(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_f64(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Double
external fun ffi_peat_btle_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_rust_buffer(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_rust_buffer(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_peat_btle_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_peat_btle_rust_future_cancel_void(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_free_void(`handle`: Long,
): Unit
external fun ffi_peat_btle_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
}
private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
// Get the bindings contract version from our ComponentInterface
val bindings_contract_version = 30
// Get the scaffolding contract version by calling the into the dylib
val scaffolding_contract_version = lib.ffi_peat_btle_uniffi_contract_version()
if (bindings_contract_version != scaffolding_contract_version) {
throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
}
}
@Suppress("UNUSED_PARAMETER")
private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
if (lib.uniffi_peat_btle_checksum_func_create_peat_mesh_with_encryption() != 8791.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_func_decode_identity_attestation() != 26160.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_func_decode_mesh_genesis() != 36795.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_func_derive_node_id_from_mac() != 10625.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_func_detect_device_pattern() != 11492.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_func_device_pattern_rotates_addresses() != 21318.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_func_is_weartak_device() != 26078.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_func_normalize_weartak_name() != 47405.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_func_restore_device_identity() != 29006.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_clear() != 53535.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_device_count() != 16223.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_get_address() != 57983.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_get_name() != 52417.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_lookup_by_address() != 39668.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_lookup_by_name() != 56375.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_on_device_discovered() != 47550.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_register_device() != 54303.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_remove_device() != 12512.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_stats() != 13682.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_update_address() != 38432.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_addressrotationhandler_update_name() != 63100.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_deviceidentity_create_attestation() != 29147.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_deviceidentity_get_node_id() != 1634.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_deviceidentity_get_private_key() != 33709.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_deviceidentity_get_public_key() != 29944.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_deviceidentity_sign() != 46839.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_identityattestation_get_node_id() != 55998.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_identityattestation_get_public_key() != 41158.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_identityattestation_verify() != 31163.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_meshgenesis_encode() != 18825.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_meshgenesis_get_encryption_secret() != 38684.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_meshgenesis_get_mesh_id() != 52516.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_app_document_count() != 46291.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_broadcast_bytes() != 9893.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_build_delta_document_for_peer() != 30080.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_build_document() != 37515.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_build_full_delta_document() != 8532.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_check_canned_message() != 51036.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_clear_location() != 46239.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_clear_peripheral_event() != 49272.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_connected_count() != 51353.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_create_attestation() != 64449.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_decrypt_only() != 58164.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_degraded_peer_count() != 22422.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_connected_peer_identifiers() != 56037.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_connected_peers() != 20341.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_connection_state_counts() != 46062.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_degraded_peers() != 51684.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_full_state_counts() != 8380.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_indirect_peers() != 50632.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_lost_peers() != 910.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_peer_callsign() != 46753.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_peer_connection_state() != 42326.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_get_public_key() != 25611.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_has_identity() != 9142.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_is_ack_active() != 36029.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_is_emergency_active() != 65503.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_is_encryption_enabled() != 46071.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_is_peer_identity_known() != 34678.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_is_peer_known() != 62882.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_is_relay_enabled() != 40734.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_known_identity_count() != 9182.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_lost_peer_count() != 37496.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_mark_canned_message_seen() != 51245.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_matches_mesh() != 24845.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_on_ble_connected() != 64877.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_on_ble_data_received() != 19910.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_on_ble_data_received_anonymous() != 26072.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_on_ble_disconnected() != 14024.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_on_ble_discovered() != 34711.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_on_incoming_connection() != 31705.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_peer_count() != 1281.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_recently_disconnected_count() != 45885.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_send_ack() != 56358.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_send_emergency() != 54121.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_set_peripheral_event() != 27428.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_sign() != 53236.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_tick() != 48013.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_total_count() != 40886.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_update_callsign() != 51189.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_update_heart_rate() != 62571.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_update_location() != 28482.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_update_peripheral_state() != 14377.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_verify_peer_identity() != 62927.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peatmesh_verify_peer_signature() != 61530.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_cleanup_interval_ms() != 61653.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_cleanup_stale_peers() != 57903.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_clear() != 53821.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_get_peer_info() != 23475.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_get_stale_peer_addresses() != 30794.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_get_stale_peers() != 22629.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_is_connected() != 6579.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_is_tracked() != 9837.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_on_peer_activity() != 27935.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_on_peer_disconnected() != 18356.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_remove_peer() != 17358.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_stats() != 20092.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_peerlifetimemanager_tracked_count() != 53156.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_check_interval_ms() != 40972.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_clear() != 37388.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_get_peer_stats() != 55626.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_get_peers_to_reconnect() != 33093.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_get_status() != 2736.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_is_tracked() != 35559.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_on_connection_success() != 34382.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_record_attempt() != 52161.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_stop_tracking() != 39616.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_track_disconnection() != 41571.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_method_reconnectionmanager_tracked_count() != 45363.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_addressrotationhandler_new() != 10200.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_deviceidentity_generate() != 58786.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_meshgenesis_create() != 16963.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_peatmesh_new() != 49261.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_peatmesh_new_from_genesis() != 27401.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_peatmesh_new_with_peripheral() != 1613.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_peerlifetimemanager_new() != 32859.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_peerlifetimemanager_with_defaults() != 59128.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_reconnectionmanager_new() != 20303.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_peat_btle_checksum_constructor_reconnectionmanager_with_defaults() != 59976.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}
/**
* @suppress
*/
public fun uniffiEnsureInitialized() {
IntegrityCheckingUniffiLib
// UniffiLib() initialized as objects are used, but we still need to explicitly
// reference it so initialization across crates works as expected.
UniffiLib
}
// Async support
// Public interface members begin here.
// Interface implemented by anything that can contain an object reference.
//
// Such types expose a `destroy()` method that must be called to cleanly
// dispose of the contained objects. Failure to call this method may result
// in memory leaks.
//
// The easiest way to ensure this method is called is to use the `.use`
// helper method to execute a block and destroy the object at the end.
interface Disposable {
fun destroy()
companion object {
fun destroy(vararg args: Any?) {
for (arg in args) {
when (arg) {
is Disposable -> arg.destroy()
is ArrayList<*> -> {
for (idx in arg.indices) {
val element = arg[idx]
if (element is Disposable) {
element.destroy()
}
}
}
is Map<*, *> -> {
for (element in arg.values) {
if (element is Disposable) {
element.destroy()
}
}
}
is Iterable<*> -> {
for (element in arg) {
if (element is Disposable) {
element.destroy()
}
}
}
}
}
}
}
}
/**
* @suppress
*/
inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
try {
block(this)
} finally {
try {
// N.B. our implementation is on the nullable type `Disposable?`.
this?.destroy()
} catch (e: Throwable) {
// swallow
}
}
/**
* Placeholder object used to signal that we're constructing an interface with a FFI handle.
*
* This is the first argument for interface constructors that input a raw handle. It exists is that
* so we can avoid signature conflicts when an interface has a regular constructor than inputs a
* Long.
*
* @suppress
* */
object UniffiWithHandle
/**
* Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
*
* @suppress
* */
object NoHandle
/**
* The cleaner interface for Object finalization code to run.
* This is the entry point to any implementation that we're using.
*
* The cleaner registers objects and returns cleanables, so now we are
* defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
* different implmentations available at compile time.
*
* @suppress
*/
interface UniffiCleaner {
interface Cleanable {
fun clean()
}
fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable
companion object
}
// The fallback Jna cleaner, which is available for both Android, and the JVM.
private class UniffiJnaCleaner : UniffiCleaner {
private val cleaner = com.sun.jna.internal.Cleaner.getCleaner()
override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
UniffiJnaCleanable(cleaner.register(value, cleanUpTask))
}
private class UniffiJnaCleanable(
private val cleanable: com.sun.jna.internal.Cleaner.Cleanable,
) : UniffiCleaner.Cleanable {
override fun clean() = cleanable.clean()
}
// We decide at uniffi binding generation time whether we were
// using Android or not.
// There are further runtime checks to chose the correct implementation
// of the cleaner.
private fun UniffiCleaner.Companion.create(): UniffiCleaner =
try {
// For safety's sake: if the library hasn't been run in android_cleaner = true
// mode, but is being run on Android, then we still need to think about
// Android API versions.
// So we check if java.lang.ref.Cleaner is there, and use that…
java.lang.Class.forName("java.lang.ref.Cleaner")
JavaLangRefCleaner()
} catch (e: ClassNotFoundException) {
// … otherwise, fallback to the JNA cleaner.
UniffiJnaCleaner()
}
private class JavaLangRefCleaner : UniffiCleaner {
val cleaner = java.lang.ref.Cleaner.create()
override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
}
private class JavaLangRefCleanable(
val cleanable: java.lang.ref.Cleaner.Cleanable
) : UniffiCleaner.Cleanable {
override fun clean() = cleanable.clean()
}
/**
* @suppress
*/
public object FfiConverterUByte: FfiConverter<UByte, Byte> {
override fun lift(value: Byte): UByte {
return value.toUByte()
}
override fun read(buf: ByteBuffer): UByte {
return lift(buf.get())
}
override fun lower(value: UByte): Byte {
return value.toByte()
}
override fun allocationSize(value: UByte) = 1UL
override fun write(value: UByte, buf: ByteBuffer) {
buf.put(value.toByte())
}
}
/**
* @suppress
*/
public object FfiConverterByte: FfiConverter<Byte, Byte> {
override fun lift(value: Byte): Byte {
return value
}
override fun read(buf: ByteBuffer): Byte {
return buf.get()
}
override fun lower(value: Byte): Byte {
return value
}
override fun allocationSize(value: Byte) = 1UL
override fun write(value: Byte, buf: ByteBuffer) {
buf.put(value)
}
}
/**
* @suppress
*/
public object FfiConverterUInt: FfiConverter<UInt, Int> {
override fun lift(value: Int): UInt {
return value.toUInt()
}
override fun read(buf: ByteBuffer): UInt {
return lift(buf.getInt())
}
override fun lower(value: UInt): Int {
return value.toInt()
}
override fun allocationSize(value: UInt) = 4UL
override fun write(value: UInt, buf: ByteBuffer) {
buf.putInt(value.toInt())
}
}
/**
* @suppress
*/
public object FfiConverterULong: FfiConverter<ULong, Long> {
override fun lift(value: Long): ULong {
return value.toULong()
}
override fun read(buf: ByteBuffer): ULong {
return lift(buf.getLong())
}
override fun lower(value: ULong): Long {
return value.toLong()
}
override fun allocationSize(value: ULong) = 8UL
override fun write(value: ULong, buf: ByteBuffer) {
buf.putLong(value.toLong())
}
}
/**
* @suppress
*/
public object FfiConverterFloat: FfiConverter<Float, Float> {
override fun lift(value: Float): Float {
return value
}
override fun read(buf: ByteBuffer): Float {
return buf.getFloat()
}
override fun lower(value: Float): Float {
return value
}
override fun allocationSize(value: Float) = 4UL
override fun write(value: Float, buf: ByteBuffer) {
buf.putFloat(value)
}
}
/**
* @suppress
*/
public object FfiConverterBoolean: FfiConverter<Boolean, Byte> {
override fun lift(value: Byte): Boolean {
return value.toInt() != 0
}
override fun read(buf: ByteBuffer): Boolean {
return lift(buf.get())
}
override fun lower(value: Boolean): Byte {
return if (value) 1.toByte() else 0.toByte()
}
override fun allocationSize(value: Boolean) = 1UL
override fun write(value: Boolean, buf: ByteBuffer) {
buf.put(lower(value))
}
}
/**
* @suppress
*/
public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
// Note: we don't inherit from FfiConverterRustBuffer, because we use a
// special encoding when lowering/lifting. We can use `RustBuffer.len` to
// store our length and avoid writing it out to the buffer.
override fun lift(value: RustBuffer.ByValue): String {
try {
val byteArr = ByteArray(value.len.toInt())
value.asByteBuffer()!!.get(byteArr)
return byteArr.toString(Charsets.UTF_8)
} finally {
RustBuffer.free(value)
}
}
override fun read(buf: ByteBuffer): String {
val len = buf.getInt()
val byteArr = ByteArray(len)
buf.get(byteArr)
return byteArr.toString(Charsets.UTF_8)
}
fun toUtf8(value: String): ByteBuffer {
// Make sure we don't have invalid UTF-16, check for lone surrogates.
return Charsets.UTF_8.newEncoder().run {
onMalformedInput(CodingErrorAction.REPORT)
encode(CharBuffer.wrap(value))
}
}
override fun lower(value: String): RustBuffer.ByValue {
val byteBuf = toUtf8(value)
// Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
// to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
rbuf.asByteBuffer()!!.put(byteBuf)
return rbuf
}
// We aren't sure exactly how many bytes our string will be once it's UTF-8
// encoded. Allocate 3 bytes per UTF-16 code unit which will always be
// enough.
override fun allocationSize(value: String): ULong {
val sizeForLength = 4UL
val sizeForString = value.length.toULong() * 3UL
return sizeForLength + sizeForString
}
override fun write(value: String, buf: ByteBuffer) {
val byteBuf = toUtf8(value)
buf.putInt(byteBuf.limit())
buf.put(byteBuf)
}
}
/**
* @suppress
*/
public object FfiConverterByteArray: FfiConverterRustBuffer<ByteArray> {
override fun read(buf: ByteBuffer): ByteArray {
val len = buf.getInt()
val byteArr = ByteArray(len)
buf.get(byteArr)
return byteArr
}
override fun allocationSize(value: ByteArray): ULong {
return 4UL + value.size.toULong()
}
override fun write(value: ByteArray, buf: ByteBuffer) {
buf.putInt(value.size)
buf.put(value)
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Handler for BLE address rotation
*/
public interface AddressRotationHandlerInterface {
/**
* Clear all mappings
*/
fun `clear`()
/**
* Get the number of tracked devices
*/
fun `deviceCount`(): kotlin.UInt
/**
* Get the current address for a node
*/
fun `getAddress`(`nodeId`: kotlin.UInt): kotlin.String?
/**
* Get the name for a node
*/
fun `getName`(`nodeId`: kotlin.UInt): kotlin.String?
/**
* Look up a device by address
*/
fun `lookupByAddress`(`address`: kotlin.String): kotlin.UInt?
/**
* Look up a device by name
*/
fun `lookupByName`(`name`: kotlin.String): kotlin.UInt?
/**
* Handle a device discovery, detecting address rotation
*/
fun `onDeviceDiscovered`(`name`: kotlin.String, `address`: kotlin.String): DeviceLookupResult?
/**
* Register a new device
*/
fun `registerDevice`(`name`: kotlin.String, `address`: kotlin.String, `nodeId`: kotlin.UInt)
/**
* Remove a device from all mappings
*/
fun `removeDevice`(`nodeId`: kotlin.UInt)
/**
* Get statistics about tracked mappings
*/
fun `stats`(): AddressRotationStats
/**
* Update the address for a device (used when address rotation is detected)
*/
fun `updateAddress`(`name`: kotlin.String, `newAddress`: kotlin.String): kotlin.Boolean
/**
* Update the name for a device
*/
fun `updateName`(`nodeId`: kotlin.UInt, `newName`: kotlin.String)
companion object
}
/**
* Handler for BLE address rotation
*/
open class AddressRotationHandler: Disposable, AutoCloseable, AddressRotationHandlerInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
/**
* Create a new address rotation handler
*/
constructor() :
this(UniffiWithHandle,
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_addressrotationhandler_new(
_status)
}
)
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_peat_btle_fn_free_addressrotationhandler(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_peat_btle_fn_clone_addressrotationhandler(handle, status)
}
}
/**
* Clear all mappings
*/override fun `clear`()
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_clear(
it,
_status)
}
}
/**
* Get the number of tracked devices
*/override fun `deviceCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_device_count(
it,
_status)
}
}
)
}
/**
* Get the current address for a node
*/override fun `getAddress`(`nodeId`: kotlin.UInt): kotlin.String? {
return FfiConverterOptionalString.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_get_address(
it,
FfiConverterUInt.lower(`nodeId`),_status)
}
}
)
}
/**
* Get the name for a node
*/override fun `getName`(`nodeId`: kotlin.UInt): kotlin.String? {
return FfiConverterOptionalString.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_get_name(
it,
FfiConverterUInt.lower(`nodeId`),_status)
}
}
)
}
/**
* Look up a device by address
*/override fun `lookupByAddress`(`address`: kotlin.String): kotlin.UInt? {
return FfiConverterOptionalUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_lookup_by_address(
it,
FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Look up a device by name
*/override fun `lookupByName`(`name`: kotlin.String): kotlin.UInt? {
return FfiConverterOptionalUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_lookup_by_name(
it,
FfiConverterString.lower(`name`),_status)
}
}
)
}
/**
* Handle a device discovery, detecting address rotation
*/override fun `onDeviceDiscovered`(`name`: kotlin.String, `address`: kotlin.String): DeviceLookupResult? {
return FfiConverterOptionalTypeDeviceLookupResult.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_on_device_discovered(
it,
FfiConverterString.lower(`name`),FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Register a new device
*/override fun `registerDevice`(`name`: kotlin.String, `address`: kotlin.String, `nodeId`: kotlin.UInt)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_register_device(
it,
FfiConverterString.lower(`name`),FfiConverterString.lower(`address`),FfiConverterUInt.lower(`nodeId`),_status)
}
}
/**
* Remove a device from all mappings
*/override fun `removeDevice`(`nodeId`: kotlin.UInt)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_remove_device(
it,
FfiConverterUInt.lower(`nodeId`),_status)
}
}
/**
* Get statistics about tracked mappings
*/override fun `stats`(): AddressRotationStats {
return FfiConverterTypeAddressRotationStats.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_stats(
it,
_status)
}
}
)
}
/**
* Update the address for a device (used when address rotation is detected)
*/override fun `updateAddress`(`name`: kotlin.String, `newAddress`: kotlin.String): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_update_address(
it,
FfiConverterString.lower(`name`),FfiConverterString.lower(`newAddress`),_status)
}
}
)
}
/**
* Update the name for a device
*/override fun `updateName`(`nodeId`: kotlin.UInt, `newName`: kotlin.String)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_addressrotationhandler_update_name(
it,
FfiConverterUInt.lower(`nodeId`),FfiConverterString.lower(`newName`),_status)
}
}
/**
* @suppress
*/
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeAddressRotationHandler: FfiConverter<AddressRotationHandler, Long> {
override fun lower(value: AddressRotationHandler): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): AddressRotationHandler {
return AddressRotationHandler(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): AddressRotationHandler {
return lift(buf.getLong())
}
override fun allocationSize(value: AddressRotationHandler) = 8UL
override fun write(value: AddressRotationHandler, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
public interface DeviceIdentityInterface {
/**
* Create an attestation proving identity ownership
*/
fun `createAttestation`(`timestampMs`: kotlin.ULong): kotlin.ByteArray
/**
* Get derived node ID
*/
fun `getNodeId`(): kotlin.UInt
/**
* Get private key bytes (for secure storage)
*/
fun `getPrivateKey`(): kotlin.ByteArray
/**
* Get public key bytes
*/
fun `getPublicKey`(): kotlin.ByteArray
/**
* Sign data
*/
fun `sign`(`message`: kotlin.ByteArray): kotlin.ByteArray
companion object
}
open class DeviceIdentity: Disposable, AutoCloseable, DeviceIdentityInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_peat_btle_fn_free_deviceidentity(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_peat_btle_fn_clone_deviceidentity(handle, status)
}
}
/**
* Create an attestation proving identity ownership
*/override fun `createAttestation`(`timestampMs`: kotlin.ULong): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_deviceidentity_create_attestation(
it,
FfiConverterULong.lower(`timestampMs`),_status)
}
}
)
}
/**
* Get derived node ID
*/override fun `getNodeId`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_deviceidentity_get_node_id(
it,
_status)
}
}
)
}
/**
* Get private key bytes (for secure storage)
*/override fun `getPrivateKey`(): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_deviceidentity_get_private_key(
it,
_status)
}
}
)
}
/**
* Get public key bytes
*/override fun `getPublicKey`(): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_deviceidentity_get_public_key(
it,
_status)
}
}
)
}
/**
* Sign data
*/override fun `sign`(`message`: kotlin.ByteArray): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_deviceidentity_sign(
it,
FfiConverterByteArray.lower(`message`),_status)
}
}
)
}
companion object {
/**
* Generate a new random identity
*/ fun `generate`(): DeviceIdentity {
return FfiConverterTypeDeviceIdentity.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_deviceidentity_generate(
_status)
}
)
}
}
}
/**
* @suppress
*/
public object FfiConverterTypeDeviceIdentity: FfiConverter<DeviceIdentity, Long> {
override fun lower(value: DeviceIdentity): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): DeviceIdentity {
return DeviceIdentity(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): DeviceIdentity {
return lift(buf.getLong())
}
override fun allocationSize(value: DeviceIdentity) = 8UL
override fun write(value: DeviceIdentity, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
public interface IdentityAttestationInterface {
/**
* Get node ID from attestation
*/
fun `getNodeId`(): kotlin.UInt
/**
* Get public key from attestation
*/
fun `getPublicKey`(): kotlin.ByteArray
/**
* Verify attestation is valid
*/
fun `verify`(): kotlin.Boolean
companion object
}
open class IdentityAttestation: Disposable, AutoCloseable, IdentityAttestationInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_peat_btle_fn_free_identityattestation(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_peat_btle_fn_clone_identityattestation(handle, status)
}
}
/**
* Get node ID from attestation
*/override fun `getNodeId`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_identityattestation_get_node_id(
it,
_status)
}
}
)
}
/**
* Get public key from attestation
*/override fun `getPublicKey`(): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_identityattestation_get_public_key(
it,
_status)
}
}
)
}
/**
* Verify attestation is valid
*/override fun `verify`(): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_identityattestation_verify(
it,
_status)
}
}
)
}
/**
* @suppress
*/
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeIdentityAttestation: FfiConverter<IdentityAttestation, Long> {
override fun lower(value: IdentityAttestation): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): IdentityAttestation {
return IdentityAttestation(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): IdentityAttestation {
return lift(buf.getLong())
}
override fun allocationSize(value: IdentityAttestation) = 8UL
override fun write(value: IdentityAttestation, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
public interface MeshGenesisInterface {
/**
* Encode genesis to bytes for storage/transmission
*/
fun `encode`(): kotlin.ByteArray
/**
* Get encryption secret for mesh
*/
fun `getEncryptionSecret`(): kotlin.ByteArray
/**
* Get mesh ID
*/
fun `getMeshId`(): kotlin.String
companion object
}
open class MeshGenesis: Disposable, AutoCloseable, MeshGenesisInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_peat_btle_fn_free_meshgenesis(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_peat_btle_fn_clone_meshgenesis(handle, status)
}
}
/**
* Encode genesis to bytes for storage/transmission
*/override fun `encode`(): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_meshgenesis_encode(
it,
_status)
}
}
)
}
/**
* Get encryption secret for mesh
*/override fun `getEncryptionSecret`(): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_meshgenesis_get_encryption_secret(
it,
_status)
}
}
)
}
/**
* Get mesh ID
*/override fun `getMeshId`(): kotlin.String {
return FfiConverterString.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_meshgenesis_get_mesh_id(
it,
_status)
}
}
)
}
companion object {
/**
* Create a new mesh as founder
*/ fun `create`(`meshName`: kotlin.String, `founderIdentity`: DeviceIdentity): MeshGenesis {
return FfiConverterTypeMeshGenesis.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_meshgenesis_create(
FfiConverterString.lower(`meshName`),FfiConverterTypeDeviceIdentity.lower(`founderIdentity`),_status)
}
)
}
}
}
/**
* @suppress
*/
public object FfiConverterTypeMeshGenesis: FfiConverter<MeshGenesis, Long> {
override fun lower(value: MeshGenesis): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): MeshGenesis {
return MeshGenesis(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): MeshGenesis {
return lift(buf.getLong())
}
override fun allocationSize(value: MeshGenesis) = 8UL
override fun write(value: MeshGenesis, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
public interface PeatMeshInterface {
/**
* Get the number of stored app documents.
*/
fun `appDocumentCount`(): kotlin.UInt
/**
* Broadcast arbitrary bytes over the mesh.
*
* Takes raw payload bytes, encrypts them (if encryption is enabled),
* and returns bytes ready to send to all connected peers.
*
* This is useful for sending extension data like CannedMessages from peat-lite.
*/
fun `broadcastBytes`(`payload`: kotlin.ByteArray): kotlin.ByteArray
/**
* Build a delta document for a specific peer.
*
* This includes only operations that have changed since the last sync
* with this peer, including app-layer documents (CannedMessages, etc.).
* Returns None if there's nothing new to send.
*/
fun `buildDeltaDocumentForPeer`(`peerId`: kotlin.UInt, `nowMs`: kotlin.ULong): kotlin.ByteArray?
/**
* Build the current document for transmission
*/
fun `buildDocument`(): kotlin.ByteArray
/**
* Build a full delta document containing all current state.
*
* Unlike `build_delta_document_for_peer`, this includes all state
* regardless of what has been sent before. Use for broadcasts or
* new peer connections. Includes app-layer documents.
*/
fun `buildFullDeltaDocument`(`nowMs`: kotlin.ULong): kotlin.ByteArray
/**
* Check if a CannedMessage has been seen recently.
*
* Uses document identity (source_node + timestamp) for deduplication.
* This prevents broadcast storms when relaying CannedMessages.
*
* Returns true if the message should be processed, false if it's a duplicate.
*/
fun `checkCannedMessage`(`sourceNode`: kotlin.UInt, `timestamp`: kotlin.ULong, `ttlMs`: kotlin.ULong): kotlin.Boolean
/**
* Clear own location
*/
fun `clearLocation`()
/**
* Clear peripheral event
*/
fun `clearPeripheralEvent`()
/**
* Get count of connected peers
*/
fun `connectedCount`(): kotlin.UInt
/**
* Create an identity attestation
*/
fun `createAttestation`(`timestampMs`: kotlin.ULong): kotlin.ByteArray?
/**
* Decrypt data received over BLE (transport layer only)
*/
fun `decryptOnly`(`data`: kotlin.ByteArray): kotlin.ByteArray?
/**
* Get count of degraded peers (connected but poor signal)
*/
fun `degradedPeerCount`(): kotlin.UInt
/**
* Get the list of connected peer identifiers for relay.
*
* Used by the Kotlin layer to relay CannedMessages to other peers
* after deduplication check.
*/
fun `getConnectedPeerIdentifiers`(): List<kotlin.String>
/**
* Get list of connected peers
*/
fun `getConnectedPeers`(): List<PeatPeer>
/**
* Get connection state counts (direct peers)
*/
fun `getConnectionStateCounts`(): StateCountSummary
/**
* Get all degraded peers (connected but poor signal quality)
*/
fun `getDegradedPeers`(): List<PeerConnectionState>
/**
* Get full state counts including indirect peers
*/
fun `getFullStateCounts`(): FullStateCountSummary
/**
* Get indirect (multi-hop) peers
*/
fun `getIndirectPeers`(): List<IndirectPeer>
/**
* Get all lost peers (disconnected and timed out)
*/
fun `getLostPeers`(): List<PeerConnectionState>
/**
* Get callsign for a peer
*/
fun `getPeerCallsign`(`nodeId`: kotlin.UInt): kotlin.String?
/**
* Get connection state for a specific peer
*/
fun `getPeerConnectionState`(`nodeId`: kotlin.UInt): PeerConnectionState?
/**
* Get own public key
*/
fun `getPublicKey`(): kotlin.ByteArray?
/**
* Check if mesh has a cryptographic identity
*/
fun `hasIdentity`(): kotlin.Boolean
/**
* Check if ACK is currently active
*/
fun `isAckActive`(): kotlin.Boolean
/**
* Check if emergency is currently active
*/
fun `isEmergencyActive`(): kotlin.Boolean
/**
* Check if encryption is enabled
*/
fun `isEncryptionEnabled`(): kotlin.Boolean
/**
* Check if a peer's identity is known
*/
fun `isPeerIdentityKnown`(`nodeId`: kotlin.UInt): kotlin.Boolean
/**
* Check if a peer is known
*/
fun `isPeerKnown`(`nodeId`: kotlin.UInt): kotlin.Boolean
/**
* Check if relay is enabled
*/
fun `isRelayEnabled`(): kotlin.Boolean
/**
* Get count of known identities
*/
fun `knownIdentityCount`(): kotlin.UInt
/**
* Get count of lost peers (disconnected and timed out)
*/
fun `lostPeerCount`(): kotlin.UInt
/**
* Mark a CannedMessage as seen (for deduplication).
*
* Call this after receiving and processing a CannedMessage to prevent
* reprocessing the same message from other relay paths.
*/
fun `markCannedMessageSeen`(`sourceNode`: kotlin.UInt, `timestamp`: kotlin.ULong)
/**
* Check if mesh matches (for filtering BLE discovery)
*/
fun `matchesMesh`(`deviceMeshId`: kotlin.String?): kotlin.Boolean
/**
* Call when a BLE connection is established
*/
fun `onBleConnected`(`identifier`: kotlin.String, `nowMs`: kotlin.ULong)
/**
* Call when BLE data is received from a known peer
*/
fun `onBleDataReceived`(`identifier`: kotlin.String, `data`: kotlin.ByteArray, `nowMs`: kotlin.ULong): DataReceivedResult?
/**
* Call when BLE data is received from an unknown source (e.g., broadcast)
*/
fun `onBleDataReceivedAnonymous`(`identifier`: kotlin.String, `data`: kotlin.ByteArray, `nowMs`: kotlin.ULong): DataReceivedResult?
/**
* Call when a BLE connection is lost
*/
fun `onBleDisconnected`(`identifier`: kotlin.String, `reason`: DisconnectReason): kotlin.UInt?
/**
* Call when a BLE device is discovered
*/
fun `onBleDiscovered`(`identifier`: kotlin.String, `name`: kotlin.String?, `rssi`: kotlin.Byte, `meshId`: kotlin.String?, `nowMs`: kotlin.ULong): PeatPeer?
/**
* Call when a remote device connects to us (incoming peripheral connection)
*
* Unlike on_ble_connected(), this creates the peer if it doesn't exist yet.
* Use this when acting as a GATT server and a central connects to us.
*/
fun `onIncomingConnection`(`identifier`: kotlin.String, `nodeId`: kotlin.UInt, `nowMs`: kotlin.ULong): kotlin.Boolean
/**
* Get count of discovered peers
*/
fun `peerCount`(): kotlin.UInt
/**
* Get count of recently disconnected peers
*/
fun `recentlyDisconnectedCount`(`withinMs`: kotlin.ULong, `nowMs`: kotlin.ULong): kotlin.UInt
/**
* Send ACK
*/
fun `sendAck`(`timestampMs`: kotlin.ULong): kotlin.ByteArray
/**
* Send emergency alert
*/
fun `sendEmergency`(`timestampMs`: kotlin.ULong): kotlin.ByteArray
/**
* Set peripheral event
*/
fun `setPeripheralEvent`(`eventType`: EventType, `timestampMs`: kotlin.ULong)
/**
* Sign data with own identity
*/
fun `sign`(`message`: kotlin.ByteArray): kotlin.ByteArray?
/**
* Periodic tick - call every sync interval
*/
fun `tick`(`nowMs`: kotlin.ULong): kotlin.ByteArray?
/**
* Get total mesh count
*/
fun `totalCount`(): kotlin.UInt
/**
* Update own callsign
*/
fun `updateCallsign`(`callsign`: kotlin.String)
/**
* Update own heart rate
*/
fun `updateHeartRate`(`bpm`: kotlin.UByte)
/**
* Update own location
*/
fun `updateLocation`(`latitude`: kotlin.Float, `longitude`: kotlin.Float, `altitude`: kotlin.Float?)
/**
* Update all peripheral state at once (efficient for encrypted transmission)
*/
fun `updatePeripheralState`(`callsign`: kotlin.String, `batteryPercent`: kotlin.UByte, `heartRate`: kotlin.UByte?, `latitude`: kotlin.Float?, `longitude`: kotlin.Float?, `altitude`: kotlin.Float?, `eventType`: EventType?, `timestampMs`: kotlin.ULong)
/**
* Verify a peer's identity from attestation bytes
* Returns true if identity was registered or verified, false otherwise
*/
fun `verifyPeerIdentity`(`attestationBytes`: kotlin.ByteArray): kotlin.Boolean
/**
* Verify a peer's signature
*/
fun `verifyPeerSignature`(`nodeId`: kotlin.UInt, `message`: kotlin.ByteArray, `signature`: kotlin.ByteArray): kotlin.Boolean
companion object
}
open class PeatMesh: Disposable, AutoCloseable, PeatMeshInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
/**
* Create a basic PeatMesh
*/
constructor(`nodeId`: kotlin.UInt, `callsign`: kotlin.String, `meshId`: kotlin.String) :
this(UniffiWithHandle,
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_peatmesh_new(
FfiConverterUInt.lower(`nodeId`),FfiConverterString.lower(`callsign`),FfiConverterString.lower(`meshId`),_status)
}
)
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_peat_btle_fn_free_peatmesh(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_peat_btle_fn_clone_peatmesh(handle, status)
}
}
/**
* Get the number of stored app documents.
*/override fun `appDocumentCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_app_document_count(
it,
_status)
}
}
)
}
/**
* Broadcast arbitrary bytes over the mesh.
*
* Takes raw payload bytes, encrypts them (if encryption is enabled),
* and returns bytes ready to send to all connected peers.
*
* This is useful for sending extension data like CannedMessages from peat-lite.
*/override fun `broadcastBytes`(`payload`: kotlin.ByteArray): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_broadcast_bytes(
it,
FfiConverterByteArray.lower(`payload`),_status)
}
}
)
}
/**
* Build a delta document for a specific peer.
*
* This includes only operations that have changed since the last sync
* with this peer, including app-layer documents (CannedMessages, etc.).
* Returns None if there's nothing new to send.
*/override fun `buildDeltaDocumentForPeer`(`peerId`: kotlin.UInt, `nowMs`: kotlin.ULong): kotlin.ByteArray? {
return FfiConverterOptionalByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_build_delta_document_for_peer(
it,
FfiConverterUInt.lower(`peerId`),FfiConverterULong.lower(`nowMs`),_status)
}
}
)
}
/**
* Build the current document for transmission
*/override fun `buildDocument`(): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_build_document(
it,
_status)
}
}
)
}
/**
* Build a full delta document containing all current state.
*
* Unlike `build_delta_document_for_peer`, this includes all state
* regardless of what has been sent before. Use for broadcasts or
* new peer connections. Includes app-layer documents.
*/override fun `buildFullDeltaDocument`(`nowMs`: kotlin.ULong): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_build_full_delta_document(
it,
FfiConverterULong.lower(`nowMs`),_status)
}
}
)
}
/**
* Check if a CannedMessage has been seen recently.
*
* Uses document identity (source_node + timestamp) for deduplication.
* This prevents broadcast storms when relaying CannedMessages.
*
* Returns true if the message should be processed, false if it's a duplicate.
*/override fun `checkCannedMessage`(`sourceNode`: kotlin.UInt, `timestamp`: kotlin.ULong, `ttlMs`: kotlin.ULong): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_check_canned_message(
it,
FfiConverterUInt.lower(`sourceNode`),FfiConverterULong.lower(`timestamp`),FfiConverterULong.lower(`ttlMs`),_status)
}
}
)
}
/**
* Clear own location
*/override fun `clearLocation`()
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_clear_location(
it,
_status)
}
}
/**
* Clear peripheral event
*/override fun `clearPeripheralEvent`()
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_clear_peripheral_event(
it,
_status)
}
}
/**
* Get count of connected peers
*/override fun `connectedCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_connected_count(
it,
_status)
}
}
)
}
/**
* Create an identity attestation
*/override fun `createAttestation`(`timestampMs`: kotlin.ULong): kotlin.ByteArray? {
return FfiConverterOptionalByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_create_attestation(
it,
FfiConverterULong.lower(`timestampMs`),_status)
}
}
)
}
/**
* Decrypt data received over BLE (transport layer only)
*/override fun `decryptOnly`(`data`: kotlin.ByteArray): kotlin.ByteArray? {
return FfiConverterOptionalByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_decrypt_only(
it,
FfiConverterByteArray.lower(`data`),_status)
}
}
)
}
/**
* Get count of degraded peers (connected but poor signal)
*/override fun `degradedPeerCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_degraded_peer_count(
it,
_status)
}
}
)
}
/**
* Get the list of connected peer identifiers for relay.
*
* Used by the Kotlin layer to relay CannedMessages to other peers
* after deduplication check.
*/override fun `getConnectedPeerIdentifiers`(): List<kotlin.String> {
return FfiConverterSequenceString.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_connected_peer_identifiers(
it,
_status)
}
}
)
}
/**
* Get list of connected peers
*/override fun `getConnectedPeers`(): List<PeatPeer> {
return FfiConverterSequenceTypePeatPeer.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_connected_peers(
it,
_status)
}
}
)
}
/**
* Get connection state counts (direct peers)
*/override fun `getConnectionStateCounts`(): StateCountSummary {
return FfiConverterTypeStateCountSummary.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_connection_state_counts(
it,
_status)
}
}
)
}
/**
* Get all degraded peers (connected but poor signal quality)
*/override fun `getDegradedPeers`(): List<PeerConnectionState> {
return FfiConverterSequenceTypePeerConnectionState.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_degraded_peers(
it,
_status)
}
}
)
}
/**
* Get full state counts including indirect peers
*/override fun `getFullStateCounts`(): FullStateCountSummary {
return FfiConverterTypeFullStateCountSummary.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_full_state_counts(
it,
_status)
}
}
)
}
/**
* Get indirect (multi-hop) peers
*/override fun `getIndirectPeers`(): List<IndirectPeer> {
return FfiConverterSequenceTypeIndirectPeer.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_indirect_peers(
it,
_status)
}
}
)
}
/**
* Get all lost peers (disconnected and timed out)
*/override fun `getLostPeers`(): List<PeerConnectionState> {
return FfiConverterSequenceTypePeerConnectionState.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_lost_peers(
it,
_status)
}
}
)
}
/**
* Get callsign for a peer
*/override fun `getPeerCallsign`(`nodeId`: kotlin.UInt): kotlin.String? {
return FfiConverterOptionalString.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_peer_callsign(
it,
FfiConverterUInt.lower(`nodeId`),_status)
}
}
)
}
/**
* Get connection state for a specific peer
*/override fun `getPeerConnectionState`(`nodeId`: kotlin.UInt): PeerConnectionState? {
return FfiConverterOptionalTypePeerConnectionState.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_peer_connection_state(
it,
FfiConverterUInt.lower(`nodeId`),_status)
}
}
)
}
/**
* Get own public key
*/override fun `getPublicKey`(): kotlin.ByteArray? {
return FfiConverterOptionalByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_get_public_key(
it,
_status)
}
}
)
}
/**
* Check if mesh has a cryptographic identity
*/override fun `hasIdentity`(): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_has_identity(
it,
_status)
}
}
)
}
/**
* Check if ACK is currently active
*/override fun `isAckActive`(): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_is_ack_active(
it,
_status)
}
}
)
}
/**
* Check if emergency is currently active
*/override fun `isEmergencyActive`(): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_is_emergency_active(
it,
_status)
}
}
)
}
/**
* Check if encryption is enabled
*/override fun `isEncryptionEnabled`(): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_is_encryption_enabled(
it,
_status)
}
}
)
}
/**
* Check if a peer's identity is known
*/override fun `isPeerIdentityKnown`(`nodeId`: kotlin.UInt): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_is_peer_identity_known(
it,
FfiConverterUInt.lower(`nodeId`),_status)
}
}
)
}
/**
* Check if a peer is known
*/override fun `isPeerKnown`(`nodeId`: kotlin.UInt): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_is_peer_known(
it,
FfiConverterUInt.lower(`nodeId`),_status)
}
}
)
}
/**
* Check if relay is enabled
*/override fun `isRelayEnabled`(): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_is_relay_enabled(
it,
_status)
}
}
)
}
/**
* Get count of known identities
*/override fun `knownIdentityCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_known_identity_count(
it,
_status)
}
}
)
}
/**
* Get count of lost peers (disconnected and timed out)
*/override fun `lostPeerCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_lost_peer_count(
it,
_status)
}
}
)
}
/**
* Mark a CannedMessage as seen (for deduplication).
*
* Call this after receiving and processing a CannedMessage to prevent
* reprocessing the same message from other relay paths.
*/override fun `markCannedMessageSeen`(`sourceNode`: kotlin.UInt, `timestamp`: kotlin.ULong)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_mark_canned_message_seen(
it,
FfiConverterUInt.lower(`sourceNode`),FfiConverterULong.lower(`timestamp`),_status)
}
}
/**
* Check if mesh matches (for filtering BLE discovery)
*/override fun `matchesMesh`(`deviceMeshId`: kotlin.String?): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_matches_mesh(
it,
FfiConverterOptionalString.lower(`deviceMeshId`),_status)
}
}
)
}
/**
* Call when a BLE connection is established
*/override fun `onBleConnected`(`identifier`: kotlin.String, `nowMs`: kotlin.ULong)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_on_ble_connected(
it,
FfiConverterString.lower(`identifier`),FfiConverterULong.lower(`nowMs`),_status)
}
}
/**
* Call when BLE data is received from a known peer
*/override fun `onBleDataReceived`(`identifier`: kotlin.String, `data`: kotlin.ByteArray, `nowMs`: kotlin.ULong): DataReceivedResult? {
return FfiConverterOptionalTypeDataReceivedResult.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_on_ble_data_received(
it,
FfiConverterString.lower(`identifier`),FfiConverterByteArray.lower(`data`),FfiConverterULong.lower(`nowMs`),_status)
}
}
)
}
/**
* Call when BLE data is received from an unknown source (e.g., broadcast)
*/override fun `onBleDataReceivedAnonymous`(`identifier`: kotlin.String, `data`: kotlin.ByteArray, `nowMs`: kotlin.ULong): DataReceivedResult? {
return FfiConverterOptionalTypeDataReceivedResult.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_on_ble_data_received_anonymous(
it,
FfiConverterString.lower(`identifier`),FfiConverterByteArray.lower(`data`),FfiConverterULong.lower(`nowMs`),_status)
}
}
)
}
/**
* Call when a BLE connection is lost
*/override fun `onBleDisconnected`(`identifier`: kotlin.String, `reason`: DisconnectReason): kotlin.UInt? {
return FfiConverterOptionalUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_on_ble_disconnected(
it,
FfiConverterString.lower(`identifier`),FfiConverterTypeDisconnectReason.lower(`reason`),_status)
}
}
)
}
/**
* Call when a BLE device is discovered
*/override fun `onBleDiscovered`(`identifier`: kotlin.String, `name`: kotlin.String?, `rssi`: kotlin.Byte, `meshId`: kotlin.String?, `nowMs`: kotlin.ULong): PeatPeer? {
return FfiConverterOptionalTypePeatPeer.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_on_ble_discovered(
it,
FfiConverterString.lower(`identifier`),FfiConverterOptionalString.lower(`name`),FfiConverterByte.lower(`rssi`),FfiConverterOptionalString.lower(`meshId`),FfiConverterULong.lower(`nowMs`),_status)
}
}
)
}
/**
* Call when a remote device connects to us (incoming peripheral connection)
*
* Unlike on_ble_connected(), this creates the peer if it doesn't exist yet.
* Use this when acting as a GATT server and a central connects to us.
*/override fun `onIncomingConnection`(`identifier`: kotlin.String, `nodeId`: kotlin.UInt, `nowMs`: kotlin.ULong): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_on_incoming_connection(
it,
FfiConverterString.lower(`identifier`),FfiConverterUInt.lower(`nodeId`),FfiConverterULong.lower(`nowMs`),_status)
}
}
)
}
/**
* Get count of discovered peers
*/override fun `peerCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_peer_count(
it,
_status)
}
}
)
}
/**
* Get count of recently disconnected peers
*/override fun `recentlyDisconnectedCount`(`withinMs`: kotlin.ULong, `nowMs`: kotlin.ULong): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_recently_disconnected_count(
it,
FfiConverterULong.lower(`withinMs`),FfiConverterULong.lower(`nowMs`),_status)
}
}
)
}
/**
* Send ACK
*/override fun `sendAck`(`timestampMs`: kotlin.ULong): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_send_ack(
it,
FfiConverterULong.lower(`timestampMs`),_status)
}
}
)
}
/**
* Send emergency alert
*/override fun `sendEmergency`(`timestampMs`: kotlin.ULong): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_send_emergency(
it,
FfiConverterULong.lower(`timestampMs`),_status)
}
}
)
}
/**
* Set peripheral event
*/override fun `setPeripheralEvent`(`eventType`: EventType, `timestampMs`: kotlin.ULong)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_set_peripheral_event(
it,
FfiConverterTypeEventType.lower(`eventType`),FfiConverterULong.lower(`timestampMs`),_status)
}
}
/**
* Sign data with own identity
*/override fun `sign`(`message`: kotlin.ByteArray): kotlin.ByteArray? {
return FfiConverterOptionalByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_sign(
it,
FfiConverterByteArray.lower(`message`),_status)
}
}
)
}
/**
* Periodic tick - call every sync interval
*/override fun `tick`(`nowMs`: kotlin.ULong): kotlin.ByteArray? {
return FfiConverterOptionalByteArray.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_tick(
it,
FfiConverterULong.lower(`nowMs`),_status)
}
}
)
}
/**
* Get total mesh count
*/override fun `totalCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_total_count(
it,
_status)
}
}
)
}
/**
* Update own callsign
*/override fun `updateCallsign`(`callsign`: kotlin.String)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_update_callsign(
it,
FfiConverterString.lower(`callsign`),_status)
}
}
/**
* Update own heart rate
*/override fun `updateHeartRate`(`bpm`: kotlin.UByte)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_update_heart_rate(
it,
FfiConverterUByte.lower(`bpm`),_status)
}
}
/**
* Update own location
*/override fun `updateLocation`(`latitude`: kotlin.Float, `longitude`: kotlin.Float, `altitude`: kotlin.Float?)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_update_location(
it,
FfiConverterFloat.lower(`latitude`),FfiConverterFloat.lower(`longitude`),FfiConverterOptionalFloat.lower(`altitude`),_status)
}
}
/**
* Update all peripheral state at once (efficient for encrypted transmission)
*/override fun `updatePeripheralState`(`callsign`: kotlin.String, `batteryPercent`: kotlin.UByte, `heartRate`: kotlin.UByte?, `latitude`: kotlin.Float?, `longitude`: kotlin.Float?, `altitude`: kotlin.Float?, `eventType`: EventType?, `timestampMs`: kotlin.ULong)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_update_peripheral_state(
it,
FfiConverterString.lower(`callsign`),FfiConverterUByte.lower(`batteryPercent`),FfiConverterOptionalUByte.lower(`heartRate`),FfiConverterOptionalFloat.lower(`latitude`),FfiConverterOptionalFloat.lower(`longitude`),FfiConverterOptionalFloat.lower(`altitude`),FfiConverterOptionalTypeEventType.lower(`eventType`),FfiConverterULong.lower(`timestampMs`),_status)
}
}
/**
* Verify a peer's identity from attestation bytes
* Returns true if identity was registered or verified, false otherwise
*/override fun `verifyPeerIdentity`(`attestationBytes`: kotlin.ByteArray): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_verify_peer_identity(
it,
FfiConverterByteArray.lower(`attestationBytes`),_status)
}
}
)
}
/**
* Verify a peer's signature
*/override fun `verifyPeerSignature`(`nodeId`: kotlin.UInt, `message`: kotlin.ByteArray, `signature`: kotlin.ByteArray): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peatmesh_verify_peer_signature(
it,
FfiConverterUInt.lower(`nodeId`),FfiConverterByteArray.lower(`message`),FfiConverterByteArray.lower(`signature`),_status)
}
}
)
}
companion object {
/**
* Create a PeatMesh from genesis (recommended for production)
*/ fun `newFromGenesis`(`callsign`: kotlin.String, `identity`: DeviceIdentity, `genesis`: MeshGenesis): PeatMesh {
return FfiConverterTypePeatMesh.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_peatmesh_new_from_genesis(
FfiConverterString.lower(`callsign`),FfiConverterTypeDeviceIdentity.lower(`identity`),FfiConverterTypeMeshGenesis.lower(`genesis`),_status)
}
)
}
/**
* Create a PeatMesh with peripheral type
*/ fun `newWithPeripheral`(`nodeId`: kotlin.UInt, `callsign`: kotlin.String, `meshId`: kotlin.String, `peripheralType`: PeripheralType): PeatMesh {
return FfiConverterTypePeatMesh.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_peatmesh_new_with_peripheral(
FfiConverterUInt.lower(`nodeId`),FfiConverterString.lower(`callsign`),FfiConverterString.lower(`meshId`),FfiConverterTypePeripheralType.lower(`peripheralType`),_status)
}
)
}
}
}
/**
* @suppress
*/
public object FfiConverterTypePeatMesh: FfiConverter<PeatMesh, Long> {
override fun lower(value: PeatMesh): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): PeatMesh {
return PeatMesh(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): PeatMesh {
return lift(buf.getLong())
}
override fun allocationSize(value: PeatMesh) = 8UL
override fun write(value: PeatMesh, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Manager for peer lifetime and stale peer cleanup
*/
public interface PeerLifetimeManagerInterface {
/**
* Get the cleanup interval from configuration in milliseconds
*/
fun `cleanupIntervalMs`(): kotlin.ULong
/**
* Remove all stale peers and return their info
*/
fun `cleanupStalePeers`(): List<StalePeerInfo>
/**
* Clear all tracked peers
*/
fun `clear`()
/**
* Get detailed info about a specific peer
*/
fun `getPeerInfo`(`address`: kotlin.String): PeerInfo?
/**
* Get just the addresses of stale peers
*/
fun `getStalePeerAddresses`(): List<kotlin.String>
/**
* Get the list of stale peers that should be removed
*/
fun `getStalePeers`(): List<StalePeerInfo>
/**
* Check if a peer is connected
*/
fun `isConnected`(`address`: kotlin.String): kotlin.Boolean
/**
* Check if a peer is being tracked
*/
fun `isTracked`(`address`: kotlin.String): kotlin.Boolean
/**
* Record activity for a peer
*/
fun `onPeerActivity`(`address`: kotlin.String, `connected`: kotlin.Boolean)
/**
* Record that a peer has disconnected
*/
fun `onPeerDisconnected`(`address`: kotlin.String)
/**
* Remove a peer from tracking
*/
fun `removePeer`(`address`: kotlin.String): kotlin.Boolean
/**
* Get statistics about tracked peers
*/
fun `stats`(): PeerLifetimeStats
/**
* Get the number of tracked peers
*/
fun `trackedCount`(): kotlin.UInt
companion object
}
/**
* Manager for peer lifetime and stale peer cleanup
*/
open class PeerLifetimeManager: Disposable, AutoCloseable, PeerLifetimeManagerInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
/**
* Create a new peer lifetime manager with the given configuration
*/
constructor(`config`: PeerLifetimeConfig) :
this(UniffiWithHandle,
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_peerlifetimemanager_new(
FfiConverterTypePeerLifetimeConfig.lower(`config`),_status)
}
)
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_peat_btle_fn_free_peerlifetimemanager(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_peat_btle_fn_clone_peerlifetimemanager(handle, status)
}
}
/**
* Get the cleanup interval from configuration in milliseconds
*/override fun `cleanupIntervalMs`(): kotlin.ULong {
return FfiConverterULong.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_cleanup_interval_ms(
it,
_status)
}
}
)
}
/**
* Remove all stale peers and return their info
*/override fun `cleanupStalePeers`(): List<StalePeerInfo> {
return FfiConverterSequenceTypeStalePeerInfo.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_cleanup_stale_peers(
it,
_status)
}
}
)
}
/**
* Clear all tracked peers
*/override fun `clear`()
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_clear(
it,
_status)
}
}
/**
* Get detailed info about a specific peer
*/override fun `getPeerInfo`(`address`: kotlin.String): PeerInfo? {
return FfiConverterOptionalTypePeerInfo.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_get_peer_info(
it,
FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Get just the addresses of stale peers
*/override fun `getStalePeerAddresses`(): List<kotlin.String> {
return FfiConverterSequenceString.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_get_stale_peer_addresses(
it,
_status)
}
}
)
}
/**
* Get the list of stale peers that should be removed
*/override fun `getStalePeers`(): List<StalePeerInfo> {
return FfiConverterSequenceTypeStalePeerInfo.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_get_stale_peers(
it,
_status)
}
}
)
}
/**
* Check if a peer is connected
*/override fun `isConnected`(`address`: kotlin.String): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_is_connected(
it,
FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Check if a peer is being tracked
*/override fun `isTracked`(`address`: kotlin.String): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_is_tracked(
it,
FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Record activity for a peer
*/override fun `onPeerActivity`(`address`: kotlin.String, `connected`: kotlin.Boolean)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_on_peer_activity(
it,
FfiConverterString.lower(`address`),FfiConverterBoolean.lower(`connected`),_status)
}
}
/**
* Record that a peer has disconnected
*/override fun `onPeerDisconnected`(`address`: kotlin.String)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_on_peer_disconnected(
it,
FfiConverterString.lower(`address`),_status)
}
}
/**
* Remove a peer from tracking
*/override fun `removePeer`(`address`: kotlin.String): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_remove_peer(
it,
FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Get statistics about tracked peers
*/override fun `stats`(): PeerLifetimeStats {
return FfiConverterTypePeerLifetimeStats.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_stats(
it,
_status)
}
}
)
}
/**
* Get the number of tracked peers
*/override fun `trackedCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_peerlifetimemanager_tracked_count(
it,
_status)
}
}
)
}
companion object {
/**
* Create a manager with default configuration
*/ fun `withDefaults`(): PeerLifetimeManager {
return FfiConverterTypePeerLifetimeManager.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_peerlifetimemanager_with_defaults(
_status)
}
)
}
}
}
/**
* @suppress
*/
public object FfiConverterTypePeerLifetimeManager: FfiConverter<PeerLifetimeManager, Long> {
override fun lower(value: PeerLifetimeManager): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): PeerLifetimeManager {
return PeerLifetimeManager(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): PeerLifetimeManager {
return lift(buf.getLong())
}
override fun allocationSize(value: PeerLifetimeManager) = 8UL
override fun write(value: PeerLifetimeManager, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Manager for auto-reconnection with exponential backoff
*/
public interface ReconnectionManagerInterface {
/**
* Get the check interval from configuration in milliseconds
*/
fun `checkIntervalMs`(): kotlin.ULong
/**
* Clear all reconnection tracking
*/
fun `clear`()
/**
* Get statistics for a peer
*/
fun `getPeerStats`(`address`: kotlin.String): PeerReconnectionStats?
/**
* Get all peers that are ready for a reconnection attempt
*/
fun `getPeersToReconnect`(): List<kotlin.String>
/**
* Get the reconnection status for a peer
*/
fun `getStatus`(`address`: kotlin.String): ReconnectionStatus
/**
* Check if a peer is being tracked for reconnection
*/
fun `isTracked`(`address`: kotlin.String): kotlin.Boolean
/**
* Called when a connection succeeds
*/
fun `onConnectionSuccess`(`address`: kotlin.String)
/**
* Record a reconnection attempt for a peer
*/
fun `recordAttempt`(`address`: kotlin.String)
/**
* Stop tracking a peer
*/
fun `stopTracking`(`address`: kotlin.String)
/**
* Track a peer for reconnection after disconnection
*/
fun `trackDisconnection`(`address`: kotlin.String)
/**
* Get the number of peers being tracked
*/
fun `trackedCount`(): kotlin.UInt
companion object
}
/**
* Manager for auto-reconnection with exponential backoff
*/
open class ReconnectionManager: Disposable, AutoCloseable, ReconnectionManagerInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
/**
* Create a new reconnection manager with the given configuration
*/
constructor(`config`: ReconnectionConfig) :
this(UniffiWithHandle,
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_reconnectionmanager_new(
FfiConverterTypeReconnectionConfig.lower(`config`),_status)
}
)
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_peat_btle_fn_free_reconnectionmanager(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_peat_btle_fn_clone_reconnectionmanager(handle, status)
}
}
/**
* Get the check interval from configuration in milliseconds
*/override fun `checkIntervalMs`(): kotlin.ULong {
return FfiConverterULong.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_check_interval_ms(
it,
_status)
}
}
)
}
/**
* Clear all reconnection tracking
*/override fun `clear`()
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_clear(
it,
_status)
}
}
/**
* Get statistics for a peer
*/override fun `getPeerStats`(`address`: kotlin.String): PeerReconnectionStats? {
return FfiConverterOptionalTypePeerReconnectionStats.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_get_peer_stats(
it,
FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Get all peers that are ready for a reconnection attempt
*/override fun `getPeersToReconnect`(): List<kotlin.String> {
return FfiConverterSequenceString.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_get_peers_to_reconnect(
it,
_status)
}
}
)
}
/**
* Get the reconnection status for a peer
*/override fun `getStatus`(`address`: kotlin.String): ReconnectionStatus {
return FfiConverterTypeReconnectionStatus.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_get_status(
it,
FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Check if a peer is being tracked for reconnection
*/override fun `isTracked`(`address`: kotlin.String): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_is_tracked(
it,
FfiConverterString.lower(`address`),_status)
}
}
)
}
/**
* Called when a connection succeeds
*/override fun `onConnectionSuccess`(`address`: kotlin.String)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_on_connection_success(
it,
FfiConverterString.lower(`address`),_status)
}
}
/**
* Record a reconnection attempt for a peer
*/override fun `recordAttempt`(`address`: kotlin.String)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_record_attempt(
it,
FfiConverterString.lower(`address`),_status)
}
}
/**
* Stop tracking a peer
*/override fun `stopTracking`(`address`: kotlin.String)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_stop_tracking(
it,
FfiConverterString.lower(`address`),_status)
}
}
/**
* Track a peer for reconnection after disconnection
*/override fun `trackDisconnection`(`address`: kotlin.String)
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_track_disconnection(
it,
FfiConverterString.lower(`address`),_status)
}
}
/**
* Get the number of peers being tracked
*/override fun `trackedCount`(): kotlin.UInt {
return FfiConverterUInt.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_method_reconnectionmanager_tracked_count(
it,
_status)
}
}
)
}
companion object {
/**
* Create a manager with default configuration
*/ fun `withDefaults`(): ReconnectionManager {
return FfiConverterTypeReconnectionManager.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_constructor_reconnectionmanager_with_defaults(
_status)
}
)
}
}
}
/**
* @suppress
*/
public object FfiConverterTypeReconnectionManager: FfiConverter<ReconnectionManager, Long> {
override fun lower(value: ReconnectionManager): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): ReconnectionManager {
return ReconnectionManager(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): ReconnectionManager {
return lift(buf.getLong())
}
override fun allocationSize(value: ReconnectionManager) = 8UL
override fun write(value: ReconnectionManager, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
/**
* Statistics about address rotation handling
*/
data class AddressRotationStats (
/**
* Number of devices tracked by name
*/
var `devicesWithNames`: kotlin.UInt
,
/**
* Total number of devices tracked
*/
var `totalDevices`: kotlin.UInt
,
/**
* Number of address mappings
*/
var `addressMappings`: kotlin.UInt
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeAddressRotationStats: FfiConverterRustBuffer<AddressRotationStats> {
override fun read(buf: ByteBuffer): AddressRotationStats {
return AddressRotationStats(
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
)
}
override fun allocationSize(value: AddressRotationStats) = (
FfiConverterUInt.allocationSize(value.`devicesWithNames`) +
FfiConverterUInt.allocationSize(value.`totalDevices`) +
FfiConverterUInt.allocationSize(value.`addressMappings`)
)
override fun write(value: AddressRotationStats, buf: ByteBuffer) {
FfiConverterUInt.write(value.`devicesWithNames`, buf)
FfiConverterUInt.write(value.`totalDevices`, buf)
FfiConverterUInt.write(value.`addressMappings`, buf)
}
}
data class DataReceivedResult (
var `sourceNode`: kotlin.UInt
,
var `isEmergency`: kotlin.Boolean
,
var `isAck`: kotlin.Boolean
,
var `counterChanged`: kotlin.Boolean
,
var `emergencyChanged`: kotlin.Boolean
,
var `totalCount`: kotlin.ULong
,
var `eventTimestamp`: kotlin.ULong
,
var `relayData`: kotlin.ByteArray?
,
var `originNode`: kotlin.UInt?
,
var `hopCount`: kotlin.UByte
,
var `callsign`: kotlin.String?
,
var `batteryPercent`: kotlin.UByte?
,
var `heartRate`: kotlin.UByte?
,
var `eventType`: EventType?
,
var `latitude`: kotlin.Float?
,
var `longitude`: kotlin.Float?
,
var `altitude`: kotlin.Float?
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeDataReceivedResult: FfiConverterRustBuffer<DataReceivedResult> {
override fun read(buf: ByteBuffer): DataReceivedResult {
return DataReceivedResult(
FfiConverterUInt.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
FfiConverterOptionalByteArray.read(buf),
FfiConverterOptionalUInt.read(buf),
FfiConverterUByte.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalUByte.read(buf),
FfiConverterOptionalUByte.read(buf),
FfiConverterOptionalTypeEventType.read(buf),
FfiConverterOptionalFloat.read(buf),
FfiConverterOptionalFloat.read(buf),
FfiConverterOptionalFloat.read(buf),
)
}
override fun allocationSize(value: DataReceivedResult) = (
FfiConverterUInt.allocationSize(value.`sourceNode`) +
FfiConverterBoolean.allocationSize(value.`isEmergency`) +
FfiConverterBoolean.allocationSize(value.`isAck`) +
FfiConverterBoolean.allocationSize(value.`counterChanged`) +
FfiConverterBoolean.allocationSize(value.`emergencyChanged`) +
FfiConverterULong.allocationSize(value.`totalCount`) +
FfiConverterULong.allocationSize(value.`eventTimestamp`) +
FfiConverterOptionalByteArray.allocationSize(value.`relayData`) +
FfiConverterOptionalUInt.allocationSize(value.`originNode`) +
FfiConverterUByte.allocationSize(value.`hopCount`) +
FfiConverterOptionalString.allocationSize(value.`callsign`) +
FfiConverterOptionalUByte.allocationSize(value.`batteryPercent`) +
FfiConverterOptionalUByte.allocationSize(value.`heartRate`) +
FfiConverterOptionalTypeEventType.allocationSize(value.`eventType`) +
FfiConverterOptionalFloat.allocationSize(value.`latitude`) +
FfiConverterOptionalFloat.allocationSize(value.`longitude`) +
FfiConverterOptionalFloat.allocationSize(value.`altitude`)
)
override fun write(value: DataReceivedResult, buf: ByteBuffer) {
FfiConverterUInt.write(value.`sourceNode`, buf)
FfiConverterBoolean.write(value.`isEmergency`, buf)
FfiConverterBoolean.write(value.`isAck`, buf)
FfiConverterBoolean.write(value.`counterChanged`, buf)
FfiConverterBoolean.write(value.`emergencyChanged`, buf)
FfiConverterULong.write(value.`totalCount`, buf)
FfiConverterULong.write(value.`eventTimestamp`, buf)
FfiConverterOptionalByteArray.write(value.`relayData`, buf)
FfiConverterOptionalUInt.write(value.`originNode`, buf)
FfiConverterUByte.write(value.`hopCount`, buf)
FfiConverterOptionalString.write(value.`callsign`, buf)
FfiConverterOptionalUByte.write(value.`batteryPercent`, buf)
FfiConverterOptionalUByte.write(value.`heartRate`, buf)
FfiConverterOptionalTypeEventType.write(value.`eventType`, buf)
FfiConverterOptionalFloat.write(value.`latitude`, buf)
FfiConverterOptionalFloat.write(value.`longitude`, buf)
FfiConverterOptionalFloat.write(value.`altitude`, buf)
}
}
/**
* Result of looking up a device by name
*/
data class DeviceLookupResult (
/**
* The node ID for this device
*/
var `nodeId`: kotlin.UInt
,
/**
* The current known address
*/
var `currentAddress`: kotlin.String
,
/**
* Whether the address has changed
*/
var `addressChanged`: kotlin.Boolean
,
/**
* The previous address (if changed)
*/
var `previousAddress`: kotlin.String?
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeDeviceLookupResult: FfiConverterRustBuffer<DeviceLookupResult> {
override fun read(buf: ByteBuffer): DeviceLookupResult {
return DeviceLookupResult(
FfiConverterUInt.read(buf),
FfiConverterString.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterOptionalString.read(buf),
)
}
override fun allocationSize(value: DeviceLookupResult) = (
FfiConverterUInt.allocationSize(value.`nodeId`) +
FfiConverterString.allocationSize(value.`currentAddress`) +
FfiConverterBoolean.allocationSize(value.`addressChanged`) +
FfiConverterOptionalString.allocationSize(value.`previousAddress`)
)
override fun write(value: DeviceLookupResult, buf: ByteBuffer) {
FfiConverterUInt.write(value.`nodeId`, buf)
FfiConverterString.write(value.`currentAddress`, buf)
FfiConverterBoolean.write(value.`addressChanged`, buf)
FfiConverterOptionalString.write(value.`previousAddress`, buf)
}
}
data class FullStateCountSummary (
var `direct`: StateCountSummary
,
var `oneHop`: kotlin.UInt
,
var `twoHop`: kotlin.UInt
,
var `threeHop`: kotlin.UInt
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeFullStateCountSummary: FfiConverterRustBuffer<FullStateCountSummary> {
override fun read(buf: ByteBuffer): FullStateCountSummary {
return FullStateCountSummary(
FfiConverterTypeStateCountSummary.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
)
}
override fun allocationSize(value: FullStateCountSummary) = (
FfiConverterTypeStateCountSummary.allocationSize(value.`direct`) +
FfiConverterUInt.allocationSize(value.`oneHop`) +
FfiConverterUInt.allocationSize(value.`twoHop`) +
FfiConverterUInt.allocationSize(value.`threeHop`)
)
override fun write(value: FullStateCountSummary, buf: ByteBuffer) {
FfiConverterTypeStateCountSummary.write(value.`direct`, buf)
FfiConverterUInt.write(value.`oneHop`, buf)
FfiConverterUInt.write(value.`twoHop`, buf)
FfiConverterUInt.write(value.`threeHop`, buf)
}
}
data class IndirectPeer (
var `nodeId`: kotlin.UInt
,
var `minHops`: kotlin.UByte
,
var `viaPeers`: List<ViaPeerRoute>
,
var `discoveredAt`: kotlin.ULong
,
var `lastSeenMs`: kotlin.ULong
,
var `messagesReceived`: kotlin.UInt
,
var `callsign`: kotlin.String?
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeIndirectPeer: FfiConverterRustBuffer<IndirectPeer> {
override fun read(buf: ByteBuffer): IndirectPeer {
return IndirectPeer(
FfiConverterUInt.read(buf),
FfiConverterUByte.read(buf),
FfiConverterSequenceTypeViaPeerRoute.read(buf),
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
FfiConverterUInt.read(buf),
FfiConverterOptionalString.read(buf),
)
}
override fun allocationSize(value: IndirectPeer) = (
FfiConverterUInt.allocationSize(value.`nodeId`) +
FfiConverterUByte.allocationSize(value.`minHops`) +
FfiConverterSequenceTypeViaPeerRoute.allocationSize(value.`viaPeers`) +
FfiConverterULong.allocationSize(value.`discoveredAt`) +
FfiConverterULong.allocationSize(value.`lastSeenMs`) +
FfiConverterUInt.allocationSize(value.`messagesReceived`) +
FfiConverterOptionalString.allocationSize(value.`callsign`)
)
override fun write(value: IndirectPeer, buf: ByteBuffer) {
FfiConverterUInt.write(value.`nodeId`, buf)
FfiConverterUByte.write(value.`minHops`, buf)
FfiConverterSequenceTypeViaPeerRoute.write(value.`viaPeers`, buf)
FfiConverterULong.write(value.`discoveredAt`, buf)
FfiConverterULong.write(value.`lastSeenMs`, buf)
FfiConverterUInt.write(value.`messagesReceived`, buf)
FfiConverterOptionalString.write(value.`callsign`, buf)
}
}
data class PeatPeer (
var `nodeId`: kotlin.UInt
,
var `identifier`: kotlin.String
,
var `name`: kotlin.String?
,
var `meshId`: kotlin.String?
,
var `rssi`: kotlin.Byte
,
var `isConnected`: kotlin.Boolean
,
var `lastSeenMs`: kotlin.ULong
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePeatPeer: FfiConverterRustBuffer<PeatPeer> {
override fun read(buf: ByteBuffer): PeatPeer {
return PeatPeer(
FfiConverterUInt.read(buf),
FfiConverterString.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterByte.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterULong.read(buf),
)
}
override fun allocationSize(value: PeatPeer) = (
FfiConverterUInt.allocationSize(value.`nodeId`) +
FfiConverterString.allocationSize(value.`identifier`) +
FfiConverterOptionalString.allocationSize(value.`name`) +
FfiConverterOptionalString.allocationSize(value.`meshId`) +
FfiConverterByte.allocationSize(value.`rssi`) +
FfiConverterBoolean.allocationSize(value.`isConnected`) +
FfiConverterULong.allocationSize(value.`lastSeenMs`)
)
override fun write(value: PeatPeer, buf: ByteBuffer) {
FfiConverterUInt.write(value.`nodeId`, buf)
FfiConverterString.write(value.`identifier`, buf)
FfiConverterOptionalString.write(value.`name`, buf)
FfiConverterOptionalString.write(value.`meshId`, buf)
FfiConverterByte.write(value.`rssi`, buf)
FfiConverterBoolean.write(value.`isConnected`, buf)
FfiConverterULong.write(value.`lastSeenMs`, buf)
}
}
data class PeerConnectionState (
var `nodeId`: kotlin.UInt
,
var `identifier`: kotlin.String
,
var `state`: ConnectionState
,
var `discoveredAt`: kotlin.ULong
,
var `connectedAt`: kotlin.ULong?
,
var `disconnectedAt`: kotlin.ULong?
,
var `disconnectReason`: DisconnectReason?
,
var `lastRssi`: kotlin.Byte?
,
var `connectionCount`: kotlin.UInt
,
var `documentsSynced`: kotlin.UInt
,
var `bytesReceived`: kotlin.ULong
,
var `bytesSent`: kotlin.ULong
,
var `lastSeenMs`: kotlin.ULong
,
var `name`: kotlin.String?
,
var `meshId`: kotlin.String?
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePeerConnectionState: FfiConverterRustBuffer<PeerConnectionState> {
override fun read(buf: ByteBuffer): PeerConnectionState {
return PeerConnectionState(
FfiConverterUInt.read(buf),
FfiConverterString.read(buf),
FfiConverterTypeConnectionState.read(buf),
FfiConverterULong.read(buf),
FfiConverterOptionalULong.read(buf),
FfiConverterOptionalULong.read(buf),
FfiConverterOptionalTypeDisconnectReason.read(buf),
FfiConverterOptionalByte.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
)
}
override fun allocationSize(value: PeerConnectionState) = (
FfiConverterUInt.allocationSize(value.`nodeId`) +
FfiConverterString.allocationSize(value.`identifier`) +
FfiConverterTypeConnectionState.allocationSize(value.`state`) +
FfiConverterULong.allocationSize(value.`discoveredAt`) +
FfiConverterOptionalULong.allocationSize(value.`connectedAt`) +
FfiConverterOptionalULong.allocationSize(value.`disconnectedAt`) +
FfiConverterOptionalTypeDisconnectReason.allocationSize(value.`disconnectReason`) +
FfiConverterOptionalByte.allocationSize(value.`lastRssi`) +
FfiConverterUInt.allocationSize(value.`connectionCount`) +
FfiConverterUInt.allocationSize(value.`documentsSynced`) +
FfiConverterULong.allocationSize(value.`bytesReceived`) +
FfiConverterULong.allocationSize(value.`bytesSent`) +
FfiConverterULong.allocationSize(value.`lastSeenMs`) +
FfiConverterOptionalString.allocationSize(value.`name`) +
FfiConverterOptionalString.allocationSize(value.`meshId`)
)
override fun write(value: PeerConnectionState, buf: ByteBuffer) {
FfiConverterUInt.write(value.`nodeId`, buf)
FfiConverterString.write(value.`identifier`, buf)
FfiConverterTypeConnectionState.write(value.`state`, buf)
FfiConverterULong.write(value.`discoveredAt`, buf)
FfiConverterOptionalULong.write(value.`connectedAt`, buf)
FfiConverterOptionalULong.write(value.`disconnectedAt`, buf)
FfiConverterOptionalTypeDisconnectReason.write(value.`disconnectReason`, buf)
FfiConverterOptionalByte.write(value.`lastRssi`, buf)
FfiConverterUInt.write(value.`connectionCount`, buf)
FfiConverterUInt.write(value.`documentsSynced`, buf)
FfiConverterULong.write(value.`bytesReceived`, buf)
FfiConverterULong.write(value.`bytesSent`, buf)
FfiConverterULong.write(value.`lastSeenMs`, buf)
FfiConverterOptionalString.write(value.`name`, buf)
FfiConverterOptionalString.write(value.`meshId`, buf)
}
}
/**
* Detailed information about a peer
*/
data class PeerInfo (
/**
* Whether the peer is currently connected
*/
var `connected`: kotlin.Boolean
,
/**
* Time since last activity in milliseconds
*/
var `timeSinceLastSeenMs`: kotlin.ULong
,
/**
* Time since first discovery in milliseconds
*/
var `timeSinceFirstSeenMs`: kotlin.ULong
,
/**
* Time since disconnect in milliseconds (if disconnected)
*/
var `timeSinceDisconnectMs`: kotlin.ULong?
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePeerInfo: FfiConverterRustBuffer<PeerInfo> {
override fun read(buf: ByteBuffer): PeerInfo {
return PeerInfo(
FfiConverterBoolean.read(buf),
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
FfiConverterOptionalULong.read(buf),
)
}
override fun allocationSize(value: PeerInfo) = (
FfiConverterBoolean.allocationSize(value.`connected`) +
FfiConverterULong.allocationSize(value.`timeSinceLastSeenMs`) +
FfiConverterULong.allocationSize(value.`timeSinceFirstSeenMs`) +
FfiConverterOptionalULong.allocationSize(value.`timeSinceDisconnectMs`)
)
override fun write(value: PeerInfo, buf: ByteBuffer) {
FfiConverterBoolean.write(value.`connected`, buf)
FfiConverterULong.write(value.`timeSinceLastSeenMs`, buf)
FfiConverterULong.write(value.`timeSinceFirstSeenMs`, buf)
FfiConverterOptionalULong.write(value.`timeSinceDisconnectMs`, buf)
}
}
/**
* Configuration for peer lifetime management
*/
data class PeerLifetimeConfig (
/**
* Timeout for disconnected peers in milliseconds
*/
var `disconnectedTimeoutMs`: kotlin.ULong
,
/**
* Timeout for connected peers in milliseconds
*/
var `connectedTimeoutMs`: kotlin.ULong
,
/**
* Interval for cleanup checks in milliseconds
*/
var `cleanupIntervalMs`: kotlin.ULong
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePeerLifetimeConfig: FfiConverterRustBuffer<PeerLifetimeConfig> {
override fun read(buf: ByteBuffer): PeerLifetimeConfig {
return PeerLifetimeConfig(
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
)
}
override fun allocationSize(value: PeerLifetimeConfig) = (
FfiConverterULong.allocationSize(value.`disconnectedTimeoutMs`) +
FfiConverterULong.allocationSize(value.`connectedTimeoutMs`) +
FfiConverterULong.allocationSize(value.`cleanupIntervalMs`)
)
override fun write(value: PeerLifetimeConfig, buf: ByteBuffer) {
FfiConverterULong.write(value.`disconnectedTimeoutMs`, buf)
FfiConverterULong.write(value.`connectedTimeoutMs`, buf)
FfiConverterULong.write(value.`cleanupIntervalMs`, buf)
}
}
/**
* Statistics about tracked peers
*/
data class PeerLifetimeStats (
/**
* Total number of tracked peers
*/
var `totalTracked`: kotlin.UInt
,
/**
* Number of connected peers
*/
var `connected`: kotlin.UInt
,
/**
* Number of disconnected peers
*/
var `disconnected`: kotlin.UInt
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePeerLifetimeStats: FfiConverterRustBuffer<PeerLifetimeStats> {
override fun read(buf: ByteBuffer): PeerLifetimeStats {
return PeerLifetimeStats(
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
)
}
override fun allocationSize(value: PeerLifetimeStats) = (
FfiConverterUInt.allocationSize(value.`totalTracked`) +
FfiConverterUInt.allocationSize(value.`connected`) +
FfiConverterUInt.allocationSize(value.`disconnected`)
)
override fun write(value: PeerLifetimeStats, buf: ByteBuffer) {
FfiConverterUInt.write(value.`totalTracked`, buf)
FfiConverterUInt.write(value.`connected`, buf)
FfiConverterUInt.write(value.`disconnected`, buf)
}
}
/**
* Statistics for a peer's reconnection state
*/
data class PeerReconnectionStats (
/**
* Number of attempts made
*/
var `attempts`: kotlin.UInt
,
/**
* Maximum allowed attempts
*/
var `maxAttempts`: kotlin.UInt
,
/**
* How long since the peer disconnected in milliseconds
*/
var `disconnectedDurationMs`: kotlin.ULong
,
/**
* Time until next reconnection attempt in milliseconds (0 if ready, u64::MAX if exhausted)
*/
var `nextAttemptDelayMs`: kotlin.ULong
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePeerReconnectionStats: FfiConverterRustBuffer<PeerReconnectionStats> {
override fun read(buf: ByteBuffer): PeerReconnectionStats {
return PeerReconnectionStats(
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
)
}
override fun allocationSize(value: PeerReconnectionStats) = (
FfiConverterUInt.allocationSize(value.`attempts`) +
FfiConverterUInt.allocationSize(value.`maxAttempts`) +
FfiConverterULong.allocationSize(value.`disconnectedDurationMs`) +
FfiConverterULong.allocationSize(value.`nextAttemptDelayMs`)
)
override fun write(value: PeerReconnectionStats, buf: ByteBuffer) {
FfiConverterUInt.write(value.`attempts`, buf)
FfiConverterUInt.write(value.`maxAttempts`, buf)
FfiConverterULong.write(value.`disconnectedDurationMs`, buf)
FfiConverterULong.write(value.`nextAttemptDelayMs`, buf)
}
}
/**
* Configuration for reconnection behavior
*/
data class ReconnectionConfig (
/**
* Base delay between reconnection attempts in milliseconds
*/
var `baseDelayMs`: kotlin.ULong
,
/**
* Maximum delay between attempts in milliseconds
*/
var `maxDelayMs`: kotlin.ULong
,
/**
* Maximum number of reconnection attempts before giving up
*/
var `maxAttempts`: kotlin.UInt
,
/**
* Interval for checking which peers need reconnection in milliseconds
*/
var `checkIntervalMs`: kotlin.ULong
,
/**
* Use flat delay instead of exponential backoff
*/
var `useFlatDelay`: kotlin.Boolean
,
/**
* Auto-reset attempt counter when max_attempts is exhausted
*/
var `resetOnExhaustion`: kotlin.Boolean
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeReconnectionConfig: FfiConverterRustBuffer<ReconnectionConfig> {
override fun read(buf: ByteBuffer): ReconnectionConfig {
return ReconnectionConfig(
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
FfiConverterUInt.read(buf),
FfiConverterULong.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
)
}
override fun allocationSize(value: ReconnectionConfig) = (
FfiConverterULong.allocationSize(value.`baseDelayMs`) +
FfiConverterULong.allocationSize(value.`maxDelayMs`) +
FfiConverterUInt.allocationSize(value.`maxAttempts`) +
FfiConverterULong.allocationSize(value.`checkIntervalMs`) +
FfiConverterBoolean.allocationSize(value.`useFlatDelay`) +
FfiConverterBoolean.allocationSize(value.`resetOnExhaustion`)
)
override fun write(value: ReconnectionConfig, buf: ByteBuffer) {
FfiConverterULong.write(value.`baseDelayMs`, buf)
FfiConverterULong.write(value.`maxDelayMs`, buf)
FfiConverterUInt.write(value.`maxAttempts`, buf)
FfiConverterULong.write(value.`checkIntervalMs`, buf)
FfiConverterBoolean.write(value.`useFlatDelay`, buf)
FfiConverterBoolean.write(value.`resetOnExhaustion`, buf)
}
}
/**
* Information about a stale peer
*/
data class StalePeerInfo (
/**
* Peer address
*/
var `address`: kotlin.String
,
/**
* Why the peer is considered stale
*/
var `reason`: StaleReason
,
/**
* How long since the peer was last seen in milliseconds
*/
var `timeSinceLastSeenMs`: kotlin.ULong
,
/**
* Whether the peer was connected when it went stale
*/
var `wasConnected`: kotlin.Boolean
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeStalePeerInfo: FfiConverterRustBuffer<StalePeerInfo> {
override fun read(buf: ByteBuffer): StalePeerInfo {
return StalePeerInfo(
FfiConverterString.read(buf),
FfiConverterTypeStaleReason.read(buf),
FfiConverterULong.read(buf),
FfiConverterBoolean.read(buf),
)
}
override fun allocationSize(value: StalePeerInfo) = (
FfiConverterString.allocationSize(value.`address`) +
FfiConverterTypeStaleReason.allocationSize(value.`reason`) +
FfiConverterULong.allocationSize(value.`timeSinceLastSeenMs`) +
FfiConverterBoolean.allocationSize(value.`wasConnected`)
)
override fun write(value: StalePeerInfo, buf: ByteBuffer) {
FfiConverterString.write(value.`address`, buf)
FfiConverterTypeStaleReason.write(value.`reason`, buf)
FfiConverterULong.write(value.`timeSinceLastSeenMs`, buf)
FfiConverterBoolean.write(value.`wasConnected`, buf)
}
}
data class StateCountSummary (
var `discovered`: kotlin.UInt
,
var `connecting`: kotlin.UInt
,
var `connected`: kotlin.UInt
,
var `degraded`: kotlin.UInt
,
var `disconnecting`: kotlin.UInt
,
var `disconnected`: kotlin.UInt
,
var `lost`: kotlin.UInt
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeStateCountSummary: FfiConverterRustBuffer<StateCountSummary> {
override fun read(buf: ByteBuffer): StateCountSummary {
return StateCountSummary(
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
FfiConverterUInt.read(buf),
)
}
override fun allocationSize(value: StateCountSummary) = (
FfiConverterUInt.allocationSize(value.`discovered`) +
FfiConverterUInt.allocationSize(value.`connecting`) +
FfiConverterUInt.allocationSize(value.`connected`) +
FfiConverterUInt.allocationSize(value.`degraded`) +
FfiConverterUInt.allocationSize(value.`disconnecting`) +
FfiConverterUInt.allocationSize(value.`disconnected`) +
FfiConverterUInt.allocationSize(value.`lost`)
)
override fun write(value: StateCountSummary, buf: ByteBuffer) {
FfiConverterUInt.write(value.`discovered`, buf)
FfiConverterUInt.write(value.`connecting`, buf)
FfiConverterUInt.write(value.`connected`, buf)
FfiConverterUInt.write(value.`degraded`, buf)
FfiConverterUInt.write(value.`disconnecting`, buf)
FfiConverterUInt.write(value.`disconnected`, buf)
FfiConverterUInt.write(value.`lost`, buf)
}
}
/**
* Via-peer routing entry for indirect peer
*/
data class ViaPeerRoute (
var `viaNodeId`: kotlin.UInt
,
var `hopCount`: kotlin.UByte
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeViaPeerRoute: FfiConverterRustBuffer<ViaPeerRoute> {
override fun read(buf: ByteBuffer): ViaPeerRoute {
return ViaPeerRoute(
FfiConverterUInt.read(buf),
FfiConverterUByte.read(buf),
)
}
override fun allocationSize(value: ViaPeerRoute) = (
FfiConverterUInt.allocationSize(value.`viaNodeId`) +
FfiConverterUByte.allocationSize(value.`hopCount`)
)
override fun write(value: ViaPeerRoute, buf: ByteBuffer) {
FfiConverterUInt.write(value.`viaNodeId`, buf)
FfiConverterUByte.write(value.`hopCount`, buf)
}
}
enum class ConnectionState {
DISCOVERED,
CONNECTING,
CONNECTED,
DEGRADED,
DISCONNECTING,
DISCONNECTED,
LOST;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeConnectionState: FfiConverterRustBuffer<ConnectionState> {
override fun read(buf: ByteBuffer) = try {
ConnectionState.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: ConnectionState) = 4UL
override fun write(value: ConnectionState, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
/**
* Patterns that indicate a device may rotate its BLE address
*/
enum class DevicePattern {
/**
* WearTAK on WearOS (WT-WEAROS-XXXX)
*/
WEAR_TAK,
/**
* Generic WearOS device (WEAROS-XXXX)
*/
WEAR_OS,
/**
* Peat mesh device (PEAT_MESH-XXXX or PEAT-XXXX)
*/
PEAT,
/**
* Unknown pattern (may still rotate addresses)
*/
UNKNOWN;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeDevicePattern: FfiConverterRustBuffer<DevicePattern> {
override fun read(buf: ByteBuffer) = try {
DevicePattern.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: DevicePattern) = 4UL
override fun write(value: DevicePattern, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
enum class DisconnectReason {
LOCAL_REQUEST,
REMOTE_REQUEST,
TIMEOUT,
LINK_LOSS,
CONNECTION_FAILED,
UNKNOWN;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeDisconnectReason: FfiConverterRustBuffer<DisconnectReason> {
override fun read(buf: ByteBuffer) = try {
DisconnectReason.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: DisconnectReason) = 4UL
override fun write(value: DisconnectReason, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
enum class EventType {
NONE,
PING,
NEED_ASSIST,
EMERGENCY,
MOVING,
IN_POSITION,
ACK;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeEventType: FfiConverterRustBuffer<EventType> {
override fun read(buf: ByteBuffer) = try {
EventType.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: EventType) = 4UL
override fun write(value: EventType, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
enum class PeripheralType {
UNKNOWN,
SOLDIER_SENSOR,
FIXED_SENSOR,
RELAY;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePeripheralType: FfiConverterRustBuffer<PeripheralType> {
override fun read(buf: ByteBuffer) = try {
PeripheralType.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: PeripheralType) = 4UL
override fun write(value: PeripheralType, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
/**
* Result of checking if a peer should be reconnected
*/
sealed class ReconnectionStatus {
/**
* Ready to attempt reconnection
*/
object Ready : ReconnectionStatus()
/**
* Waiting for backoff delay to expire
*/
data class Waiting(
/**
* Time remaining until next attempt is allowed in milliseconds
*/
val `remainingMs`: kotlin.ULong) : ReconnectionStatus()
{
companion object
}
/**
* Maximum attempts exceeded, peer is abandoned
*/
data class Exhausted(
/**
* Number of attempts that were made
*/
val `attempts`: kotlin.UInt) : ReconnectionStatus()
{
companion object
}
/**
* Peer is not being tracked for reconnection
*/
object NotTracked : ReconnectionStatus()
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeReconnectionStatus : FfiConverterRustBuffer<ReconnectionStatus>{
override fun read(buf: ByteBuffer): ReconnectionStatus {
return when(buf.getInt()) {
1 -> ReconnectionStatus.Ready
2 -> ReconnectionStatus.Waiting(
FfiConverterULong.read(buf),
)
3 -> ReconnectionStatus.Exhausted(
FfiConverterUInt.read(buf),
)
4 -> ReconnectionStatus.NotTracked
else -> throw RuntimeException("invalid enum value, something is very wrong!!")
}
}
override fun allocationSize(value: ReconnectionStatus) = when(value) {
is ReconnectionStatus.Ready -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
)
}
is ReconnectionStatus.Waiting -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
+ FfiConverterULong.allocationSize(value.`remainingMs`)
)
}
is ReconnectionStatus.Exhausted -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
+ FfiConverterUInt.allocationSize(value.`attempts`)
)
}
is ReconnectionStatus.NotTracked -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
)
}
}
override fun write(value: ReconnectionStatus, buf: ByteBuffer) {
when(value) {
is ReconnectionStatus.Ready -> {
buf.putInt(1)
Unit
}
is ReconnectionStatus.Waiting -> {
buf.putInt(2)
FfiConverterULong.write(value.`remainingMs`, buf)
Unit
}
is ReconnectionStatus.Exhausted -> {
buf.putInt(3)
FfiConverterUInt.write(value.`attempts`, buf)
Unit
}
is ReconnectionStatus.NotTracked -> {
buf.putInt(4)
Unit
}
}.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
}
}
/**
* Reason a peer is considered stale
*/
enum class StaleReason {
/**
* Disconnected peer hasn't been seen in a while
*/
DISCONNECTED_TIMEOUT,
/**
* Connected peer hasn't had activity (possible ghost connection)
*/
CONNECTED_TIMEOUT;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeStaleReason: FfiConverterRustBuffer<StaleReason> {
override fun read(buf: ByteBuffer) = try {
StaleReason.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: StaleReason) = 4UL
override fun write(value: StaleReason, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
/**
* @suppress
*/
public object FfiConverterOptionalUByte: FfiConverterRustBuffer<kotlin.UByte?> {
override fun read(buf: ByteBuffer): kotlin.UByte? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterUByte.read(buf)
}
override fun allocationSize(value: kotlin.UByte?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterUByte.allocationSize(value)
}
}
override fun write(value: kotlin.UByte?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterUByte.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalByte: FfiConverterRustBuffer<kotlin.Byte?> {
override fun read(buf: ByteBuffer): kotlin.Byte? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterByte.read(buf)
}
override fun allocationSize(value: kotlin.Byte?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterByte.allocationSize(value)
}
}
override fun write(value: kotlin.Byte?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterByte.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalUInt: FfiConverterRustBuffer<kotlin.UInt?> {
override fun read(buf: ByteBuffer): kotlin.UInt? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterUInt.read(buf)
}
override fun allocationSize(value: kotlin.UInt?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterUInt.allocationSize(value)
}
}
override fun write(value: kotlin.UInt?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterUInt.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalULong: FfiConverterRustBuffer<kotlin.ULong?> {
override fun read(buf: ByteBuffer): kotlin.ULong? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterULong.read(buf)
}
override fun allocationSize(value: kotlin.ULong?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterULong.allocationSize(value)
}
}
override fun write(value: kotlin.ULong?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterULong.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalFloat: FfiConverterRustBuffer<kotlin.Float?> {
override fun read(buf: ByteBuffer): kotlin.Float? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterFloat.read(buf)
}
override fun allocationSize(value: kotlin.Float?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterFloat.allocationSize(value)
}
}
override fun write(value: kotlin.Float?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterFloat.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalString: FfiConverterRustBuffer<kotlin.String?> {
override fun read(buf: ByteBuffer): kotlin.String? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterString.read(buf)
}
override fun allocationSize(value: kotlin.String?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterString.allocationSize(value)
}
}
override fun write(value: kotlin.String?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterString.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalByteArray: FfiConverterRustBuffer<kotlin.ByteArray?> {
override fun read(buf: ByteBuffer): kotlin.ByteArray? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterByteArray.read(buf)
}
override fun allocationSize(value: kotlin.ByteArray?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterByteArray.allocationSize(value)
}
}
override fun write(value: kotlin.ByteArray?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterByteArray.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeDeviceIdentity: FfiConverterRustBuffer<DeviceIdentity?> {
override fun read(buf: ByteBuffer): DeviceIdentity? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeDeviceIdentity.read(buf)
}
override fun allocationSize(value: DeviceIdentity?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeDeviceIdentity.allocationSize(value)
}
}
override fun write(value: DeviceIdentity?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeDeviceIdentity.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeIdentityAttestation: FfiConverterRustBuffer<IdentityAttestation?> {
override fun read(buf: ByteBuffer): IdentityAttestation? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeIdentityAttestation.read(buf)
}
override fun allocationSize(value: IdentityAttestation?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeIdentityAttestation.allocationSize(value)
}
}
override fun write(value: IdentityAttestation?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeIdentityAttestation.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeMeshGenesis: FfiConverterRustBuffer<MeshGenesis?> {
override fun read(buf: ByteBuffer): MeshGenesis? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeMeshGenesis.read(buf)
}
override fun allocationSize(value: MeshGenesis?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeMeshGenesis.allocationSize(value)
}
}
override fun write(value: MeshGenesis?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeMeshGenesis.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypePeatMesh: FfiConverterRustBuffer<PeatMesh?> {
override fun read(buf: ByteBuffer): PeatMesh? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypePeatMesh.read(buf)
}
override fun allocationSize(value: PeatMesh?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypePeatMesh.allocationSize(value)
}
}
override fun write(value: PeatMesh?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypePeatMesh.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeDataReceivedResult: FfiConverterRustBuffer<DataReceivedResult?> {
override fun read(buf: ByteBuffer): DataReceivedResult? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeDataReceivedResult.read(buf)
}
override fun allocationSize(value: DataReceivedResult?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeDataReceivedResult.allocationSize(value)
}
}
override fun write(value: DataReceivedResult?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeDataReceivedResult.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeDeviceLookupResult: FfiConverterRustBuffer<DeviceLookupResult?> {
override fun read(buf: ByteBuffer): DeviceLookupResult? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeDeviceLookupResult.read(buf)
}
override fun allocationSize(value: DeviceLookupResult?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeDeviceLookupResult.allocationSize(value)
}
}
override fun write(value: DeviceLookupResult?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeDeviceLookupResult.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypePeatPeer: FfiConverterRustBuffer<PeatPeer?> {
override fun read(buf: ByteBuffer): PeatPeer? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypePeatPeer.read(buf)
}
override fun allocationSize(value: PeatPeer?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypePeatPeer.allocationSize(value)
}
}
override fun write(value: PeatPeer?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypePeatPeer.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypePeerConnectionState: FfiConverterRustBuffer<PeerConnectionState?> {
override fun read(buf: ByteBuffer): PeerConnectionState? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypePeerConnectionState.read(buf)
}
override fun allocationSize(value: PeerConnectionState?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypePeerConnectionState.allocationSize(value)
}
}
override fun write(value: PeerConnectionState?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypePeerConnectionState.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypePeerInfo: FfiConverterRustBuffer<PeerInfo?> {
override fun read(buf: ByteBuffer): PeerInfo? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypePeerInfo.read(buf)
}
override fun allocationSize(value: PeerInfo?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypePeerInfo.allocationSize(value)
}
}
override fun write(value: PeerInfo?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypePeerInfo.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypePeerReconnectionStats: FfiConverterRustBuffer<PeerReconnectionStats?> {
override fun read(buf: ByteBuffer): PeerReconnectionStats? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypePeerReconnectionStats.read(buf)
}
override fun allocationSize(value: PeerReconnectionStats?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypePeerReconnectionStats.allocationSize(value)
}
}
override fun write(value: PeerReconnectionStats?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypePeerReconnectionStats.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeDisconnectReason: FfiConverterRustBuffer<DisconnectReason?> {
override fun read(buf: ByteBuffer): DisconnectReason? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeDisconnectReason.read(buf)
}
override fun allocationSize(value: DisconnectReason?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeDisconnectReason.allocationSize(value)
}
}
override fun write(value: DisconnectReason?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeDisconnectReason.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeEventType: FfiConverterRustBuffer<EventType?> {
override fun read(buf: ByteBuffer): EventType? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeEventType.read(buf)
}
override fun allocationSize(value: EventType?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeEventType.allocationSize(value)
}
}
override fun write(value: EventType?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeEventType.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceString: FfiConverterRustBuffer<List<kotlin.String>> {
override fun read(buf: ByteBuffer): List<kotlin.String> {
val len = buf.getInt()
return List<kotlin.String>(len) {
FfiConverterString.read(buf)
}
}
override fun allocationSize(value: List<kotlin.String>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<kotlin.String>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterString.write(it, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceTypeIndirectPeer: FfiConverterRustBuffer<List<IndirectPeer>> {
override fun read(buf: ByteBuffer): List<IndirectPeer> {
val len = buf.getInt()
return List<IndirectPeer>(len) {
FfiConverterTypeIndirectPeer.read(buf)
}
}
override fun allocationSize(value: List<IndirectPeer>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypeIndirectPeer.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<IndirectPeer>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypeIndirectPeer.write(it, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceTypePeatPeer: FfiConverterRustBuffer<List<PeatPeer>> {
override fun read(buf: ByteBuffer): List<PeatPeer> {
val len = buf.getInt()
return List<PeatPeer>(len) {
FfiConverterTypePeatPeer.read(buf)
}
}
override fun allocationSize(value: List<PeatPeer>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypePeatPeer.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<PeatPeer>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypePeatPeer.write(it, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceTypePeerConnectionState: FfiConverterRustBuffer<List<PeerConnectionState>> {
override fun read(buf: ByteBuffer): List<PeerConnectionState> {
val len = buf.getInt()
return List<PeerConnectionState>(len) {
FfiConverterTypePeerConnectionState.read(buf)
}
}
override fun allocationSize(value: List<PeerConnectionState>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypePeerConnectionState.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<PeerConnectionState>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypePeerConnectionState.write(it, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceTypeStalePeerInfo: FfiConverterRustBuffer<List<StalePeerInfo>> {
override fun read(buf: ByteBuffer): List<StalePeerInfo> {
val len = buf.getInt()
return List<StalePeerInfo>(len) {
FfiConverterTypeStalePeerInfo.read(buf)
}
}
override fun allocationSize(value: List<StalePeerInfo>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypeStalePeerInfo.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<StalePeerInfo>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypeStalePeerInfo.write(it, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceTypeViaPeerRoute: FfiConverterRustBuffer<List<ViaPeerRoute>> {
override fun read(buf: ByteBuffer): List<ViaPeerRoute> {
val len = buf.getInt()
return List<ViaPeerRoute>(len) {
FfiConverterTypeViaPeerRoute.read(buf)
}
}
override fun allocationSize(value: List<ViaPeerRoute>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypeViaPeerRoute.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<ViaPeerRoute>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypeViaPeerRoute.write(it, buf)
}
}
}
/**
* Create a PeatMesh with encryption enabled (returns null if secret is wrong length)
*/ fun `createPeatMeshWithEncryption`(`nodeId`: kotlin.UInt, `callsign`: kotlin.String, `meshId`: kotlin.String, `encryptionSecret`: kotlin.ByteArray): PeatMesh? {
return FfiConverterOptionalTypePeatMesh.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_create_peat_mesh_with_encryption(
FfiConverterUInt.lower(`nodeId`),FfiConverterString.lower(`callsign`),FfiConverterString.lower(`meshId`),FfiConverterByteArray.lower(`encryptionSecret`),_status)
}
)
}
/**
* Decode an IdentityAttestation from bytes (returns null if invalid)
*/ fun `decodeIdentityAttestation`(`encoded`: kotlin.ByteArray): IdentityAttestation? {
return FfiConverterOptionalTypeIdentityAttestation.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_decode_identity_attestation(
FfiConverterByteArray.lower(`encoded`),_status)
}
)
}
/**
* Decode a MeshGenesis from bytes (returns null if invalid)
*/ fun `decodeMeshGenesis`(`encoded`: kotlin.ByteArray): MeshGenesis? {
return FfiConverterOptionalTypeMeshGenesis.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_decode_mesh_genesis(
FfiConverterByteArray.lower(`encoded`),_status)
}
)
}
/**
* Derive a node ID from a MAC address string (format: "AA:BB:CC:DD:EE:FF")
*/ fun `deriveNodeIdFromMac`(`macAddress`: kotlin.String): kotlin.UInt {
return FfiConverterUInt.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_derive_node_id_from_mac(
FfiConverterString.lower(`macAddress`),_status)
}
)
}
/**
* Detect the device pattern from a BLE device name
*/ fun `detectDevicePattern`(`name`: kotlin.String): DevicePattern {
return FfiConverterTypeDevicePattern.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_detect_device_pattern(
FfiConverterString.lower(`name`),_status)
}
)
}
/**
* Check if a device pattern is known to rotate addresses
*/ fun `devicePatternRotatesAddresses`(`pattern`: DevicePattern): kotlin.Boolean {
return FfiConverterBoolean.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_device_pattern_rotates_addresses(
FfiConverterTypeDevicePattern.lower(`pattern`),_status)
}
)
}
/**
* Check if a device name matches a WearTAK/WearOS pattern
*/ fun `isWeartakDevice`(`name`: kotlin.String): kotlin.Boolean {
return FfiConverterBoolean.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_is_weartak_device(
FfiConverterString.lower(`name`),_status)
}
)
}
/**
* Normalize a WearTAK device name (removes "WT-" prefix if present)
*/ fun `normalizeWeartakName`(`name`: kotlin.String): kotlin.String {
return FfiConverterString.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_normalize_weartak_name(
FfiConverterString.lower(`name`),_status)
}
)
}
/**
* Restore a DeviceIdentity from private key bytes (returns null if invalid)
*/ fun `restoreDeviceIdentity`(`privateKey`: kotlin.ByteArray): DeviceIdentity? {
return FfiConverterOptionalTypeDeviceIdentity.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_peat_btle_fn_func_restore_device_identity(
FfiConverterByteArray.lower(`privateKey`),_status)
}
)
}