sdk

Radroots SDK and bindings
git clone https://radroots.dev/git/sdk.git
Log | Files | Refs | README

radroots_sdk.kt (87413B)


      1 // This file was autogenerated by some hot garbage in the `uniffi` crate.
      2 // Trust me, you don't want to mess with it!
      3 
      4 @file:Suppress("NAME_SHADOWING")
      5 
      6 package uniffi.radroots_sdk
      7 
      8 // Common helper code.
      9 //
     10 // Ideally this would live in a separate .kt file where it can be unittested etc
     11 // in isolation, and perhaps even published as a re-useable package.
     12 //
     13 // However, it's important that the details of how this helper code works (e.g. the
     14 // way that different builtin types are passed across the FFI) exactly match what's
     15 // expected by the Rust code on the other side of the interface. In practice right
     16 // now that means coming from the exact some version of `uniffi` that was used to
     17 // compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
     18 // helpers directly inline like we're doing here.
     19 
     20 import com.sun.jna.Library
     21 import com.sun.jna.IntegerType
     22 import com.sun.jna.Native
     23 import com.sun.jna.Pointer
     24 import com.sun.jna.Structure
     25 import com.sun.jna.Callback
     26 import com.sun.jna.ptr.*
     27 import java.nio.ByteBuffer
     28 import java.nio.ByteOrder
     29 import java.nio.CharBuffer
     30 import java.nio.charset.CodingErrorAction
     31 import java.util.concurrent.atomic.AtomicLong
     32 import java.util.concurrent.ConcurrentHashMap
     33 import java.util.concurrent.atomic.AtomicBoolean
     34 import kotlin.coroutines.resume
     35 import kotlinx.coroutines.CancellableContinuation
     36 import kotlinx.coroutines.DelicateCoroutinesApi
     37 import kotlinx.coroutines.GlobalScope
     38 import kotlinx.coroutines.Job
     39 import kotlinx.coroutines.launch
     40 import kotlinx.coroutines.suspendCancellableCoroutine
     41 
     42 // This is a helper for safely working with byte buffers returned from the Rust code.
     43 // A rust-owned buffer is represented by its capacity, its current length, and a
     44 // pointer to the underlying data.
     45 
     46 /**
     47  * @suppress
     48  */
     49 @Structure.FieldOrder("capacity", "len", "data")
     50 open class RustBuffer : Structure() {
     51     // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
     52     // When dealing with these fields, make sure to call `toULong()`.
     53     @JvmField var capacity: Long = 0
     54     @JvmField var len: Long = 0
     55     @JvmField var data: Pointer? = null
     56 
     57     class ByValue: RustBuffer(), Structure.ByValue
     58     class ByReference: RustBuffer(), Structure.ByReference
     59 
     60    internal fun setValue(other: RustBuffer) {
     61         capacity = other.capacity
     62         len = other.len
     63         data = other.data
     64     }
     65 
     66     companion object {
     67         internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
     68             // Note: need to convert the size to a `Long` value to make this work with JVM.
     69             UniffiLib.INSTANCE.ffi_radroots_sdk_ffi_rustbuffer_alloc(size.toLong(), status)
     70         }.also {
     71             if(it.data == null) {
     72                throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
     73            }
     74         }
     75 
     76         internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
     77             var buf = RustBuffer.ByValue()
     78             buf.capacity = capacity.toLong()
     79             buf.len = len.toLong()
     80             buf.data = data
     81             return buf
     82         }
     83 
     84         internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
     85             UniffiLib.INSTANCE.ffi_radroots_sdk_ffi_rustbuffer_free(buf, status)
     86         }
     87     }
     88 
     89     @Suppress("TooGenericExceptionThrown")
     90     fun asByteBuffer() =
     91         this.data?.getByteBuffer(0, this.len.toLong())?.also {
     92             it.order(ByteOrder.BIG_ENDIAN)
     93         }
     94 }
     95 
     96 /**
     97  * The equivalent of the `*mut RustBuffer` type.
     98  * Required for callbacks taking in an out pointer.
     99  *
    100  * Size is the sum of all values in the struct.
    101  *
    102  * @suppress
    103  */
    104 class RustBufferByReference : ByReference(16) {
    105     /**
    106      * Set the pointed-to `RustBuffer` to the given value.
    107      */
    108     fun setValue(value: RustBuffer.ByValue) {
    109         // NOTE: The offsets are as they are in the C-like struct.
    110         val pointer = getPointer()
    111         pointer.setLong(0, value.capacity)
    112         pointer.setLong(8, value.len)
    113         pointer.setPointer(16, value.data)
    114     }
    115 
    116     /**
    117      * Get a `RustBuffer.ByValue` from this reference.
    118      */
    119     fun getValue(): RustBuffer.ByValue {
    120         val pointer = getPointer()
    121         val value = RustBuffer.ByValue()
    122         value.writeField("capacity", pointer.getLong(0))
    123         value.writeField("len", pointer.getLong(8))
    124         value.writeField("data", pointer.getLong(16))
    125 
    126         return value
    127     }
    128 }
    129 
    130 // This is a helper for safely passing byte references into the rust code.
    131 // It's not actually used at the moment, because there aren't many things that you
    132 // can take a direct pointer to in the JVM, and if we're going to copy something
    133 // then we might as well copy it into a `RustBuffer`. But it's here for API
    134 // completeness.
    135 
    136 @Structure.FieldOrder("len", "data")
    137 internal open class ForeignBytes : Structure() {
    138     @JvmField var len: Int = 0
    139     @JvmField var data: Pointer? = null
    140 
    141     class ByValue : ForeignBytes(), Structure.ByValue
    142 }
    143 /**
    144  * The FfiConverter interface handles converter types to and from the FFI
    145  *
    146  * All implementing objects should be public to support external types.  When a
    147  * type is external we need to import it's FfiConverter.
    148  *
    149  * @suppress
    150  */
    151 public interface FfiConverter<KotlinType, FfiType> {
    152     // Convert an FFI type to a Kotlin type
    153     fun lift(value: FfiType): KotlinType
    154 
    155     // Convert an Kotlin type to an FFI type
    156     fun lower(value: KotlinType): FfiType
    157 
    158     // Read a Kotlin type from a `ByteBuffer`
    159     fun read(buf: ByteBuffer): KotlinType
    160 
    161     // Calculate bytes to allocate when creating a `RustBuffer`
    162     //
    163     // This must return at least as many bytes as the write() function will
    164     // write. It can return more bytes than needed, for example when writing
    165     // Strings we can't know the exact bytes needed until we the UTF-8
    166     // encoding, so we pessimistically allocate the largest size possible (3
    167     // bytes per codepoint).  Allocating extra bytes is not really a big deal
    168     // because the `RustBuffer` is short-lived.
    169     fun allocationSize(value: KotlinType): ULong
    170 
    171     // Write a Kotlin type to a `ByteBuffer`
    172     fun write(value: KotlinType, buf: ByteBuffer)
    173 
    174     // Lower a value into a `RustBuffer`
    175     //
    176     // This method lowers a value into a `RustBuffer` rather than the normal
    177     // FfiType.  It's used by the callback interface code.  Callback interface
    178     // returns are always serialized into a `RustBuffer` regardless of their
    179     // normal FFI type.
    180     fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
    181         val rbuf = RustBuffer.alloc(allocationSize(value))
    182         try {
    183             val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
    184                 it.order(ByteOrder.BIG_ENDIAN)
    185             }
    186             write(value, bbuf)
    187             rbuf.writeField("len", bbuf.position().toLong())
    188             return rbuf
    189         } catch (e: Throwable) {
    190             RustBuffer.free(rbuf)
    191             throw e
    192         }
    193     }
    194 
    195     // Lift a value from a `RustBuffer`.
    196     //
    197     // This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
    198     // It's currently only used by the `FfiConverterRustBuffer` class below.
    199     fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
    200         val byteBuf = rbuf.asByteBuffer()!!
    201         try {
    202            val item = read(byteBuf)
    203            if (byteBuf.hasRemaining()) {
    204                throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
    205            }
    206            return item
    207         } finally {
    208             RustBuffer.free(rbuf)
    209         }
    210     }
    211 }
    212 
    213 /**
    214  * FfiConverter that uses `RustBuffer` as the FfiType
    215  *
    216  * @suppress
    217  */
    218 public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
    219     override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
    220     override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
    221 }
    222 // A handful of classes and functions to support the generated data structures.
    223 // This would be a good candidate for isolating in its own ffi-support lib.
    224 
    225 internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
    226 internal const val UNIFFI_CALL_ERROR = 1.toByte()
    227 internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
    228 
    229 @Structure.FieldOrder("code", "error_buf")
    230 internal open class UniffiRustCallStatus : Structure() {
    231     @JvmField var code: Byte = 0
    232     @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
    233 
    234     class ByValue: UniffiRustCallStatus(), Structure.ByValue
    235 
    236     fun isSuccess(): Boolean {
    237         return code == UNIFFI_CALL_SUCCESS
    238     }
    239 
    240     fun isError(): Boolean {
    241         return code == UNIFFI_CALL_ERROR
    242     }
    243 
    244     fun isPanic(): Boolean {
    245         return code == UNIFFI_CALL_UNEXPECTED_ERROR
    246     }
    247 
    248     companion object {
    249         fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
    250             val callStatus = UniffiRustCallStatus.ByValue()
    251             callStatus.code = code
    252             callStatus.error_buf = errorBuf
    253             return callStatus
    254         }
    255     }
    256 }
    257 
    258 class InternalException(message: String) : kotlin.Exception(message)
    259 
    260 /**
    261  * Each top-level error class has a companion object that can lift the error from the call status's rust buffer
    262  *
    263  * @suppress
    264  */
    265 interface UniffiRustCallStatusErrorHandler<E> {
    266     fun lift(error_buf: RustBuffer.ByValue): E;
    267 }
    268 
    269 // Helpers for calling Rust
    270 // In practice we usually need to be synchronized to call this safely, so it doesn't
    271 // synchronize itself
    272 
    273 // Call a rust function that returns a Result<>.  Pass in the Error class companion that corresponds to the Err
    274 private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
    275     var status = UniffiRustCallStatus()
    276     val return_value = callback(status)
    277     uniffiCheckCallStatus(errorHandler, status)
    278     return return_value
    279 }
    280 
    281 // Check UniffiRustCallStatus and throw an error if the call wasn't successful
    282 private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
    283     if (status.isSuccess()) {
    284         return
    285     } else if (status.isError()) {
    286         throw errorHandler.lift(status.error_buf)
    287     } else if (status.isPanic()) {
    288         // when the rust code sees a panic, it tries to construct a rustbuffer
    289         // with the message.  but if that code panics, then it just sends back
    290         // an empty buffer.
    291         if (status.error_buf.len > 0) {
    292             throw InternalException(FfiConverterString.lift(status.error_buf))
    293         } else {
    294             throw InternalException("Rust panic")
    295         }
    296     } else {
    297         throw InternalException("Unknown rust call status: $status.code")
    298     }
    299 }
    300 
    301 /**
    302  * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
    303  *
    304  * @suppress
    305  */
    306 object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
    307     override fun lift(error_buf: RustBuffer.ByValue): InternalException {
    308         RustBuffer.free(error_buf)
    309         return InternalException("Unexpected CALL_ERROR")
    310     }
    311 }
    312 
    313 // Call a rust function that returns a plain value
    314 private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
    315     return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
    316 }
    317 
    318 internal inline fun<T> uniffiTraitInterfaceCall(
    319     callStatus: UniffiRustCallStatus,
    320     makeCall: () -> T,
    321     writeReturn: (T) -> Unit,
    322 ) {
    323     try {
    324         writeReturn(makeCall())
    325     } catch(e: kotlin.Exception) {
    326         callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
    327         callStatus.error_buf = FfiConverterString.lower(e.toString())
    328     }
    329 }
    330 
    331 internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
    332     callStatus: UniffiRustCallStatus,
    333     makeCall: () -> T,
    334     writeReturn: (T) -> Unit,
    335     lowerError: (E) -> RustBuffer.ByValue
    336 ) {
    337     try {
    338         writeReturn(makeCall())
    339     } catch(e: kotlin.Exception) {
    340         if (e is E) {
    341             callStatus.code = UNIFFI_CALL_ERROR
    342             callStatus.error_buf = lowerError(e)
    343         } else {
    344             callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
    345             callStatus.error_buf = FfiConverterString.lower(e.toString())
    346         }
    347     }
    348 }
    349 // Map handles to objects
    350 //
    351 // This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
    352 internal class UniffiHandleMap<T: Any> {
    353     private val map = ConcurrentHashMap<Long, T>()
    354     private val counter = java.util.concurrent.atomic.AtomicLong(0)
    355 
    356     val size: Int
    357         get() = map.size
    358 
    359     // Insert a new object into the handle map and get a handle for it
    360     fun insert(obj: T): Long {
    361         val handle = counter.getAndAdd(1)
    362         map.put(handle, obj)
    363         return handle
    364     }
    365 
    366     // Get an object from the handle map
    367     fun get(handle: Long): T {
    368         return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
    369     }
    370 
    371     // Remove an entry from the handlemap and get the Kotlin object back
    372     fun remove(handle: Long): T {
    373         return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
    374     }
    375 }
    376 
    377 // Contains loading, initialization code,
    378 // and the FFI Function declarations in a com.sun.jna.Library.
    379 @Synchronized
    380 private fun findLibraryName(componentName: String): String {
    381     val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
    382     if (libOverride != null) {
    383         return libOverride
    384     }
    385     return "radroots_sdk_ffi"
    386 }
    387 
    388 private inline fun <reified Lib : Library> loadIndirect(
    389     componentName: String
    390 ): Lib {
    391     return Native.load<Lib>(findLibraryName(componentName), Lib::class.java)
    392 }
    393 
    394 // Define FFI callback types
    395 internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
    396     fun callback(`data`: Long,`pollResult`: Byte,)
    397 }
    398 internal interface UniffiForeignFutureFree : com.sun.jna.Callback {
    399     fun callback(`handle`: Long,)
    400 }
    401 internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
    402     fun callback(`handle`: Long,)
    403 }
    404 @Structure.FieldOrder("handle", "free")
    405 internal open class UniffiForeignFuture(
    406     @JvmField internal var `handle`: Long = 0.toLong(),
    407     @JvmField internal var `free`: UniffiForeignFutureFree? = null,
    408 ) : Structure() {
    409     class UniffiByValue(
    410         `handle`: Long = 0.toLong(),
    411         `free`: UniffiForeignFutureFree? = null,
    412     ): UniffiForeignFuture(`handle`,`free`,), Structure.ByValue
    413 
    414    internal fun uniffiSetValue(other: UniffiForeignFuture) {
    415         `handle` = other.`handle`
    416         `free` = other.`free`
    417     }
    418 
    419 }
    420 @Structure.FieldOrder("returnValue", "callStatus")
    421 internal open class UniffiForeignFutureStructU8(
    422     @JvmField internal var `returnValue`: Byte = 0.toByte(),
    423     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    424 ) : Structure() {
    425     class UniffiByValue(
    426         `returnValue`: Byte = 0.toByte(),
    427         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    428     ): UniffiForeignFutureStructU8(`returnValue`,`callStatus`,), Structure.ByValue
    429 
    430    internal fun uniffiSetValue(other: UniffiForeignFutureStructU8) {
    431         `returnValue` = other.`returnValue`
    432         `callStatus` = other.`callStatus`
    433     }
    434 
    435 }
    436 internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
    437     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU8.UniffiByValue,)
    438 }
    439 @Structure.FieldOrder("returnValue", "callStatus")
    440 internal open class UniffiForeignFutureStructI8(
    441     @JvmField internal var `returnValue`: Byte = 0.toByte(),
    442     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    443 ) : Structure() {
    444     class UniffiByValue(
    445         `returnValue`: Byte = 0.toByte(),
    446         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    447     ): UniffiForeignFutureStructI8(`returnValue`,`callStatus`,), Structure.ByValue
    448 
    449    internal fun uniffiSetValue(other: UniffiForeignFutureStructI8) {
    450         `returnValue` = other.`returnValue`
    451         `callStatus` = other.`callStatus`
    452     }
    453 
    454 }
    455 internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
    456     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI8.UniffiByValue,)
    457 }
    458 @Structure.FieldOrder("returnValue", "callStatus")
    459 internal open class UniffiForeignFutureStructU16(
    460     @JvmField internal var `returnValue`: Short = 0.toShort(),
    461     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    462 ) : Structure() {
    463     class UniffiByValue(
    464         `returnValue`: Short = 0.toShort(),
    465         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    466     ): UniffiForeignFutureStructU16(`returnValue`,`callStatus`,), Structure.ByValue
    467 
    468    internal fun uniffiSetValue(other: UniffiForeignFutureStructU16) {
    469         `returnValue` = other.`returnValue`
    470         `callStatus` = other.`callStatus`
    471     }
    472 
    473 }
    474 internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
    475     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU16.UniffiByValue,)
    476 }
    477 @Structure.FieldOrder("returnValue", "callStatus")
    478 internal open class UniffiForeignFutureStructI16(
    479     @JvmField internal var `returnValue`: Short = 0.toShort(),
    480     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    481 ) : Structure() {
    482     class UniffiByValue(
    483         `returnValue`: Short = 0.toShort(),
    484         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    485     ): UniffiForeignFutureStructI16(`returnValue`,`callStatus`,), Structure.ByValue
    486 
    487    internal fun uniffiSetValue(other: UniffiForeignFutureStructI16) {
    488         `returnValue` = other.`returnValue`
    489         `callStatus` = other.`callStatus`
    490     }
    491 
    492 }
    493 internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
    494     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI16.UniffiByValue,)
    495 }
    496 @Structure.FieldOrder("returnValue", "callStatus")
    497 internal open class UniffiForeignFutureStructU32(
    498     @JvmField internal var `returnValue`: Int = 0,
    499     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    500 ) : Structure() {
    501     class UniffiByValue(
    502         `returnValue`: Int = 0,
    503         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    504     ): UniffiForeignFutureStructU32(`returnValue`,`callStatus`,), Structure.ByValue
    505 
    506    internal fun uniffiSetValue(other: UniffiForeignFutureStructU32) {
    507         `returnValue` = other.`returnValue`
    508         `callStatus` = other.`callStatus`
    509     }
    510 
    511 }
    512 internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
    513     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU32.UniffiByValue,)
    514 }
    515 @Structure.FieldOrder("returnValue", "callStatus")
    516 internal open class UniffiForeignFutureStructI32(
    517     @JvmField internal var `returnValue`: Int = 0,
    518     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    519 ) : Structure() {
    520     class UniffiByValue(
    521         `returnValue`: Int = 0,
    522         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    523     ): UniffiForeignFutureStructI32(`returnValue`,`callStatus`,), Structure.ByValue
    524 
    525    internal fun uniffiSetValue(other: UniffiForeignFutureStructI32) {
    526         `returnValue` = other.`returnValue`
    527         `callStatus` = other.`callStatus`
    528     }
    529 
    530 }
    531 internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
    532     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI32.UniffiByValue,)
    533 }
    534 @Structure.FieldOrder("returnValue", "callStatus")
    535 internal open class UniffiForeignFutureStructU64(
    536     @JvmField internal var `returnValue`: Long = 0.toLong(),
    537     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    538 ) : Structure() {
    539     class UniffiByValue(
    540         `returnValue`: Long = 0.toLong(),
    541         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    542     ): UniffiForeignFutureStructU64(`returnValue`,`callStatus`,), Structure.ByValue
    543 
    544    internal fun uniffiSetValue(other: UniffiForeignFutureStructU64) {
    545         `returnValue` = other.`returnValue`
    546         `callStatus` = other.`callStatus`
    547     }
    548 
    549 }
    550 internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
    551     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU64.UniffiByValue,)
    552 }
    553 @Structure.FieldOrder("returnValue", "callStatus")
    554 internal open class UniffiForeignFutureStructI64(
    555     @JvmField internal var `returnValue`: Long = 0.toLong(),
    556     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    557 ) : Structure() {
    558     class UniffiByValue(
    559         `returnValue`: Long = 0.toLong(),
    560         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    561     ): UniffiForeignFutureStructI64(`returnValue`,`callStatus`,), Structure.ByValue
    562 
    563    internal fun uniffiSetValue(other: UniffiForeignFutureStructI64) {
    564         `returnValue` = other.`returnValue`
    565         `callStatus` = other.`callStatus`
    566     }
    567 
    568 }
    569 internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
    570     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI64.UniffiByValue,)
    571 }
    572 @Structure.FieldOrder("returnValue", "callStatus")
    573 internal open class UniffiForeignFutureStructF32(
    574     @JvmField internal var `returnValue`: Float = 0.0f,
    575     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    576 ) : Structure() {
    577     class UniffiByValue(
    578         `returnValue`: Float = 0.0f,
    579         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    580     ): UniffiForeignFutureStructF32(`returnValue`,`callStatus`,), Structure.ByValue
    581 
    582    internal fun uniffiSetValue(other: UniffiForeignFutureStructF32) {
    583         `returnValue` = other.`returnValue`
    584         `callStatus` = other.`callStatus`
    585     }
    586 
    587 }
    588 internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
    589     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF32.UniffiByValue,)
    590 }
    591 @Structure.FieldOrder("returnValue", "callStatus")
    592 internal open class UniffiForeignFutureStructF64(
    593     @JvmField internal var `returnValue`: Double = 0.0,
    594     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    595 ) : Structure() {
    596     class UniffiByValue(
    597         `returnValue`: Double = 0.0,
    598         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    599     ): UniffiForeignFutureStructF64(`returnValue`,`callStatus`,), Structure.ByValue
    600 
    601    internal fun uniffiSetValue(other: UniffiForeignFutureStructF64) {
    602         `returnValue` = other.`returnValue`
    603         `callStatus` = other.`callStatus`
    604     }
    605 
    606 }
    607 internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
    608     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF64.UniffiByValue,)
    609 }
    610 @Structure.FieldOrder("returnValue", "callStatus")
    611 internal open class UniffiForeignFutureStructPointer(
    612     @JvmField internal var `returnValue`: Pointer = Pointer.NULL,
    613     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    614 ) : Structure() {
    615     class UniffiByValue(
    616         `returnValue`: Pointer = Pointer.NULL,
    617         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    618     ): UniffiForeignFutureStructPointer(`returnValue`,`callStatus`,), Structure.ByValue
    619 
    620    internal fun uniffiSetValue(other: UniffiForeignFutureStructPointer) {
    621         `returnValue` = other.`returnValue`
    622         `callStatus` = other.`callStatus`
    623     }
    624 
    625 }
    626 internal interface UniffiForeignFutureCompletePointer : com.sun.jna.Callback {
    627     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructPointer.UniffiByValue,)
    628 }
    629 @Structure.FieldOrder("returnValue", "callStatus")
    630 internal open class UniffiForeignFutureStructRustBuffer(
    631     @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
    632     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    633 ) : Structure() {
    634     class UniffiByValue(
    635         `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
    636         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    637     ): UniffiForeignFutureStructRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
    638 
    639    internal fun uniffiSetValue(other: UniffiForeignFutureStructRustBuffer) {
    640         `returnValue` = other.`returnValue`
    641         `callStatus` = other.`callStatus`
    642     }
    643 
    644 }
    645 internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
    646     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructRustBuffer.UniffiByValue,)
    647 }
    648 @Structure.FieldOrder("callStatus")
    649 internal open class UniffiForeignFutureStructVoid(
    650     @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    651 ) : Structure() {
    652     class UniffiByValue(
    653         `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
    654     ): UniffiForeignFutureStructVoid(`callStatus`,), Structure.ByValue
    655 
    656    internal fun uniffiSetValue(other: UniffiForeignFutureStructVoid) {
    657         `callStatus` = other.`callStatus`
    658     }
    659 
    660 }
    661 internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
    662     fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,)
    663 }
    664 
    665 
    666 
    667 
    668 
    669 
    670 
    671 
    672 
    673 
    674 
    675 
    676 
    677 
    678 
    679 
    680 
    681 
    682 
    683 
    684 
    685 
    686 
    687 
    688 
    689 
    690 
    691 
    692 
    693 
    694 
    695 
    696 
    697 
    698 
    699 
    700 
    701 
    702 
    703 
    704 
    705 
    706 
    707 
    708 
    709 
    710 
    711 
    712 
    713 
    714 
    715 
    716 
    717 
    718 
    719 
    720 
    721 
    722 
    723 
    724 
    725 
    726 
    727 
    728 
    729 
    730 
    731 
    732 
    733 
    734 
    735 
    736 
    737 
    738 
    739 
    740 // For large crates we prevent `MethodTooLargeException` (see #2340)
    741 // N.B. the name of the extension is very misleading, since it is
    742 // rather `InterfaceTooLargeException`, caused by too many methods
    743 // in the interface for large crates.
    744 //
    745 // By splitting the otherwise huge interface into two parts
    746 // * UniffiLib
    747 // * IntegrityCheckingUniffiLib (this)
    748 // we allow for ~2x as many methods in the UniffiLib interface.
    749 //
    750 // The `ffi_uniffi_contract_version` method and all checksum methods are put
    751 // into `IntegrityCheckingUniffiLib` and these methods are called only once,
    752 // when the library is loaded.
    753 internal interface IntegrityCheckingUniffiLib : Library {
    754     // Integrity check functions only
    755     fun uniffi_radroots_sdk_ffi_checksum_func_parse_rhi_evidence_report(
    756 ): Short
    757 fun uniffi_radroots_sdk_ffi_checksum_func_parse_trade_evidence_manifest(
    758 ): Short
    759 fun uniffi_radroots_sdk_ffi_checksum_func_prepare_rhi_evidence_attestation(
    760 ): Short
    761 fun uniffi_radroots_sdk_ffi_checksum_func_validate_rhi_evidence_attestation(
    762 ): Short
    763 fun uniffi_radroots_sdk_ffi_checksum_method_mobileclient_capabilities(
    764 ): Short
    765 fun uniffi_radroots_sdk_ffi_checksum_method_mobileclient_close(
    766 ): Short
    767 fun uniffi_radroots_sdk_ffi_checksum_method_mobileclient_is_closed(
    768 ): Short
    769 fun uniffi_radroots_sdk_ffi_checksum_constructor_mobileclient_memory(
    770 ): Short
    771 fun ffi_radroots_sdk_ffi_uniffi_contract_version(
    772 ): Int
    773 
    774 }
    775 
    776 // A JNA Library to expose the extern-C FFI definitions.
    777 // This is an implementation detail which will be called internally by the public API.
    778 internal interface UniffiLib : Library {
    779     companion object {
    780         internal val INSTANCE: UniffiLib by lazy {
    781             val componentName = "radroots_sdk"
    782             // For large crates we prevent `MethodTooLargeException` (see #2340)
    783             // N.B. the name of the extension is very misleading, since it is
    784             // rather `InterfaceTooLargeException`, caused by too many methods
    785             // in the interface for large crates.
    786             //
    787             // By splitting the otherwise huge interface into two parts
    788             // * UniffiLib (this)
    789             // * IntegrityCheckingUniffiLib
    790             // And all checksum methods are put into `IntegrityCheckingUniffiLib`
    791             // we allow for ~2x as many methods in the UniffiLib interface.
    792             //
    793             // Thus we first load the library with `loadIndirect` as `IntegrityCheckingUniffiLib`
    794             // so that we can (optionally!) call `uniffiCheckApiChecksums`...
    795             loadIndirect<IntegrityCheckingUniffiLib>(componentName)
    796                 .also { lib: IntegrityCheckingUniffiLib ->
    797                     uniffiCheckContractApiVersion(lib)
    798                     uniffiCheckApiChecksums(lib)
    799                 }
    800             // ... and then we load the library as `UniffiLib`
    801             // N.B. we cannot use `loadIndirect` once and then try to cast it to `UniffiLib`
    802             // => results in `java.lang.ClassCastException: com.sun.proxy.$Proxy cannot be cast to ...`
    803             // error. So we must call `loadIndirect` twice. For crates large enough
    804             // to trigger this issue, the performance impact is negligible, running on
    805             // a macOS M1 machine the `loadIndirect` call takes ~50ms.
    806             val lib = loadIndirect<UniffiLib>(componentName)
    807             // No need to check the contract version and checksums, since
    808             // we already did that with `IntegrityCheckingUniffiLib` above.
    809             // Loading of library with integrity check done.
    810             lib
    811         }
    812 
    813         // The Cleaner for the whole library
    814         internal val CLEANER: UniffiCleaner by lazy {
    815             UniffiCleaner.create()
    816         }
    817     }
    818 
    819     // FFI functions
    820     fun uniffi_radroots_sdk_ffi_fn_clone_mobileclient(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
    821 ): Pointer
    822 fun uniffi_radroots_sdk_ffi_fn_free_mobileclient(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
    823 ): Unit
    824 fun uniffi_radroots_sdk_ffi_fn_constructor_mobileclient_memory(uniffi_out_err: UniffiRustCallStatus,
    825 ): Pointer
    826 fun uniffi_radroots_sdk_ffi_fn_method_mobileclient_capabilities(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
    827 ): RustBuffer.ByValue
    828 fun uniffi_radroots_sdk_ffi_fn_method_mobileclient_close(`ptr`: Pointer,
    829 ): Long
    830 fun uniffi_radroots_sdk_ffi_fn_method_mobileclient_is_closed(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
    831 ): Byte
    832 fun uniffi_radroots_sdk_ffi_fn_func_parse_rhi_evidence_report(`canonicalContent`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
    833 ): RustBuffer.ByValue
    834 fun uniffi_radroots_sdk_ffi_fn_func_parse_trade_evidence_manifest(`canonicalBytes`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
    835 ): RustBuffer.ByValue
    836 fun uniffi_radroots_sdk_ffi_fn_func_prepare_rhi_evidence_attestation(`canonicalContent`: RustBuffer.ByValue,`createdAtUnixS`: Long,uniffi_out_err: UniffiRustCallStatus,
    837 ): RustBuffer.ByValue
    838 fun uniffi_radroots_sdk_ffi_fn_func_validate_rhi_evidence_attestation(`event`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
    839 ): RustBuffer.ByValue
    840 fun ffi_radroots_sdk_ffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
    841 ): RustBuffer.ByValue
    842 fun ffi_radroots_sdk_ffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
    843 ): RustBuffer.ByValue
    844 fun ffi_radroots_sdk_ffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
    845 ): Unit
    846 fun ffi_radroots_sdk_ffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
    847 ): RustBuffer.ByValue
    848 fun ffi_radroots_sdk_ffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    849 ): Unit
    850 fun ffi_radroots_sdk_ffi_rust_future_cancel_u8(`handle`: Long,
    851 ): Unit
    852 fun ffi_radroots_sdk_ffi_rust_future_free_u8(`handle`: Long,
    853 ): Unit
    854 fun ffi_radroots_sdk_ffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    855 ): Byte
    856 fun ffi_radroots_sdk_ffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    857 ): Unit
    858 fun ffi_radroots_sdk_ffi_rust_future_cancel_i8(`handle`: Long,
    859 ): Unit
    860 fun ffi_radroots_sdk_ffi_rust_future_free_i8(`handle`: Long,
    861 ): Unit
    862 fun ffi_radroots_sdk_ffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    863 ): Byte
    864 fun ffi_radroots_sdk_ffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    865 ): Unit
    866 fun ffi_radroots_sdk_ffi_rust_future_cancel_u16(`handle`: Long,
    867 ): Unit
    868 fun ffi_radroots_sdk_ffi_rust_future_free_u16(`handle`: Long,
    869 ): Unit
    870 fun ffi_radroots_sdk_ffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    871 ): Short
    872 fun ffi_radroots_sdk_ffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    873 ): Unit
    874 fun ffi_radroots_sdk_ffi_rust_future_cancel_i16(`handle`: Long,
    875 ): Unit
    876 fun ffi_radroots_sdk_ffi_rust_future_free_i16(`handle`: Long,
    877 ): Unit
    878 fun ffi_radroots_sdk_ffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    879 ): Short
    880 fun ffi_radroots_sdk_ffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    881 ): Unit
    882 fun ffi_radroots_sdk_ffi_rust_future_cancel_u32(`handle`: Long,
    883 ): Unit
    884 fun ffi_radroots_sdk_ffi_rust_future_free_u32(`handle`: Long,
    885 ): Unit
    886 fun ffi_radroots_sdk_ffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    887 ): Int
    888 fun ffi_radroots_sdk_ffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    889 ): Unit
    890 fun ffi_radroots_sdk_ffi_rust_future_cancel_i32(`handle`: Long,
    891 ): Unit
    892 fun ffi_radroots_sdk_ffi_rust_future_free_i32(`handle`: Long,
    893 ): Unit
    894 fun ffi_radroots_sdk_ffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    895 ): Int
    896 fun ffi_radroots_sdk_ffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    897 ): Unit
    898 fun ffi_radroots_sdk_ffi_rust_future_cancel_u64(`handle`: Long,
    899 ): Unit
    900 fun ffi_radroots_sdk_ffi_rust_future_free_u64(`handle`: Long,
    901 ): Unit
    902 fun ffi_radroots_sdk_ffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    903 ): Long
    904 fun ffi_radroots_sdk_ffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    905 ): Unit
    906 fun ffi_radroots_sdk_ffi_rust_future_cancel_i64(`handle`: Long,
    907 ): Unit
    908 fun ffi_radroots_sdk_ffi_rust_future_free_i64(`handle`: Long,
    909 ): Unit
    910 fun ffi_radroots_sdk_ffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    911 ): Long
    912 fun ffi_radroots_sdk_ffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    913 ): Unit
    914 fun ffi_radroots_sdk_ffi_rust_future_cancel_f32(`handle`: Long,
    915 ): Unit
    916 fun ffi_radroots_sdk_ffi_rust_future_free_f32(`handle`: Long,
    917 ): Unit
    918 fun ffi_radroots_sdk_ffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    919 ): Float
    920 fun ffi_radroots_sdk_ffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    921 ): Unit
    922 fun ffi_radroots_sdk_ffi_rust_future_cancel_f64(`handle`: Long,
    923 ): Unit
    924 fun ffi_radroots_sdk_ffi_rust_future_free_f64(`handle`: Long,
    925 ): Unit
    926 fun ffi_radroots_sdk_ffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    927 ): Double
    928 fun ffi_radroots_sdk_ffi_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    929 ): Unit
    930 fun ffi_radroots_sdk_ffi_rust_future_cancel_pointer(`handle`: Long,
    931 ): Unit
    932 fun ffi_radroots_sdk_ffi_rust_future_free_pointer(`handle`: Long,
    933 ): Unit
    934 fun ffi_radroots_sdk_ffi_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    935 ): Pointer
    936 fun ffi_radroots_sdk_ffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    937 ): Unit
    938 fun ffi_radroots_sdk_ffi_rust_future_cancel_rust_buffer(`handle`: Long,
    939 ): Unit
    940 fun ffi_radroots_sdk_ffi_rust_future_free_rust_buffer(`handle`: Long,
    941 ): Unit
    942 fun ffi_radroots_sdk_ffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    943 ): RustBuffer.ByValue
    944 fun ffi_radroots_sdk_ffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
    945 ): Unit
    946 fun ffi_radroots_sdk_ffi_rust_future_cancel_void(`handle`: Long,
    947 ): Unit
    948 fun ffi_radroots_sdk_ffi_rust_future_free_void(`handle`: Long,
    949 ): Unit
    950 fun ffi_radroots_sdk_ffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
    951 ): Unit
    952 
    953 }
    954 
    955 private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
    956     // Get the bindings contract version from our ComponentInterface
    957     val bindings_contract_version = 29
    958     // Get the scaffolding contract version by calling the into the dylib
    959     val scaffolding_contract_version = lib.ffi_radroots_sdk_ffi_uniffi_contract_version()
    960     if (bindings_contract_version != scaffolding_contract_version) {
    961         throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
    962     }
    963 }
    964 @Suppress("UNUSED_PARAMETER")
    965 private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
    966     if (lib.uniffi_radroots_sdk_ffi_checksum_func_parse_rhi_evidence_report() != 37549.toShort()) {
    967         throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    968     }
    969     if (lib.uniffi_radroots_sdk_ffi_checksum_func_parse_trade_evidence_manifest() != 35922.toShort()) {
    970         throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    971     }
    972     if (lib.uniffi_radroots_sdk_ffi_checksum_func_prepare_rhi_evidence_attestation() != 53127.toShort()) {
    973         throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    974     }
    975     if (lib.uniffi_radroots_sdk_ffi_checksum_func_validate_rhi_evidence_attestation() != 46555.toShort()) {
    976         throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    977     }
    978     if (lib.uniffi_radroots_sdk_ffi_checksum_method_mobileclient_capabilities() != 23938.toShort()) {
    979         throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    980     }
    981     if (lib.uniffi_radroots_sdk_ffi_checksum_method_mobileclient_close() != 15210.toShort()) {
    982         throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    983     }
    984     if (lib.uniffi_radroots_sdk_ffi_checksum_method_mobileclient_is_closed() != 40205.toShort()) {
    985         throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    986     }
    987     if (lib.uniffi_radroots_sdk_ffi_checksum_constructor_mobileclient_memory() != 50243.toShort()) {
    988         throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
    989     }
    990 }
    991 
    992 /**
    993  * @suppress
    994  */
    995 public fun uniffiEnsureInitialized() {
    996     UniffiLib.INSTANCE
    997 }
    998 
    999 // Async support
   1000 // Async return type handlers
   1001 
   1002 internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toByte()
   1003 internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toByte()
   1004 
   1005 internal val uniffiContinuationHandleMap = UniffiHandleMap<CancellableContinuation<Byte>>()
   1006 
   1007 // FFI type for Rust future continuations
   1008 internal object uniffiRustFutureContinuationCallbackImpl: UniffiRustFutureContinuationCallback {
   1009     override fun callback(data: Long, pollResult: Byte) {
   1010         uniffiContinuationHandleMap.remove(data).resume(pollResult)
   1011     }
   1012 }
   1013 
   1014 internal suspend fun<T, F, E: kotlin.Exception> uniffiRustCallAsync(
   1015     rustFuture: Long,
   1016     pollFunc: (Long, UniffiRustFutureContinuationCallback, Long) -> Unit,
   1017     completeFunc: (Long, UniffiRustCallStatus) -> F,
   1018     freeFunc: (Long) -> Unit,
   1019     liftFunc: (F) -> T,
   1020     errorHandler: UniffiRustCallStatusErrorHandler<E>
   1021 ): T {
   1022     try {
   1023         do {
   1024             val pollResult = suspendCancellableCoroutine<Byte> { continuation ->
   1025                 pollFunc(
   1026                     rustFuture,
   1027                     uniffiRustFutureContinuationCallbackImpl,
   1028                     uniffiContinuationHandleMap.insert(continuation)
   1029                 )
   1030             }
   1031         } while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY);
   1032 
   1033         return liftFunc(
   1034             uniffiRustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) })
   1035         )
   1036     } finally {
   1037         freeFunc(rustFuture)
   1038     }
   1039 }
   1040 
   1041 // Public interface members begin here.
   1042 
   1043 
   1044 // Interface implemented by anything that can contain an object reference.
   1045 //
   1046 // Such types expose a `destroy()` method that must be called to cleanly
   1047 // dispose of the contained objects. Failure to call this method may result
   1048 // in memory leaks.
   1049 //
   1050 // The easiest way to ensure this method is called is to use the `.use`
   1051 // helper method to execute a block and destroy the object at the end.
   1052 interface Disposable {
   1053     fun destroy()
   1054     companion object {
   1055         fun destroy(vararg args: Any?) {
   1056             for (arg in args) {
   1057                 when (arg) {
   1058                     is Disposable -> arg.destroy()
   1059                     is ArrayList<*> -> {
   1060                         for (idx in arg.indices) {
   1061                             val element = arg[idx]
   1062                             if (element is Disposable) {
   1063                                 element.destroy()
   1064                             }
   1065                         }
   1066                     }
   1067                     is Map<*, *> -> {
   1068                         for (element in arg.values) {
   1069                             if (element is Disposable) {
   1070                                 element.destroy()
   1071                             }
   1072                         }
   1073                     }
   1074                     is Iterable<*> -> {
   1075                         for (element in arg) {
   1076                             if (element is Disposable) {
   1077                                 element.destroy()
   1078                             }
   1079                         }
   1080                     }
   1081                 }
   1082             }
   1083         }
   1084     }
   1085 }
   1086 
   1087 /**
   1088  * @suppress
   1089  */
   1090 inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
   1091     try {
   1092         block(this)
   1093     } finally {
   1094         try {
   1095             // N.B. our implementation is on the nullable type `Disposable?`.
   1096             this?.destroy()
   1097         } catch (e: Throwable) {
   1098             // swallow
   1099         }
   1100     }
   1101 
   1102 /**
   1103  * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
   1104  *
   1105  * @suppress
   1106  * */
   1107 object NoPointer
   1108 /**
   1109  * The cleaner interface for Object finalization code to run.
   1110  * This is the entry point to any implementation that we're using.
   1111  *
   1112  * The cleaner registers objects and returns cleanables, so now we are
   1113  * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
   1114  * different implmentations available at compile time.
   1115  *
   1116  * @suppress
   1117  */
   1118 interface UniffiCleaner {
   1119     interface Cleanable {
   1120         fun clean()
   1121     }
   1122 
   1123     fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable
   1124 
   1125     companion object
   1126 }
   1127 
   1128 // The fallback Jna cleaner, which is available for both Android, and the JVM.
   1129 private class UniffiJnaCleaner : UniffiCleaner {
   1130     private val cleaner = com.sun.jna.internal.Cleaner.getCleaner()
   1131 
   1132     override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
   1133         UniffiJnaCleanable(cleaner.register(value, cleanUpTask))
   1134 }
   1135 
   1136 private class UniffiJnaCleanable(
   1137     private val cleanable: com.sun.jna.internal.Cleaner.Cleanable,
   1138 ) : UniffiCleaner.Cleanable {
   1139     override fun clean() = cleanable.clean()
   1140 }
   1141 
   1142 
   1143 // We decide at uniffi binding generation time whether we were
   1144 // using Android or not.
   1145 // There are further runtime checks to chose the correct implementation
   1146 // of the cleaner.
   1147 private fun UniffiCleaner.Companion.create(): UniffiCleaner =
   1148     try {
   1149         // For safety's sake: if the library hasn't been run in android_cleaner = true
   1150         // mode, but is being run on Android, then we still need to think about
   1151         // Android API versions.
   1152         // So we check if java.lang.ref.Cleaner is there, and use that…
   1153         java.lang.Class.forName("java.lang.ref.Cleaner")
   1154         JavaLangRefCleaner()
   1155     } catch (e: ClassNotFoundException) {
   1156         // … otherwise, fallback to the JNA cleaner.
   1157         UniffiJnaCleaner()
   1158     }
   1159 
   1160 private class JavaLangRefCleaner : UniffiCleaner {
   1161     val cleaner = java.lang.ref.Cleaner.create()
   1162 
   1163     override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
   1164         JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
   1165 }
   1166 
   1167 private class JavaLangRefCleanable(
   1168     val cleanable: java.lang.ref.Cleaner.Cleanable
   1169 ) : UniffiCleaner.Cleanable {
   1170     override fun clean() = cleanable.clean()
   1171 }
   1172 
   1173 /**
   1174  * @suppress
   1175  */
   1176 public object FfiConverterUShort: FfiConverter<UShort, Short> {
   1177     override fun lift(value: Short): UShort {
   1178         return value.toUShort()
   1179     }
   1180 
   1181     override fun read(buf: ByteBuffer): UShort {
   1182         return lift(buf.getShort())
   1183     }
   1184 
   1185     override fun lower(value: UShort): Short {
   1186         return value.toShort()
   1187     }
   1188 
   1189     override fun allocationSize(value: UShort) = 2UL
   1190 
   1191     override fun write(value: UShort, buf: ByteBuffer) {
   1192         buf.putShort(value.toShort())
   1193     }
   1194 }
   1195 
   1196 /**
   1197  * @suppress
   1198  */
   1199 public object FfiConverterUInt: FfiConverter<UInt, Int> {
   1200     override fun lift(value: Int): UInt {
   1201         return value.toUInt()
   1202     }
   1203 
   1204     override fun read(buf: ByteBuffer): UInt {
   1205         return lift(buf.getInt())
   1206     }
   1207 
   1208     override fun lower(value: UInt): Int {
   1209         return value.toInt()
   1210     }
   1211 
   1212     override fun allocationSize(value: UInt) = 4UL
   1213 
   1214     override fun write(value: UInt, buf: ByteBuffer) {
   1215         buf.putInt(value.toInt())
   1216     }
   1217 }
   1218 
   1219 /**
   1220  * @suppress
   1221  */
   1222 public object FfiConverterULong: FfiConverter<ULong, Long> {
   1223     override fun lift(value: Long): ULong {
   1224         return value.toULong()
   1225     }
   1226 
   1227     override fun read(buf: ByteBuffer): ULong {
   1228         return lift(buf.getLong())
   1229     }
   1230 
   1231     override fun lower(value: ULong): Long {
   1232         return value.toLong()
   1233     }
   1234 
   1235     override fun allocationSize(value: ULong) = 8UL
   1236 
   1237     override fun write(value: ULong, buf: ByteBuffer) {
   1238         buf.putLong(value.toLong())
   1239     }
   1240 }
   1241 
   1242 /**
   1243  * @suppress
   1244  */
   1245 public object FfiConverterBoolean: FfiConverter<Boolean, Byte> {
   1246     override fun lift(value: Byte): Boolean {
   1247         return value.toInt() != 0
   1248     }
   1249 
   1250     override fun read(buf: ByteBuffer): Boolean {
   1251         return lift(buf.get())
   1252     }
   1253 
   1254     override fun lower(value: Boolean): Byte {
   1255         return if (value) 1.toByte() else 0.toByte()
   1256     }
   1257 
   1258     override fun allocationSize(value: Boolean) = 1UL
   1259 
   1260     override fun write(value: Boolean, buf: ByteBuffer) {
   1261         buf.put(lower(value))
   1262     }
   1263 }
   1264 
   1265 /**
   1266  * @suppress
   1267  */
   1268 public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
   1269     // Note: we don't inherit from FfiConverterRustBuffer, because we use a
   1270     // special encoding when lowering/lifting.  We can use `RustBuffer.len` to
   1271     // store our length and avoid writing it out to the buffer.
   1272     override fun lift(value: RustBuffer.ByValue): String {
   1273         try {
   1274             val byteArr = ByteArray(value.len.toInt())
   1275             value.asByteBuffer()!!.get(byteArr)
   1276             return byteArr.toString(Charsets.UTF_8)
   1277         } finally {
   1278             RustBuffer.free(value)
   1279         }
   1280     }
   1281 
   1282     override fun read(buf: ByteBuffer): String {
   1283         val len = buf.getInt()
   1284         val byteArr = ByteArray(len)
   1285         buf.get(byteArr)
   1286         return byteArr.toString(Charsets.UTF_8)
   1287     }
   1288 
   1289     fun toUtf8(value: String): ByteBuffer {
   1290         // Make sure we don't have invalid UTF-16, check for lone surrogates.
   1291         return Charsets.UTF_8.newEncoder().run {
   1292             onMalformedInput(CodingErrorAction.REPORT)
   1293             encode(CharBuffer.wrap(value))
   1294         }
   1295     }
   1296 
   1297     override fun lower(value: String): RustBuffer.ByValue {
   1298         val byteBuf = toUtf8(value)
   1299         // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
   1300         // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
   1301         val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
   1302         rbuf.asByteBuffer()!!.put(byteBuf)
   1303         return rbuf
   1304     }
   1305 
   1306     // We aren't sure exactly how many bytes our string will be once it's UTF-8
   1307     // encoded.  Allocate 3 bytes per UTF-16 code unit which will always be
   1308     // enough.
   1309     override fun allocationSize(value: String): ULong {
   1310         val sizeForLength = 4UL
   1311         val sizeForString = value.length.toULong() * 3UL
   1312         return sizeForLength + sizeForString
   1313     }
   1314 
   1315     override fun write(value: String, buf: ByteBuffer) {
   1316         val byteBuf = toUtf8(value)
   1317         buf.putInt(byteBuf.limit())
   1318         buf.put(byteBuf)
   1319     }
   1320 }
   1321 
   1322 /**
   1323  * @suppress
   1324  */
   1325 public object FfiConverterByteArray: FfiConverterRustBuffer<ByteArray> {
   1326     override fun read(buf: ByteBuffer): ByteArray {
   1327         val len = buf.getInt()
   1328         val byteArr = ByteArray(len)
   1329         buf.get(byteArr)
   1330         return byteArr
   1331     }
   1332     override fun allocationSize(value: ByteArray): ULong {
   1333         return 4UL + value.size.toULong()
   1334     }
   1335     override fun write(value: ByteArray, buf: ByteBuffer) {
   1336         buf.putInt(value.size)
   1337         buf.put(value)
   1338     }
   1339 }
   1340 
   1341 
   1342 // This template implements a class for working with a Rust struct via a Pointer/Arc<T>
   1343 // to the live Rust struct on the other side of the FFI.
   1344 //
   1345 // Each instance implements core operations for working with the Rust `Arc<T>` and the
   1346 // Kotlin Pointer to work with the live Rust struct on the other side of the FFI.
   1347 //
   1348 // There's some subtlety here, because we have to be careful not to operate on a Rust
   1349 // struct after it has been dropped, and because we must expose a public API for freeing
   1350 // theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
   1351 //
   1352 //   * Each instance holds an opaque pointer to the underlying Rust struct.
   1353 //     Method calls need to read this pointer from the object's state and pass it in to
   1354 //     the Rust FFI.
   1355 //
   1356 //   * When an instance is no longer needed, its pointer should be passed to a
   1357 //     special destructor function provided by the Rust FFI, which will drop the
   1358 //     underlying Rust struct.
   1359 //
   1360 //   * Given an instance, calling code is expected to call the special
   1361 //     `destroy` method in order to free it after use, either by calling it explicitly
   1362 //     or by using a higher-level helper like the `use` method. Failing to do so risks
   1363 //     leaking the underlying Rust struct.
   1364 //
   1365 //   * We can't assume that calling code will do the right thing, and must be prepared
   1366 //     to handle Kotlin method calls executing concurrently with or even after a call to
   1367 //     `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
   1368 //
   1369 //   * We must never allow Rust code to operate on the underlying Rust struct after
   1370 //     the destructor has been called, and must never call the destructor more than once.
   1371 //     Doing so may trigger memory unsafety.
   1372 //
   1373 //   * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
   1374 //     is implemented to call the destructor when the Kotlin object becomes unreachable.
   1375 //     This is done in a background thread. This is not a panacea, and client code should be aware that
   1376 //      1. the thread may starve if some there are objects that have poorly performing
   1377 //     `drop` methods or do significant work in their `drop` methods.
   1378 //      2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
   1379 //         or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
   1380 //
   1381 // If we try to implement this with mutual exclusion on access to the pointer, there is the
   1382 // possibility of a race between a method call and a concurrent call to `destroy`:
   1383 //
   1384 //    * Thread A starts a method call, reads the value of the pointer, but is interrupted
   1385 //      before it can pass the pointer over the FFI to Rust.
   1386 //    * Thread B calls `destroy` and frees the underlying Rust struct.
   1387 //    * Thread A resumes, passing the already-read pointer value to Rust and triggering
   1388 //      a use-after-free.
   1389 //
   1390 // One possible solution would be to use a `ReadWriteLock`, with each method call taking
   1391 // a read lock (and thus allowed to run concurrently) and the special `destroy` method
   1392 // taking a write lock (and thus blocking on live method calls). However, we aim not to
   1393 // generate methods with any hidden blocking semantics, and a `destroy` method that might
   1394 // block if called incorrectly seems to meet that bar.
   1395 //
   1396 // So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
   1397 // the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
   1398 // has been called. These are updated according to the following rules:
   1399 //
   1400 //    * The initial value of the counter is 1, indicating a live object with no in-flight calls.
   1401 //      The initial value for the flag is false.
   1402 //
   1403 //    * At the start of each method call, we atomically check the counter.
   1404 //      If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
   1405 //      If it is nonzero them we atomically increment it by 1 and proceed with the method call.
   1406 //
   1407 //    * At the end of each method call, we atomically decrement and check the counter.
   1408 //      If it has reached zero then we destroy the underlying Rust struct.
   1409 //
   1410 //    * When `destroy` is called, we atomically flip the flag from false to true.
   1411 //      If the flag was already true we silently fail.
   1412 //      Otherwise we atomically decrement and check the counter.
   1413 //      If it has reached zero then we destroy the underlying Rust struct.
   1414 //
   1415 // Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
   1416 // and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
   1417 //
   1418 // The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
   1419 // called *and* all in-flight method calls have completed, avoiding violating any of the expectations
   1420 // of the underlying Rust code.
   1421 //
   1422 // This makes a cleaner a better alternative to _not_ calling `destroy()` as
   1423 // and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
   1424 // method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
   1425 // thread may be starved, and the app will leak memory.
   1426 //
   1427 // In this case, `destroy`ing manually may be a better solution.
   1428 //
   1429 // The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
   1430 // with Rust peers are reclaimed:
   1431 //
   1432 // 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
   1433 // 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
   1434 // 3. The memory is reclaimed when the process terminates.
   1435 //
   1436 // [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
   1437 //
   1438 
   1439 
   1440 /**
   1441  * Thread-safe mobile handle delegating lifecycle to [`radroots_sdk::Client`].
   1442  */
   1443 public interface MobileClientInterface {
   1444 
   1445     /**
   1446      * Returns stable capability DTOs without probing host resources.
   1447      */
   1448     fun `capabilities`(): List<CapabilityStatus>
   1449 
   1450     /**
   1451      * Explicitly closes SDK-owned resources without installing a runtime.
   1452      */
   1453     suspend fun `close`()
   1454 
   1455     /**
   1456      * Returns whether explicit SDK close completed across all clones.
   1457      */
   1458     fun `isClosed`(): kotlin.Boolean
   1459 
   1460     companion object
   1461 }
   1462 
   1463 /**
   1464  * Thread-safe mobile handle delegating lifecycle to [`radroots_sdk::Client`].
   1465  */
   1466 open class MobileClient: Disposable, AutoCloseable, MobileClientInterface
   1467 {
   1468 
   1469     constructor(pointer: Pointer) {
   1470         this.pointer = pointer
   1471         this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
   1472     }
   1473 
   1474     /**
   1475      * This constructor can be used to instantiate a fake object. Only used for tests. Any
   1476      * attempt to actually use an object constructed this way will fail as there is no
   1477      * connected Rust object.
   1478      */
   1479     @Suppress("UNUSED_PARAMETER")
   1480     constructor(noPointer: NoPointer) {
   1481         this.pointer = null
   1482         this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
   1483     }
   1484 
   1485     protected val pointer: Pointer?
   1486     protected val cleanable: UniffiCleaner.Cleanable
   1487 
   1488     private val wasDestroyed = AtomicBoolean(false)
   1489     private val callCounter = AtomicLong(1)
   1490 
   1491     override fun destroy() {
   1492         // Only allow a single call to this method.
   1493         // TODO: maybe we should log a warning if called more than once?
   1494         if (this.wasDestroyed.compareAndSet(false, true)) {
   1495             // This decrement always matches the initial count of 1 given at creation time.
   1496             if (this.callCounter.decrementAndGet() == 0L) {
   1497                 cleanable.clean()
   1498             }
   1499         }
   1500     }
   1501 
   1502     @Synchronized
   1503     override fun close() {
   1504         this.destroy()
   1505     }
   1506 
   1507     internal inline fun <R> callWithPointer(block: (ptr: Pointer) -> R): R {
   1508         // Check and increment the call counter, to keep the object alive.
   1509         // This needs a compare-and-set retry loop in case of concurrent updates.
   1510         do {
   1511             val c = this.callCounter.get()
   1512             if (c == 0L) {
   1513                 throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
   1514             }
   1515             if (c == Long.MAX_VALUE) {
   1516                 throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
   1517             }
   1518         } while (! this.callCounter.compareAndSet(c, c + 1L))
   1519         // Now we can safely do the method call without the pointer being freed concurrently.
   1520         try {
   1521             return block(this.uniffiClonePointer())
   1522         } finally {
   1523             // This decrement always matches the increment we performed above.
   1524             if (this.callCounter.decrementAndGet() == 0L) {
   1525                 cleanable.clean()
   1526             }
   1527         }
   1528     }
   1529 
   1530     // Use a static inner class instead of a closure so as not to accidentally
   1531     // capture `this` as part of the cleanable's action.
   1532     private class UniffiCleanAction(private val pointer: Pointer?) : Runnable {
   1533         override fun run() {
   1534             pointer?.let { ptr ->
   1535                 uniffiRustCall { status ->
   1536                     UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_free_mobileclient(ptr, status)
   1537                 }
   1538             }
   1539         }
   1540     }
   1541 
   1542     fun uniffiClonePointer(): Pointer {
   1543         return uniffiRustCall() { status ->
   1544             UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_clone_mobileclient(pointer!!, status)
   1545         }
   1546     }
   1547 
   1548 
   1549     /**
   1550      * Returns stable capability DTOs without probing host resources.
   1551      */override fun `capabilities`(): List<CapabilityStatus> {
   1552             return FfiConverterSequenceTypeCapabilityStatus.lift(
   1553     callWithPointer {
   1554     uniffiRustCall() { _status ->
   1555     UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_method_mobileclient_capabilities(
   1556         it, _status)
   1557 }
   1558     }
   1559     )
   1560     }
   1561 
   1562 
   1563 
   1564     /**
   1565      * Explicitly closes SDK-owned resources without installing a runtime.
   1566      */
   1567     @Throws(Exception::class)
   1568     @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
   1569     override suspend fun `close`() {
   1570         return uniffiRustCallAsync(
   1571         callWithPointer { thisPtr ->
   1572             UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_method_mobileclient_close(
   1573                 thisPtr,
   1574 
   1575             )
   1576         },
   1577         { future, callback, continuation -> UniffiLib.INSTANCE.ffi_radroots_sdk_ffi_rust_future_poll_void(future, callback, continuation) },
   1578         { future, continuation -> UniffiLib.INSTANCE.ffi_radroots_sdk_ffi_rust_future_complete_void(future, continuation) },
   1579         { future -> UniffiLib.INSTANCE.ffi_radroots_sdk_ffi_rust_future_free_void(future) },
   1580         // lift function
   1581         { Unit },
   1582 
   1583         // Error FFI converter
   1584         Exception.ErrorHandler,
   1585     )
   1586     }
   1587 
   1588 
   1589     /**
   1590      * Returns whether explicit SDK close completed across all clones.
   1591      */override fun `isClosed`(): kotlin.Boolean {
   1592             return FfiConverterBoolean.lift(
   1593     callWithPointer {
   1594     uniffiRustCall() { _status ->
   1595     UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_method_mobileclient_is_closed(
   1596         it, _status)
   1597 }
   1598     }
   1599     )
   1600     }
   1601 
   1602 
   1603 
   1604 
   1605 
   1606     companion object {
   1607 
   1608     /**
   1609      * Creates a deterministic, local-only memory client without I/O.
   1610      */
   1611     @Throws(Exception::class) fun `memory`(): MobileClient {
   1612             return FfiConverterTypeMobileClient.lift(
   1613     uniffiRustCallWithError(Exception) { _status ->
   1614     UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_constructor_mobileclient_memory(
   1615         _status)
   1616 }
   1617     )
   1618     }
   1619 
   1620 
   1621 
   1622     }
   1623 
   1624 }
   1625 
   1626 /**
   1627  * @suppress
   1628  */
   1629 public object FfiConverterTypeMobileClient: FfiConverter<MobileClient, Pointer> {
   1630 
   1631     override fun lower(value: MobileClient): Pointer {
   1632         return value.uniffiClonePointer()
   1633     }
   1634 
   1635     override fun lift(value: Pointer): MobileClient {
   1636         return MobileClient(value)
   1637     }
   1638 
   1639     override fun read(buf: ByteBuffer): MobileClient {
   1640         // The Rust code always writes pointers as 8 bytes, and will
   1641         // fail to compile if they don't fit.
   1642         return lift(Pointer(buf.getLong()))
   1643     }
   1644 
   1645     override fun allocationSize(value: MobileClient) = 8UL
   1646 
   1647     override fun write(value: MobileClient, buf: ByteBuffer) {
   1648         // The Rust code always expects pointers written as 8 bytes,
   1649         // and will fail to compile if they don't fit.
   1650         buf.putLong(Pointer.nativeValue(lower(value)))
   1651     }
   1652 }
   1653 
   1654 
   1655 
   1656 /**
   1657  * Versioned, presentation-independent capability observation.
   1658  */
   1659 data class CapabilityStatus (
   1660     var `id`: kotlin.String,
   1661     var `compiled`: kotlin.Boolean,
   1662     var `configured`: kotlin.Boolean,
   1663     var `availability`: CapabilityAvailability,
   1664     var `maturity`: CapabilityMaturity
   1665 ) {
   1666 
   1667     companion object
   1668 }
   1669 
   1670 /**
   1671  * @suppress
   1672  */
   1673 public object FfiConverterTypeCapabilityStatus: FfiConverterRustBuffer<CapabilityStatus> {
   1674     override fun read(buf: ByteBuffer): CapabilityStatus {
   1675         return CapabilityStatus(
   1676             FfiConverterString.read(buf),
   1677             FfiConverterBoolean.read(buf),
   1678             FfiConverterBoolean.read(buf),
   1679             FfiConverterTypeCapabilityAvailability.read(buf),
   1680             FfiConverterTypeCapabilityMaturity.read(buf),
   1681         )
   1682     }
   1683 
   1684     override fun allocationSize(value: CapabilityStatus) = (
   1685             FfiConverterString.allocationSize(value.`id`) +
   1686             FfiConverterBoolean.allocationSize(value.`compiled`) +
   1687             FfiConverterBoolean.allocationSize(value.`configured`) +
   1688             FfiConverterTypeCapabilityAvailability.allocationSize(value.`availability`) +
   1689             FfiConverterTypeCapabilityMaturity.allocationSize(value.`maturity`)
   1690     )
   1691 
   1692     override fun write(value: CapabilityStatus, buf: ByteBuffer) {
   1693             FfiConverterString.write(value.`id`, buf)
   1694             FfiConverterBoolean.write(value.`compiled`, buf)
   1695             FfiConverterBoolean.write(value.`configured`, buf)
   1696             FfiConverterTypeCapabilityAvailability.write(value.`availability`, buf)
   1697             FfiConverterTypeCapabilityMaturity.write(value.`maturity`, buf)
   1698     }
   1699 }
   1700 
   1701 
   1702 
   1703 /**
   1704  * Verified final RHI attestation projection.
   1705  */
   1706 data class RhiEvidenceAttestation (
   1707     var `issuerPubkey`: kotlin.String,
   1708     var `tradeId`: kotlin.String,
   1709     var `claimMutationId`: kotlin.String,
   1710     var `outcome`: TradeEvidenceOutcome,
   1711     var `observedAtUnixS`: kotlin.String,
   1712     var `tradeGeneration`: kotlin.String,
   1713     var `statementDigest`: kotlin.String,
   1714     var `supersession`: RhiEvidenceSupersession?,
   1715     var `canonicalContent`: kotlin.String
   1716 ) {
   1717 
   1718     companion object
   1719 }
   1720 
   1721 /**
   1722  * @suppress
   1723  */
   1724 public object FfiConverterTypeRhiEvidenceAttestation: FfiConverterRustBuffer<RhiEvidenceAttestation> {
   1725     override fun read(buf: ByteBuffer): RhiEvidenceAttestation {
   1726         return RhiEvidenceAttestation(
   1727             FfiConverterString.read(buf),
   1728             FfiConverterString.read(buf),
   1729             FfiConverterString.read(buf),
   1730             FfiConverterTypeTradeEvidenceOutcome.read(buf),
   1731             FfiConverterString.read(buf),
   1732             FfiConverterString.read(buf),
   1733             FfiConverterString.read(buf),
   1734             FfiConverterOptionalTypeRhiEvidenceSupersession.read(buf),
   1735             FfiConverterString.read(buf),
   1736         )
   1737     }
   1738 
   1739     override fun allocationSize(value: RhiEvidenceAttestation) = (
   1740             FfiConverterString.allocationSize(value.`issuerPubkey`) +
   1741             FfiConverterString.allocationSize(value.`tradeId`) +
   1742             FfiConverterString.allocationSize(value.`claimMutationId`) +
   1743             FfiConverterTypeTradeEvidenceOutcome.allocationSize(value.`outcome`) +
   1744             FfiConverterString.allocationSize(value.`observedAtUnixS`) +
   1745             FfiConverterString.allocationSize(value.`tradeGeneration`) +
   1746             FfiConverterString.allocationSize(value.`statementDigest`) +
   1747             FfiConverterOptionalTypeRhiEvidenceSupersession.allocationSize(value.`supersession`) +
   1748             FfiConverterString.allocationSize(value.`canonicalContent`)
   1749     )
   1750 
   1751     override fun write(value: RhiEvidenceAttestation, buf: ByteBuffer) {
   1752             FfiConverterString.write(value.`issuerPubkey`, buf)
   1753             FfiConverterString.write(value.`tradeId`, buf)
   1754             FfiConverterString.write(value.`claimMutationId`, buf)
   1755             FfiConverterTypeTradeEvidenceOutcome.write(value.`outcome`, buf)
   1756             FfiConverterString.write(value.`observedAtUnixS`, buf)
   1757             FfiConverterString.write(value.`tradeGeneration`, buf)
   1758             FfiConverterString.write(value.`statementDigest`, buf)
   1759             FfiConverterOptionalTypeRhiEvidenceSupersession.write(value.`supersession`, buf)
   1760             FfiConverterString.write(value.`canonicalContent`, buf)
   1761     }
   1762 }
   1763 
   1764 
   1765 
   1766 /**
   1767  * Bounded projection of one canonical RHI evidence report.
   1768  */
   1769 data class RhiEvidenceReport (
   1770     var `contractId`: kotlin.String,
   1771     var `contractVersion`: kotlin.UShort,
   1772     var `issuerPubkey`: kotlin.String,
   1773     var `tradeId`: kotlin.String,
   1774     var `claimMutationId`: kotlin.String,
   1775     var `outcome`: TradeEvidenceOutcome,
   1776     var `reasonCodes`: List<kotlin.String>,
   1777     var `projectionDigest`: kotlin.String,
   1778     var `evidenceManifestDigest`: kotlin.String,
   1779     var `evidencePolicyDigest`: kotlin.String,
   1780     var `observedAtUnixS`: kotlin.String,
   1781     var `tradeGeneration`: kotlin.String,
   1782     var `statementDigest`: kotlin.String,
   1783     var `supersession`: RhiEvidenceSupersession?,
   1784     var `canonicalContent`: kotlin.String
   1785 ) {
   1786 
   1787     companion object
   1788 }
   1789 
   1790 /**
   1791  * @suppress
   1792  */
   1793 public object FfiConverterTypeRhiEvidenceReport: FfiConverterRustBuffer<RhiEvidenceReport> {
   1794     override fun read(buf: ByteBuffer): RhiEvidenceReport {
   1795         return RhiEvidenceReport(
   1796             FfiConverterString.read(buf),
   1797             FfiConverterUShort.read(buf),
   1798             FfiConverterString.read(buf),
   1799             FfiConverterString.read(buf),
   1800             FfiConverterString.read(buf),
   1801             FfiConverterTypeTradeEvidenceOutcome.read(buf),
   1802             FfiConverterSequenceString.read(buf),
   1803             FfiConverterString.read(buf),
   1804             FfiConverterString.read(buf),
   1805             FfiConverterString.read(buf),
   1806             FfiConverterString.read(buf),
   1807             FfiConverterString.read(buf),
   1808             FfiConverterString.read(buf),
   1809             FfiConverterOptionalTypeRhiEvidenceSupersession.read(buf),
   1810             FfiConverterString.read(buf),
   1811         )
   1812     }
   1813 
   1814     override fun allocationSize(value: RhiEvidenceReport) = (
   1815             FfiConverterString.allocationSize(value.`contractId`) +
   1816             FfiConverterUShort.allocationSize(value.`contractVersion`) +
   1817             FfiConverterString.allocationSize(value.`issuerPubkey`) +
   1818             FfiConverterString.allocationSize(value.`tradeId`) +
   1819             FfiConverterString.allocationSize(value.`claimMutationId`) +
   1820             FfiConverterTypeTradeEvidenceOutcome.allocationSize(value.`outcome`) +
   1821             FfiConverterSequenceString.allocationSize(value.`reasonCodes`) +
   1822             FfiConverterString.allocationSize(value.`projectionDigest`) +
   1823             FfiConverterString.allocationSize(value.`evidenceManifestDigest`) +
   1824             FfiConverterString.allocationSize(value.`evidencePolicyDigest`) +
   1825             FfiConverterString.allocationSize(value.`observedAtUnixS`) +
   1826             FfiConverterString.allocationSize(value.`tradeGeneration`) +
   1827             FfiConverterString.allocationSize(value.`statementDigest`) +
   1828             FfiConverterOptionalTypeRhiEvidenceSupersession.allocationSize(value.`supersession`) +
   1829             FfiConverterString.allocationSize(value.`canonicalContent`)
   1830     )
   1831 
   1832     override fun write(value: RhiEvidenceReport, buf: ByteBuffer) {
   1833             FfiConverterString.write(value.`contractId`, buf)
   1834             FfiConverterUShort.write(value.`contractVersion`, buf)
   1835             FfiConverterString.write(value.`issuerPubkey`, buf)
   1836             FfiConverterString.write(value.`tradeId`, buf)
   1837             FfiConverterString.write(value.`claimMutationId`, buf)
   1838             FfiConverterTypeTradeEvidenceOutcome.write(value.`outcome`, buf)
   1839             FfiConverterSequenceString.write(value.`reasonCodes`, buf)
   1840             FfiConverterString.write(value.`projectionDigest`, buf)
   1841             FfiConverterString.write(value.`evidenceManifestDigest`, buf)
   1842             FfiConverterString.write(value.`evidencePolicyDigest`, buf)
   1843             FfiConverterString.write(value.`observedAtUnixS`, buf)
   1844             FfiConverterString.write(value.`tradeGeneration`, buf)
   1845             FfiConverterString.write(value.`statementDigest`, buf)
   1846             FfiConverterOptionalTypeRhiEvidenceSupersession.write(value.`supersession`, buf)
   1847             FfiConverterString.write(value.`canonicalContent`, buf)
   1848     }
   1849 }
   1850 
   1851 
   1852 
   1853 /**
   1854  * Exact immutable RHI supersession reference.
   1855  */
   1856 data class RhiEvidenceSupersession (
   1857     var `reportId`: kotlin.String,
   1858     var `eventId`: kotlin.String
   1859 ) {
   1860 
   1861     companion object
   1862 }
   1863 
   1864 /**
   1865  * @suppress
   1866  */
   1867 public object FfiConverterTypeRhiEvidenceSupersession: FfiConverterRustBuffer<RhiEvidenceSupersession> {
   1868     override fun read(buf: ByteBuffer): RhiEvidenceSupersession {
   1869         return RhiEvidenceSupersession(
   1870             FfiConverterString.read(buf),
   1871             FfiConverterString.read(buf),
   1872         )
   1873     }
   1874 
   1875     override fun allocationSize(value: RhiEvidenceSupersession) = (
   1876             FfiConverterString.allocationSize(value.`reportId`) +
   1877             FfiConverterString.allocationSize(value.`eventId`)
   1878     )
   1879 
   1880     override fun write(value: RhiEvidenceSupersession, buf: ByteBuffer) {
   1881             FfiConverterString.write(value.`reportId`, buf)
   1882             FfiConverterString.write(value.`eventId`, buf)
   1883     }
   1884 }
   1885 
   1886 
   1887 
   1888 /**
   1889  * Signed NIP-01 event input for verified attestation admission.
   1890  */
   1891 data class SignedEvent (
   1892     var `id`: kotlin.String,
   1893     var `authorPubkey`: kotlin.String,
   1894     var `createdAtUnixS`: kotlin.ULong,
   1895     var `kind`: kotlin.UInt,
   1896     var `tags`: List<List<kotlin.String>>,
   1897     var `content`: kotlin.String,
   1898     var `signature`: kotlin.String
   1899 ) {
   1900 
   1901     companion object
   1902 }
   1903 
   1904 /**
   1905  * @suppress
   1906  */
   1907 public object FfiConverterTypeSignedEvent: FfiConverterRustBuffer<SignedEvent> {
   1908     override fun read(buf: ByteBuffer): SignedEvent {
   1909         return SignedEvent(
   1910             FfiConverterString.read(buf),
   1911             FfiConverterString.read(buf),
   1912             FfiConverterULong.read(buf),
   1913             FfiConverterUInt.read(buf),
   1914             FfiConverterSequenceSequenceString.read(buf),
   1915             FfiConverterString.read(buf),
   1916             FfiConverterString.read(buf),
   1917         )
   1918     }
   1919 
   1920     override fun allocationSize(value: SignedEvent) = (
   1921             FfiConverterString.allocationSize(value.`id`) +
   1922             FfiConverterString.allocationSize(value.`authorPubkey`) +
   1923             FfiConverterULong.allocationSize(value.`createdAtUnixS`) +
   1924             FfiConverterUInt.allocationSize(value.`kind`) +
   1925             FfiConverterSequenceSequenceString.allocationSize(value.`tags`) +
   1926             FfiConverterString.allocationSize(value.`content`) +
   1927             FfiConverterString.allocationSize(value.`signature`)
   1928     )
   1929 
   1930     override fun write(value: SignedEvent, buf: ByteBuffer) {
   1931             FfiConverterString.write(value.`id`, buf)
   1932             FfiConverterString.write(value.`authorPubkey`, buf)
   1933             FfiConverterULong.write(value.`createdAtUnixS`, buf)
   1934             FfiConverterUInt.write(value.`kind`, buf)
   1935             FfiConverterSequenceSequenceString.write(value.`tags`, buf)
   1936             FfiConverterString.write(value.`content`, buf)
   1937             FfiConverterString.write(value.`signature`, buf)
   1938     }
   1939 }
   1940 
   1941 
   1942 
   1943 /**
   1944  * Bounded projection of one canonical evidence manifest.
   1945  */
   1946 data class TradeEvidenceManifest (
   1947     var `contractId`: kotlin.String,
   1948     var `contractVersion`: kotlin.UShort,
   1949     var `tradeId`: kotlin.String,
   1950     var `tradeGeneration`: kotlin.String,
   1951     var `observedAtUnixS`: kotlin.String,
   1952     var `coverage`: TradeEvidenceCoverage,
   1953     var `evidencePolicyDigest`: kotlin.String,
   1954     var `manifestDigest`: kotlin.String,
   1955     var `canonicalBytesHex`: kotlin.String
   1956 ) {
   1957 
   1958     companion object
   1959 }
   1960 
   1961 /**
   1962  * @suppress
   1963  */
   1964 public object FfiConverterTypeTradeEvidenceManifest: FfiConverterRustBuffer<TradeEvidenceManifest> {
   1965     override fun read(buf: ByteBuffer): TradeEvidenceManifest {
   1966         return TradeEvidenceManifest(
   1967             FfiConverterString.read(buf),
   1968             FfiConverterUShort.read(buf),
   1969             FfiConverterString.read(buf),
   1970             FfiConverterString.read(buf),
   1971             FfiConverterString.read(buf),
   1972             FfiConverterTypeTradeEvidenceCoverage.read(buf),
   1973             FfiConverterString.read(buf),
   1974             FfiConverterString.read(buf),
   1975             FfiConverterString.read(buf),
   1976         )
   1977     }
   1978 
   1979     override fun allocationSize(value: TradeEvidenceManifest) = (
   1980             FfiConverterString.allocationSize(value.`contractId`) +
   1981             FfiConverterUShort.allocationSize(value.`contractVersion`) +
   1982             FfiConverterString.allocationSize(value.`tradeId`) +
   1983             FfiConverterString.allocationSize(value.`tradeGeneration`) +
   1984             FfiConverterString.allocationSize(value.`observedAtUnixS`) +
   1985             FfiConverterTypeTradeEvidenceCoverage.allocationSize(value.`coverage`) +
   1986             FfiConverterString.allocationSize(value.`evidencePolicyDigest`) +
   1987             FfiConverterString.allocationSize(value.`manifestDigest`) +
   1988             FfiConverterString.allocationSize(value.`canonicalBytesHex`)
   1989     )
   1990 
   1991     override fun write(value: TradeEvidenceManifest, buf: ByteBuffer) {
   1992             FfiConverterString.write(value.`contractId`, buf)
   1993             FfiConverterUShort.write(value.`contractVersion`, buf)
   1994             FfiConverterString.write(value.`tradeId`, buf)
   1995             FfiConverterString.write(value.`tradeGeneration`, buf)
   1996             FfiConverterString.write(value.`observedAtUnixS`, buf)
   1997             FfiConverterTypeTradeEvidenceCoverage.write(value.`coverage`, buf)
   1998             FfiConverterString.write(value.`evidencePolicyDigest`, buf)
   1999             FfiConverterString.write(value.`manifestDigest`, buf)
   2000             FfiConverterString.write(value.`canonicalBytesHex`, buf)
   2001     }
   2002 }
   2003 
   2004 
   2005 
   2006 /**
   2007  * One unsigned typed event plan ready for host-owned signing.
   2008  */
   2009 data class TypedEvidenceEventPlan (
   2010     var `contractId`: kotlin.String,
   2011     var `kind`: kotlin.UInt,
   2012     var `authorPubkey`: kotlin.String,
   2013     var `createdAtUnixS`: kotlin.String,
   2014     var `expectedEventId`: kotlin.String,
   2015     var `tags`: List<List<kotlin.String>>,
   2016     var `content`: kotlin.String
   2017 ) {
   2018 
   2019     companion object
   2020 }
   2021 
   2022 /**
   2023  * @suppress
   2024  */
   2025 public object FfiConverterTypeTypedEvidenceEventPlan: FfiConverterRustBuffer<TypedEvidenceEventPlan> {
   2026     override fun read(buf: ByteBuffer): TypedEvidenceEventPlan {
   2027         return TypedEvidenceEventPlan(
   2028             FfiConverterString.read(buf),
   2029             FfiConverterUInt.read(buf),
   2030             FfiConverterString.read(buf),
   2031             FfiConverterString.read(buf),
   2032             FfiConverterString.read(buf),
   2033             FfiConverterSequenceSequenceString.read(buf),
   2034             FfiConverterString.read(buf),
   2035         )
   2036     }
   2037 
   2038     override fun allocationSize(value: TypedEvidenceEventPlan) = (
   2039             FfiConverterString.allocationSize(value.`contractId`) +
   2040             FfiConverterUInt.allocationSize(value.`kind`) +
   2041             FfiConverterString.allocationSize(value.`authorPubkey`) +
   2042             FfiConverterString.allocationSize(value.`createdAtUnixS`) +
   2043             FfiConverterString.allocationSize(value.`expectedEventId`) +
   2044             FfiConverterSequenceSequenceString.allocationSize(value.`tags`) +
   2045             FfiConverterString.allocationSize(value.`content`)
   2046     )
   2047 
   2048     override fun write(value: TypedEvidenceEventPlan, buf: ByteBuffer) {
   2049             FfiConverterString.write(value.`contractId`, buf)
   2050             FfiConverterUInt.write(value.`kind`, buf)
   2051             FfiConverterString.write(value.`authorPubkey`, buf)
   2052             FfiConverterString.write(value.`createdAtUnixS`, buf)
   2053             FfiConverterString.write(value.`expectedEventId`, buf)
   2054             FfiConverterSequenceSequenceString.write(value.`tags`, buf)
   2055             FfiConverterString.write(value.`content`, buf)
   2056     }
   2057 }
   2058 
   2059 
   2060 
   2061 /**
   2062  * Current side-effect-free capability availability.
   2063  */
   2064 
   2065 enum class CapabilityAvailability {
   2066 
   2067     AVAILABLE,
   2068     DEGRADED,
   2069     UNAVAILABLE,
   2070     UNSUPPORTED;
   2071     companion object
   2072 }
   2073 
   2074 
   2075 /**
   2076  * @suppress
   2077  */
   2078 public object FfiConverterTypeCapabilityAvailability: FfiConverterRustBuffer<CapabilityAvailability> {
   2079     override fun read(buf: ByteBuffer) = try {
   2080         CapabilityAvailability.values()[buf.getInt() - 1]
   2081     } catch (e: IndexOutOfBoundsException) {
   2082         throw RuntimeException("invalid enum value, something is very wrong!!", e)
   2083     }
   2084 
   2085     override fun allocationSize(value: CapabilityAvailability) = 4UL
   2086 
   2087     override fun write(value: CapabilityAvailability, buf: ByteBuffer) {
   2088         buf.putInt(value.ordinal + 1)
   2089     }
   2090 }
   2091 
   2092 
   2093 
   2094 
   2095 
   2096 /**
   2097  * Stable capability maturity independent of runtime availability.
   2098  */
   2099 
   2100 enum class CapabilityMaturity {
   2101 
   2102     STABLE,
   2103     PREVIEW,
   2104     EXPERIMENTAL;
   2105     companion object
   2106 }
   2107 
   2108 
   2109 /**
   2110  * @suppress
   2111  */
   2112 public object FfiConverterTypeCapabilityMaturity: FfiConverterRustBuffer<CapabilityMaturity> {
   2113     override fun read(buf: ByteBuffer) = try {
   2114         CapabilityMaturity.values()[buf.getInt() - 1]
   2115     } catch (e: IndexOutOfBoundsException) {
   2116         throw RuntimeException("invalid enum value, something is very wrong!!", e)
   2117     }
   2118 
   2119     override fun allocationSize(value: CapabilityMaturity) = 4UL
   2120 
   2121     override fun write(value: CapabilityMaturity, buf: ByteBuffer) {
   2122         buf.putInt(value.ordinal + 1)
   2123     }
   2124 }
   2125 
   2126 
   2127 
   2128 
   2129 
   2130 
   2131 
   2132 /**
   2133  * Secret-safe SDK failure at the language boundary.
   2134  */
   2135 sealed class Exception: kotlin.Exception() {
   2136 
   2137     class Sdk(
   2138 
   2139         val `code`: kotlin.String,
   2140 
   2141         val `message`: kotlin.String,
   2142 
   2143         val `retryable`: kotlin.Boolean
   2144         ) : Exception() {
   2145         override val message
   2146             get() = "code=${ `code` }, message=${ `message` }, retryable=${ `retryable` }"
   2147     }
   2148 
   2149 
   2150     companion object ErrorHandler : UniffiRustCallStatusErrorHandler<Exception> {
   2151         override fun lift(error_buf: RustBuffer.ByValue): Exception = FfiConverterTypeError.lift(error_buf)
   2152     }
   2153 
   2154 
   2155 }
   2156 
   2157 /**
   2158  * @suppress
   2159  */
   2160 public object FfiConverterTypeError : FfiConverterRustBuffer<Exception> {
   2161     override fun read(buf: ByteBuffer): Exception {
   2162 
   2163 
   2164         return when(buf.getInt()) {
   2165             1 -> Exception.Sdk(
   2166                 FfiConverterString.read(buf),
   2167                 FfiConverterString.read(buf),
   2168                 FfiConverterBoolean.read(buf),
   2169                 )
   2170             else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
   2171         }
   2172     }
   2173 
   2174     override fun allocationSize(value: Exception): ULong {
   2175         return when(value) {
   2176             is Exception.Sdk -> (
   2177                 // Add the size for the Int that specifies the variant plus the size needed for all fields
   2178                 4UL
   2179                 + FfiConverterString.allocationSize(value.`code`)
   2180                 + FfiConverterString.allocationSize(value.`message`)
   2181                 + FfiConverterBoolean.allocationSize(value.`retryable`)
   2182             )
   2183         }
   2184     }
   2185 
   2186     override fun write(value: Exception, buf: ByteBuffer) {
   2187         when(value) {
   2188             is Exception.Sdk -> {
   2189                 buf.putInt(1)
   2190                 FfiConverterString.write(value.`code`, buf)
   2191                 FfiConverterString.write(value.`message`, buf)
   2192                 FfiConverterBoolean.write(value.`retryable`, buf)
   2193                 Unit
   2194             }
   2195         }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
   2196     }
   2197 
   2198 }
   2199 
   2200 
   2201 
   2202 /**
   2203  * Final evidence coverage vocabulary.
   2204  */
   2205 
   2206 enum class TradeEvidenceCoverage {
   2207 
   2208     MISSING,
   2209     PARTIAL,
   2210     SCOPE_SATISFIED,
   2211     UNSUPPORTED;
   2212     companion object
   2213 }
   2214 
   2215 
   2216 /**
   2217  * @suppress
   2218  */
   2219 public object FfiConverterTypeTradeEvidenceCoverage: FfiConverterRustBuffer<TradeEvidenceCoverage> {
   2220     override fun read(buf: ByteBuffer) = try {
   2221         TradeEvidenceCoverage.values()[buf.getInt() - 1]
   2222     } catch (e: IndexOutOfBoundsException) {
   2223         throw RuntimeException("invalid enum value, something is very wrong!!", e)
   2224     }
   2225 
   2226     override fun allocationSize(value: TradeEvidenceCoverage) = 4UL
   2227 
   2228     override fun write(value: TradeEvidenceCoverage, buf: ByteBuffer) {
   2229         buf.putInt(value.ordinal + 1)
   2230     }
   2231 }
   2232 
   2233 
   2234 
   2235 
   2236 
   2237 /**
   2238  * Final evidence outcome vocabulary.
   2239  */
   2240 
   2241 enum class TradeEvidenceOutcome {
   2242 
   2243     VALID,
   2244     INVALID,
   2245     INDETERMINATE;
   2246     companion object
   2247 }
   2248 
   2249 
   2250 /**
   2251  * @suppress
   2252  */
   2253 public object FfiConverterTypeTradeEvidenceOutcome: FfiConverterRustBuffer<TradeEvidenceOutcome> {
   2254     override fun read(buf: ByteBuffer) = try {
   2255         TradeEvidenceOutcome.values()[buf.getInt() - 1]
   2256     } catch (e: IndexOutOfBoundsException) {
   2257         throw RuntimeException("invalid enum value, something is very wrong!!", e)
   2258     }
   2259 
   2260     override fun allocationSize(value: TradeEvidenceOutcome) = 4UL
   2261 
   2262     override fun write(value: TradeEvidenceOutcome, buf: ByteBuffer) {
   2263         buf.putInt(value.ordinal + 1)
   2264     }
   2265 }
   2266 
   2267 
   2268 
   2269 
   2270 
   2271 
   2272 /**
   2273  * @suppress
   2274  */
   2275 public object FfiConverterOptionalTypeRhiEvidenceSupersession: FfiConverterRustBuffer<RhiEvidenceSupersession?> {
   2276     override fun read(buf: ByteBuffer): RhiEvidenceSupersession? {
   2277         if (buf.get().toInt() == 0) {
   2278             return null
   2279         }
   2280         return FfiConverterTypeRhiEvidenceSupersession.read(buf)
   2281     }
   2282 
   2283     override fun allocationSize(value: RhiEvidenceSupersession?): ULong {
   2284         if (value == null) {
   2285             return 1UL
   2286         } else {
   2287             return 1UL + FfiConverterTypeRhiEvidenceSupersession.allocationSize(value)
   2288         }
   2289     }
   2290 
   2291     override fun write(value: RhiEvidenceSupersession?, buf: ByteBuffer) {
   2292         if (value == null) {
   2293             buf.put(0)
   2294         } else {
   2295             buf.put(1)
   2296             FfiConverterTypeRhiEvidenceSupersession.write(value, buf)
   2297         }
   2298     }
   2299 }
   2300 
   2301 
   2302 
   2303 
   2304 /**
   2305  * @suppress
   2306  */
   2307 public object FfiConverterSequenceString: FfiConverterRustBuffer<List<kotlin.String>> {
   2308     override fun read(buf: ByteBuffer): List<kotlin.String> {
   2309         val len = buf.getInt()
   2310         return List<kotlin.String>(len) {
   2311             FfiConverterString.read(buf)
   2312         }
   2313     }
   2314 
   2315     override fun allocationSize(value: List<kotlin.String>): ULong {
   2316         val sizeForLength = 4UL
   2317         val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum()
   2318         return sizeForLength + sizeForItems
   2319     }
   2320 
   2321     override fun write(value: List<kotlin.String>, buf: ByteBuffer) {
   2322         buf.putInt(value.size)
   2323         value.iterator().forEach {
   2324             FfiConverterString.write(it, buf)
   2325         }
   2326     }
   2327 }
   2328 
   2329 
   2330 
   2331 
   2332 /**
   2333  * @suppress
   2334  */
   2335 public object FfiConverterSequenceTypeCapabilityStatus: FfiConverterRustBuffer<List<CapabilityStatus>> {
   2336     override fun read(buf: ByteBuffer): List<CapabilityStatus> {
   2337         val len = buf.getInt()
   2338         return List<CapabilityStatus>(len) {
   2339             FfiConverterTypeCapabilityStatus.read(buf)
   2340         }
   2341     }
   2342 
   2343     override fun allocationSize(value: List<CapabilityStatus>): ULong {
   2344         val sizeForLength = 4UL
   2345         val sizeForItems = value.map { FfiConverterTypeCapabilityStatus.allocationSize(it) }.sum()
   2346         return sizeForLength + sizeForItems
   2347     }
   2348 
   2349     override fun write(value: List<CapabilityStatus>, buf: ByteBuffer) {
   2350         buf.putInt(value.size)
   2351         value.iterator().forEach {
   2352             FfiConverterTypeCapabilityStatus.write(it, buf)
   2353         }
   2354     }
   2355 }
   2356 
   2357 
   2358 
   2359 
   2360 /**
   2361  * @suppress
   2362  */
   2363 public object FfiConverterSequenceSequenceString: FfiConverterRustBuffer<List<List<kotlin.String>>> {
   2364     override fun read(buf: ByteBuffer): List<List<kotlin.String>> {
   2365         val len = buf.getInt()
   2366         return List<List<kotlin.String>>(len) {
   2367             FfiConverterSequenceString.read(buf)
   2368         }
   2369     }
   2370 
   2371     override fun allocationSize(value: List<List<kotlin.String>>): ULong {
   2372         val sizeForLength = 4UL
   2373         val sizeForItems = value.map { FfiConverterSequenceString.allocationSize(it) }.sum()
   2374         return sizeForLength + sizeForItems
   2375     }
   2376 
   2377     override fun write(value: List<List<kotlin.String>>, buf: ByteBuffer) {
   2378         buf.putInt(value.size)
   2379         value.iterator().forEach {
   2380             FfiConverterSequenceString.write(it, buf)
   2381         }
   2382     }
   2383 }
   2384 
   2385 
   2386 
   2387 
   2388 
   2389 
   2390 
   2391 
   2392     @Throws(Exception::class) fun `parseRhiEvidenceReport`(`canonicalContent`: kotlin.String): RhiEvidenceReport {
   2393             return FfiConverterTypeRhiEvidenceReport.lift(
   2394     uniffiRustCallWithError(Exception) { _status ->
   2395     UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_func_parse_rhi_evidence_report(
   2396         FfiConverterString.lower(`canonicalContent`),_status)
   2397 }
   2398     )
   2399     }
   2400 
   2401 
   2402     @Throws(Exception::class) fun `parseTradeEvidenceManifest`(`canonicalBytes`: kotlin.ByteArray): TradeEvidenceManifest {
   2403             return FfiConverterTypeTradeEvidenceManifest.lift(
   2404     uniffiRustCallWithError(Exception) { _status ->
   2405     UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_func_parse_trade_evidence_manifest(
   2406         FfiConverterByteArray.lower(`canonicalBytes`),_status)
   2407 }
   2408     )
   2409     }
   2410 
   2411 
   2412     @Throws(Exception::class) fun `prepareRhiEvidenceAttestation`(`canonicalContent`: kotlin.String, `createdAtUnixS`: kotlin.ULong): TypedEvidenceEventPlan {
   2413             return FfiConverterTypeTypedEvidenceEventPlan.lift(
   2414     uniffiRustCallWithError(Exception) { _status ->
   2415     UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_func_prepare_rhi_evidence_attestation(
   2416         FfiConverterString.lower(`canonicalContent`),FfiConverterULong.lower(`createdAtUnixS`),_status)
   2417 }
   2418     )
   2419     }
   2420 
   2421 
   2422     @Throws(Exception::class) fun `validateRhiEvidenceAttestation`(`event`: SignedEvent): RhiEvidenceAttestation {
   2423             return FfiConverterTypeRhiEvidenceAttestation.lift(
   2424     uniffiRustCallWithError(Exception) { _status ->
   2425     UniffiLib.INSTANCE.uniffi_radroots_sdk_ffi_fn_func_validate_rhi_evidence_attestation(
   2426         FfiConverterTypeSignedEvent.lower(`event`),_status)
   2427 }
   2428     )
   2429     }