Coverage Summary for Class: NetworkEventResult (io.actrium.actr)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| NetworkEventResult |
0%
(0/1)
|
|
0%
(0/5)
|
0%
(0/34)
|
| NetworkEventResult$Companion |
|
| Total |
0%
(0/1)
|
|
0%
(0/5)
|
0%
(0/34)
|
// This file was autogenerated by some hot garbage in the `uniffi` crate.
// Trust me, you don't want to mess with it!
@file:Suppress("NAME_SHADOWING")
package io.actrium.actr
// Common helper code.
//
// Ideally this would live in a separate .kt file where it can be unittested etc
// in isolation, and perhaps even published as a re-useable package.
//
// However, it's important that the details of how this helper code works (e.g. the
// way that different builtin types are passed across the FFI) exactly match what's
// expected by the Rust code on the other side of the interface. In practice right
// now that means coming from the exact some version of `uniffi` that was used to
// compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
// helpers directly inline like we're doing here.
import com.sun.jna.Library
import com.sun.jna.IntegerType
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure
import com.sun.jna.Callback
import com.sun.jna.ptr.*
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.nio.CharBuffer
import java.nio.charset.CodingErrorAction
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.coroutines.resume
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
// This is a helper for safely working with byte buffers returned from the Rust code.
// A rust-owned buffer is represented by its capacity, its current length, and a
// pointer to the underlying data.
/**
* @suppress
*/
@Structure.FieldOrder("capacity", "len", "data")
open class RustBuffer : Structure() {
// Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
// When dealing with these fields, make sure to call `toULong()`.
@JvmField var capacity: Long = 0
@JvmField var len: Long = 0
@JvmField var data: Pointer? = null
class ByValue: RustBuffer(), Structure.ByValue
class ByReference: RustBuffer(), Structure.ByReference
internal fun setValue(other: RustBuffer) {
capacity = other.capacity
len = other.len
data = other.data
}
companion object {
internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
// Note: need to convert the size to a `Long` value to make this work with JVM.
UniffiLib.ffi_actr_rustbuffer_alloc(size.toLong(), status)
}.also {
if(it.data == null) {
throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
}
}
internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
var buf = RustBuffer.ByValue()
buf.capacity = capacity.toLong()
buf.len = len.toLong()
buf.data = data
return buf
}
internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
UniffiLib.ffi_actr_rustbuffer_free(buf, status)
}
}
@Suppress("TooGenericExceptionThrown")
fun asByteBuffer() =
this.data?.getByteBuffer(0, this.len)?.also {
it.order(ByteOrder.BIG_ENDIAN)
}
}
// This is a helper for safely passing byte references into the rust code.
// It's not actually used at the moment, because there aren't many things that you
// can take a direct pointer to in the JVM, and if we're going to copy something
// then we might as well copy it into a `RustBuffer`. But it's here for API
// completeness.
@Structure.FieldOrder("len", "data")
internal open class ForeignBytes : Structure() {
@JvmField var len: Int = 0
@JvmField var data: Pointer? = null
class ByValue : ForeignBytes(), Structure.ByValue
}
/**
* The FfiConverter interface handles converter types to and from the FFI
*
* All implementing objects should be public to support external types. When a
* type is external we need to import it's FfiConverter.
*
* @suppress
*/
public interface FfiConverter<KotlinType, FfiType> {
// Convert an FFI type to a Kotlin type
fun lift(value: FfiType): KotlinType
// Convert an Kotlin type to an FFI type
fun lower(value: KotlinType): FfiType
// Read a Kotlin type from a `ByteBuffer`
fun read(buf: ByteBuffer): KotlinType
// Calculate bytes to allocate when creating a `RustBuffer`
//
// This must return at least as many bytes as the write() function will
// write. It can return more bytes than needed, for example when writing
// Strings we can't know the exact bytes needed until we the UTF-8
// encoding, so we pessimistically allocate the largest size possible (3
// bytes per codepoint). Allocating extra bytes is not really a big deal
// because the `RustBuffer` is short-lived.
fun allocationSize(value: KotlinType): ULong
// Write a Kotlin type to a `ByteBuffer`
fun write(value: KotlinType, buf: ByteBuffer)
// Lower a value into a `RustBuffer`
//
// This method lowers a value into a `RustBuffer` rather than the normal
// FfiType. It's used by the callback interface code. Callback interface
// returns are always serialized into a `RustBuffer` regardless of their
// normal FFI type.
fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
val rbuf = RustBuffer.alloc(allocationSize(value))
try {
val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
it.order(ByteOrder.BIG_ENDIAN)
}
write(value, bbuf)
rbuf.writeField("len", bbuf.position().toLong())
return rbuf
} catch (e: Throwable) {
RustBuffer.free(rbuf)
throw e
}
}
// Lift a value from a `RustBuffer`.
//
// This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
// It's currently only used by the `FfiConverterRustBuffer` class below.
fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
val byteBuf = rbuf.asByteBuffer()!!
try {
val item = read(byteBuf)
if (byteBuf.hasRemaining()) {
throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
}
return item
} finally {
RustBuffer.free(rbuf)
}
}
}
/**
* FfiConverter that uses `RustBuffer` as the FfiType
*
* @suppress
*/
public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
}
// A handful of classes and functions to support the generated data structures.
// This would be a good candidate for isolating in its own ffi-support lib.
internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
internal const val UNIFFI_CALL_ERROR = 1.toByte()
internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
@Structure.FieldOrder("code", "error_buf")
internal open class UniffiRustCallStatus : Structure() {
@JvmField var code: Byte = 0
@JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
class ByValue: UniffiRustCallStatus(), Structure.ByValue
fun isSuccess(): Boolean {
return code == UNIFFI_CALL_SUCCESS
}
fun isError(): Boolean {
return code == UNIFFI_CALL_ERROR
}
fun isPanic(): Boolean {
return code == UNIFFI_CALL_UNEXPECTED_ERROR
}
companion object {
fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
val callStatus = UniffiRustCallStatus.ByValue()
callStatus.code = code
callStatus.error_buf = errorBuf
return callStatus
}
}
}
class InternalException(message: String) : kotlin.Exception(message)
/**
* Each top-level error class has a companion object that can lift the error from the call status's rust buffer
*
* @suppress
*/
interface UniffiRustCallStatusErrorHandler<E> {
fun lift(error_buf: RustBuffer.ByValue): E;
}
// Helpers for calling Rust
// In practice we usually need to be synchronized to call this safely, so it doesn't
// synchronize itself
// Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
var status = UniffiRustCallStatus()
val return_value = callback(status)
uniffiCheckCallStatus(errorHandler, status)
return return_value
}
// Check UniffiRustCallStatus and throw an error if the call wasn't successful
private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
if (status.isSuccess()) {
return
} else if (status.isError()) {
throw errorHandler.lift(status.error_buf)
} else if (status.isPanic()) {
// when the rust code sees a panic, it tries to construct a rustbuffer
// with the message. but if that code panics, then it just sends back
// an empty buffer.
if (status.error_buf.len > 0) {
throw InternalException(FfiConverterString.lift(status.error_buf))
} else {
throw InternalException("Rust panic")
}
} else {
throw InternalException("Unknown rust call status: $status.code")
}
}
/**
* UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
*
* @suppress
*/
object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
override fun lift(error_buf: RustBuffer.ByValue): InternalException {
RustBuffer.free(error_buf)
return InternalException("Unexpected CALL_ERROR")
}
}
// Call a rust function that returns a plain value
private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
}
internal inline fun<T> uniffiTraitInterfaceCall(
callStatus: UniffiRustCallStatus,
makeCall: () -> T,
writeReturn: (T) -> Unit,
) {
try {
writeReturn(makeCall())
} catch(e: kotlin.Exception) {
val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
callStatus.error_buf = FfiConverterString.lower(err)
}
}
internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
callStatus: UniffiRustCallStatus,
makeCall: () -> T,
writeReturn: (T) -> Unit,
lowerError: (E) -> RustBuffer.ByValue
) {
try {
writeReturn(makeCall())
} catch(e: kotlin.Exception) {
if (e is E) {
callStatus.code = UNIFFI_CALL_ERROR
callStatus.error_buf = lowerError(e)
} else {
val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
callStatus.error_buf = FfiConverterString.lower(err)
}
}
}
// Initial value and increment amount for handles.
// These ensure that Kotlin-generated handles always have the lowest bit set
private const val UNIFFI_HANDLEMAP_INITIAL = 1.toLong()
private const val UNIFFI_HANDLEMAP_DELTA = 2.toLong()
// Map handles to objects
//
// This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
internal class UniffiHandleMap<T: Any> {
private val map = ConcurrentHashMap<Long, T>()
// Start
private val counter = java.util.concurrent.atomic.AtomicLong(UNIFFI_HANDLEMAP_INITIAL)
val size: Int
get() = map.size
// Insert a new object into the handle map and get a handle for it
fun insert(obj: T): Long {
val handle = counter.getAndAdd(UNIFFI_HANDLEMAP_DELTA)
map.put(handle, obj)
return handle
}
// Clone a handle, creating a new one
fun clone(handle: Long): Long {
val obj = map.get(handle) ?: throw InternalException("UniffiHandleMap.clone: Invalid handle")
return insert(obj)
}
// Get an object from the handle map
fun get(handle: Long): T {
return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
}
// Remove an entry from the handlemap and get the Kotlin object back
fun remove(handle: Long): T {
return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
}
}
// Contains loading, initialization code,
// and the FFI Function declarations in a com.sun.jna.Library.
@Synchronized
private fun findLibraryName(componentName: String): String {
val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
if (libOverride != null) {
return libOverride
}
return "actr"
}
// Define FFI callback types
internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
fun callback(`data`: Long,`pollResult`: Byte,)
}
internal interface UniffiForeignFutureDroppedCallback : com.sun.jna.Callback {
fun callback(`handle`: Long,)
}
internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
fun callback(`handle`: Long,)
}
internal interface UniffiCallbackInterfaceClone : com.sun.jna.Callback {
fun callback(`handle`: Long,)
: Long
}
@Structure.FieldOrder("handle", "free")
internal open class UniffiForeignFutureDroppedCallbackStruct(
@JvmField internal var `handle`: Long = 0.toLong(),
@JvmField internal var `free`: UniffiForeignFutureDroppedCallback? = null,
) : Structure() {
class UniffiByValue(
`handle`: Long = 0.toLong(),
`free`: UniffiForeignFutureDroppedCallback? = null,
): UniffiForeignFutureDroppedCallbackStruct(`handle`,`free`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureDroppedCallbackStruct) {
`handle` = other.`handle`
`free` = other.`free`
}
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU8(
@JvmField internal var `returnValue`: Byte = 0.toByte(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Byte = 0.toByte(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultU8(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultU8) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU8.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI8(
@JvmField internal var `returnValue`: Byte = 0.toByte(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Byte = 0.toByte(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultI8(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultI8) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI8.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU16(
@JvmField internal var `returnValue`: Short = 0.toShort(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Short = 0.toShort(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultU16(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultU16) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU16.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI16(
@JvmField internal var `returnValue`: Short = 0.toShort(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Short = 0.toShort(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultI16(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultI16) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI16.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU32(
@JvmField internal var `returnValue`: Int = 0,
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Int = 0,
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultU32(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultU32) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI32(
@JvmField internal var `returnValue`: Int = 0,
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Int = 0,
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultI32(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultI32) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultU64(
@JvmField internal var `returnValue`: Long = 0.toLong(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Long = 0.toLong(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultU64(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultU64) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultI64(
@JvmField internal var `returnValue`: Long = 0.toLong(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Long = 0.toLong(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultI64(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultI64) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultF32(
@JvmField internal var `returnValue`: Float = 0.0f,
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Float = 0.0f,
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultF32(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultF32) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF32.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultF64(
@JvmField internal var `returnValue`: Double = 0.0,
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: Double = 0.0,
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultF64(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultF64) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF64.UniffiByValue,)
}
@Structure.FieldOrder("returnValue", "callStatus")
internal open class UniffiForeignFutureResultRustBuffer(
@JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultRustBuffer) {
`returnValue` = other.`returnValue`
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultRustBuffer.UniffiByValue,)
}
@Structure.FieldOrder("callStatus")
internal open class UniffiForeignFutureResultVoid(
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
) : Structure() {
class UniffiByValue(
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
): UniffiForeignFutureResultVoid(`callStatus`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiForeignFutureResultVoid) {
`callStatus` = other.`callStatus`
}
}
internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultVoid.UniffiByValue,)
}
internal interface UniffiCallbackInterfaceDataStreamCallbackMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`chunk`: RustBuffer.ByValue,`sender`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceMediaTrackCallbackMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`sample`: RustBuffer.ByValue,`sender`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceLogCallbackMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`level`: RustBuffer.ByValue,`target`: RustBuffer.ByValue,`message`: RustBuffer.ByValue,`timestampMs`: Long,`uniffiOutReturn`: Pointer,uniffiCallStatus: UniffiRustCallStatus,)
}
internal interface UniffiCallbackInterfaceCredentialObserverBridgeMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceCredentialObserverBridgeMethod1 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceMailboxObserverBridgeMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceSignalingObserverBridgeMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceSignalingObserverBridgeMethod1 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceSignalingObserverBridgeMethod2 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWebRtcObserverBridgeMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWebRtcObserverBridgeMethod1 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWebRtcObserverBridgeMethod2 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWebSocketObserverBridgeMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWebSocketObserverBridgeMethod1 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWebSocketObserverBridgeMethod2 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod0 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod1 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod2 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod3 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
internal interface UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod4 : com.sun.jna.Callback {
fun callback(`uniffiHandle`: Long,`ctx`: Long,`envelope`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteRustBuffer,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,)
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onStream")
internal open class UniffiVTableCallbackInterfaceDataStreamCallback(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onStream`: UniffiCallbackInterfaceDataStreamCallbackMethod0? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onStream`: UniffiCallbackInterfaceDataStreamCallbackMethod0? = null,
): UniffiVTableCallbackInterfaceDataStreamCallback(`uniffiFree`,`uniffiClone`,`onStream`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceDataStreamCallback) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onStream` = other.`onStream`
}
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onSample")
internal open class UniffiVTableCallbackInterfaceMediaTrackCallback(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onSample`: UniffiCallbackInterfaceMediaTrackCallbackMethod0? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onSample`: UniffiCallbackInterfaceMediaTrackCallbackMethod0? = null,
): UniffiVTableCallbackInterfaceMediaTrackCallback(`uniffiFree`,`uniffiClone`,`onSample`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceMediaTrackCallback) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onSample` = other.`onSample`
}
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onLog")
internal open class UniffiVTableCallbackInterfaceLogCallback(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onLog`: UniffiCallbackInterfaceLogCallbackMethod0? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onLog`: UniffiCallbackInterfaceLogCallbackMethod0? = null,
): UniffiVTableCallbackInterfaceLogCallback(`uniffiFree`,`uniffiClone`,`onLog`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceLogCallback) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onLog` = other.`onLog`
}
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onRenewed", "onExpiring")
internal open class UniffiVTableCallbackInterfaceCredentialObserverBridge(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onRenewed`: UniffiCallbackInterfaceCredentialObserverBridgeMethod0? = null,
@JvmField internal var `onExpiring`: UniffiCallbackInterfaceCredentialObserverBridgeMethod1? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onRenewed`: UniffiCallbackInterfaceCredentialObserverBridgeMethod0? = null,
`onExpiring`: UniffiCallbackInterfaceCredentialObserverBridgeMethod1? = null,
): UniffiVTableCallbackInterfaceCredentialObserverBridge(`uniffiFree`,`uniffiClone`,`onRenewed`,`onExpiring`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceCredentialObserverBridge) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onRenewed` = other.`onRenewed`
`onExpiring` = other.`onExpiring`
}
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onBackpressure")
internal open class UniffiVTableCallbackInterfaceMailboxObserverBridge(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onBackpressure`: UniffiCallbackInterfaceMailboxObserverBridgeMethod0? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onBackpressure`: UniffiCallbackInterfaceMailboxObserverBridgeMethod0? = null,
): UniffiVTableCallbackInterfaceMailboxObserverBridge(`uniffiFree`,`uniffiClone`,`onBackpressure`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceMailboxObserverBridge) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onBackpressure` = other.`onBackpressure`
}
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onConnecting", "onConnected", "onDisconnected")
internal open class UniffiVTableCallbackInterfaceSignalingObserverBridge(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onConnecting`: UniffiCallbackInterfaceSignalingObserverBridgeMethod0? = null,
@JvmField internal var `onConnected`: UniffiCallbackInterfaceSignalingObserverBridgeMethod1? = null,
@JvmField internal var `onDisconnected`: UniffiCallbackInterfaceSignalingObserverBridgeMethod2? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onConnecting`: UniffiCallbackInterfaceSignalingObserverBridgeMethod0? = null,
`onConnected`: UniffiCallbackInterfaceSignalingObserverBridgeMethod1? = null,
`onDisconnected`: UniffiCallbackInterfaceSignalingObserverBridgeMethod2? = null,
): UniffiVTableCallbackInterfaceSignalingObserverBridge(`uniffiFree`,`uniffiClone`,`onConnecting`,`onConnected`,`onDisconnected`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceSignalingObserverBridge) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onConnecting` = other.`onConnecting`
`onConnected` = other.`onConnected`
`onDisconnected` = other.`onDisconnected`
}
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onConnecting", "onConnected", "onDisconnected")
internal open class UniffiVTableCallbackInterfaceWebRtcObserverBridge(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onConnecting`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod0? = null,
@JvmField internal var `onConnected`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod1? = null,
@JvmField internal var `onDisconnected`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod2? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onConnecting`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod0? = null,
`onConnected`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod1? = null,
`onDisconnected`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod2? = null,
): UniffiVTableCallbackInterfaceWebRtcObserverBridge(`uniffiFree`,`uniffiClone`,`onConnecting`,`onConnected`,`onDisconnected`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceWebRtcObserverBridge) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onConnecting` = other.`onConnecting`
`onConnected` = other.`onConnected`
`onDisconnected` = other.`onDisconnected`
}
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onConnecting", "onConnected", "onDisconnected")
internal open class UniffiVTableCallbackInterfaceWebSocketObserverBridge(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onConnecting`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod0? = null,
@JvmField internal var `onConnected`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod1? = null,
@JvmField internal var `onDisconnected`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod2? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onConnecting`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod0? = null,
`onConnected`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod1? = null,
`onDisconnected`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod2? = null,
): UniffiVTableCallbackInterfaceWebSocketObserverBridge(`uniffiFree`,`uniffiClone`,`onConnecting`,`onConnected`,`onDisconnected`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceWebSocketObserverBridge) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onConnecting` = other.`onConnecting`
`onConnected` = other.`onConnected`
`onDisconnected` = other.`onDisconnected`
}
}
@Structure.FieldOrder("uniffiFree", "uniffiClone", "onStart", "onReady", "onStop", "onError", "dispatch")
internal open class UniffiVTableCallbackInterfaceWorkloadLifecycleBridge(
@JvmField internal var `uniffiFree`: UniffiCallbackInterfaceFree? = null,
@JvmField internal var `uniffiClone`: UniffiCallbackInterfaceClone? = null,
@JvmField internal var `onStart`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod0? = null,
@JvmField internal var `onReady`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod1? = null,
@JvmField internal var `onStop`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod2? = null,
@JvmField internal var `onError`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod3? = null,
@JvmField internal var `dispatch`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod4? = null,
) : Structure() {
class UniffiByValue(
`uniffiFree`: UniffiCallbackInterfaceFree? = null,
`uniffiClone`: UniffiCallbackInterfaceClone? = null,
`onStart`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod0? = null,
`onReady`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod1? = null,
`onStop`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod2? = null,
`onError`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod3? = null,
`dispatch`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod4? = null,
): UniffiVTableCallbackInterfaceWorkloadLifecycleBridge(`uniffiFree`,`uniffiClone`,`onStart`,`onReady`,`onStop`,`onError`,`dispatch`,), Structure.ByValue
internal fun uniffiSetValue(other: UniffiVTableCallbackInterfaceWorkloadLifecycleBridge) {
`uniffiFree` = other.`uniffiFree`
`uniffiClone` = other.`uniffiClone`
`onStart` = other.`onStart`
`onReady` = other.`onReady`
`onStop` = other.`onStop`
`onError` = other.`onError`
`dispatch` = other.`dispatch`
}
}
// A JNA Library to expose the extern-C FFI definitions.
// This is an implementation detail which will be called internally by the public API.
// For large crates we prevent `MethodTooLargeException` (see #2340)
// N.B. the name of the extension is very misleading, since it is
// rather `InterfaceTooLargeException`, caused by too many methods
// in the interface for large crates.
//
// By splitting the otherwise huge interface into two parts
// * UniffiLib (this)
// * IntegrityCheckingUniffiLib
// And all checksum methods are put into `IntegrityCheckingUniffiLib`
// we allow for ~2x as many methods in the UniffiLib interface.
//
// Note: above all written when we used JNA's `loadIndirect` etc.
// We now use JNA's "direct mapping" - unclear if same considerations apply exactly.
internal object IntegrityCheckingUniffiLib {
init {
Native.register(IntegrityCheckingUniffiLib::class.java, findLibraryName(componentName = "actr"))
uniffiCheckContractApiVersion(this)
uniffiCheckApiChecksums(this)
}
external fun uniffi_actr_checksum_func_actr_error_is_retryable(
): Short
external fun uniffi_actr_checksum_func_actr_error_kind(
): Short
external fun uniffi_actr_checksum_func_actr_error_requires_dlq(
): Short
external fun uniffi_actr_checksum_func_set_log_callback(
): Short
external fun uniffi_actr_checksum_func_resolve_manifest_dependency(
): Short
external fun uniffi_actr_checksum_func_resolve_manifest_dependency_alias_list(
): Short
external fun uniffi_actr_checksum_func_resolve_manifest_package_actr_type(
): Short
external fun uniffi_actr_checksum_method_contextbridge_add_media_track(
): Short
external fun uniffi_actr_checksum_method_contextbridge_call_raw(
): Short
external fun uniffi_actr_checksum_method_contextbridge_discover(
): Short
external fun uniffi_actr_checksum_method_contextbridge_register_media_track(
): Short
external fun uniffi_actr_checksum_method_contextbridge_register_stream(
): Short
external fun uniffi_actr_checksum_method_contextbridge_remove_media_track(
): Short
external fun uniffi_actr_checksum_method_contextbridge_send_data_stream(
): Short
external fun uniffi_actr_checksum_method_contextbridge_send_media_sample(
): Short
external fun uniffi_actr_checksum_method_contextbridge_tell_raw(
): Short
external fun uniffi_actr_checksum_method_contextbridge_unregister_media_track(
): Short
external fun uniffi_actr_checksum_method_contextbridge_unregister_stream(
): Short
external fun uniffi_actr_checksum_method_opusencoder_encode(
): Short
external fun uniffi_actr_checksum_method_opusencoder_frame_size(
): Short
external fun uniffi_actr_checksum_method_actrnode_create_network_event_handle(
): Short
external fun uniffi_actr_checksum_method_actrnode_start(
): Short
external fun uniffi_actr_checksum_method_actrrefwrapper_actor_id(
): Short
external fun uniffi_actr_checksum_method_actrrefwrapper_call(
): Short
external fun uniffi_actr_checksum_method_actrrefwrapper_discover(
): Short
external fun uniffi_actr_checksum_method_actrrefwrapper_is_shutting_down(
): Short
external fun uniffi_actr_checksum_method_actrrefwrapper_shutdown(
): Short
external fun uniffi_actr_checksum_method_actrrefwrapper_tell(
): Short
external fun uniffi_actr_checksum_method_actrrefwrapper_wait_for_shutdown(
): Short
external fun uniffi_actr_checksum_method_networkeventhandlewrapper_cleanup_connections(
): Short
external fun uniffi_actr_checksum_method_networkeventhandlewrapper_force_reconnect(
): Short
external fun uniffi_actr_checksum_method_networkeventhandlewrapper_handle_app_lifecycle_changed(
): Short
external fun uniffi_actr_checksum_method_networkeventhandlewrapper_handle_network_path_changed(
): Short
external fun uniffi_actr_checksum_constructor_opusencoder_new(
): Short
external fun uniffi_actr_checksum_constructor_actrnode_new_from_linked_workload(
): Short
external fun uniffi_actr_checksum_constructor_actrnode_new_from_package_file(
): Short
external fun uniffi_actr_checksum_constructor_actrnode_new_from_package_file_with_observers(
): Short
external fun uniffi_actr_checksum_constructor_dynamicworkload_new(
): Short
external fun uniffi_actr_checksum_constructor_runtimeobservers_new(
): Short
external fun uniffi_actr_checksum_method_datastreamcallback_on_stream(
): Short
external fun uniffi_actr_checksum_method_mediatrackcallback_on_sample(
): Short
external fun uniffi_actr_checksum_method_logcallback_on_log(
): Short
external fun uniffi_actr_checksum_method_credentialobserverbridge_on_renewed(
): Short
external fun uniffi_actr_checksum_method_credentialobserverbridge_on_expiring(
): Short
external fun uniffi_actr_checksum_method_mailboxobserverbridge_on_backpressure(
): Short
external fun uniffi_actr_checksum_method_signalingobserverbridge_on_connecting(
): Short
external fun uniffi_actr_checksum_method_signalingobserverbridge_on_connected(
): Short
external fun uniffi_actr_checksum_method_signalingobserverbridge_on_disconnected(
): Short
external fun uniffi_actr_checksum_method_webrtcobserverbridge_on_connecting(
): Short
external fun uniffi_actr_checksum_method_webrtcobserverbridge_on_connected(
): Short
external fun uniffi_actr_checksum_method_webrtcobserverbridge_on_disconnected(
): Short
external fun uniffi_actr_checksum_method_websocketobserverbridge_on_connecting(
): Short
external fun uniffi_actr_checksum_method_websocketobserverbridge_on_connected(
): Short
external fun uniffi_actr_checksum_method_websocketobserverbridge_on_disconnected(
): Short
external fun uniffi_actr_checksum_method_workloadlifecyclebridge_on_start(
): Short
external fun uniffi_actr_checksum_method_workloadlifecyclebridge_on_ready(
): Short
external fun uniffi_actr_checksum_method_workloadlifecyclebridge_on_stop(
): Short
external fun uniffi_actr_checksum_method_workloadlifecyclebridge_on_error(
): Short
external fun uniffi_actr_checksum_method_workloadlifecyclebridge_dispatch(
): Short
external fun ffi_actr_uniffi_contract_version(
): Int
}
internal object UniffiLib {
// The Cleaner for the whole library
internal val CLEANER: UniffiCleaner by lazy {
UniffiCleaner.create()
}
init {
Native.register(UniffiLib::class.java, findLibraryName(componentName = "actr"))
uniffiCallbackInterfaceCredentialObserverBridge.register(this)
uniffiCallbackInterfaceDataStreamCallback.register(this)
uniffiCallbackInterfaceLogCallback.register(this)
uniffiCallbackInterfaceMailboxObserverBridge.register(this)
uniffiCallbackInterfaceMediaTrackCallback.register(this)
uniffiCallbackInterfaceSignalingObserverBridge.register(this)
uniffiCallbackInterfaceWebRtcObserverBridge.register(this)
uniffiCallbackInterfaceWebSocketObserverBridge.register(this)
uniffiCallbackInterfaceWorkloadLifecycleBridge.register(this)
}
external fun uniffi_actr_fn_clone_contextbridge(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_free_contextbridge(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_method_contextbridge_add_media_track(`ptr`: Long,`target`: RustBuffer.ByValue,`trackId`: RustBuffer.ByValue,`codec`: RustBuffer.ByValue,`mediaType`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_contextbridge_call_raw(`ptr`: Long,`target`: RustBuffer.ByValue,`routeKey`: RustBuffer.ByValue,`payloadType`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`timeoutMs`: Long,
): Long
external fun uniffi_actr_fn_method_contextbridge_discover(`ptr`: Long,`targetType`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_contextbridge_register_media_track(`ptr`: Long,`trackId`: RustBuffer.ByValue,`callback`: Long,
): Long
external fun uniffi_actr_fn_method_contextbridge_register_stream(`ptr`: Long,`streamId`: RustBuffer.ByValue,`callback`: Long,
): Long
external fun uniffi_actr_fn_method_contextbridge_remove_media_track(`ptr`: Long,`target`: RustBuffer.ByValue,`trackId`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_contextbridge_send_data_stream(`ptr`: Long,`target`: RustBuffer.ByValue,`chunk`: RustBuffer.ByValue,`payloadType`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_contextbridge_send_media_sample(`ptr`: Long,`target`: RustBuffer.ByValue,`trackId`: RustBuffer.ByValue,`sample`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_contextbridge_tell_raw(`ptr`: Long,`target`: RustBuffer.ByValue,`routeKey`: RustBuffer.ByValue,`payloadType`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_contextbridge_unregister_media_track(`ptr`: Long,`trackId`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_contextbridge_unregister_stream(`ptr`: Long,`streamId`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_clone_opusencoder(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_free_opusencoder(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_constructor_opusencoder_new(`sampleRate`: Int,`channels`: Byte,`frameSize`: Short,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_method_opusencoder_encode(`ptr`: Long,`pcm`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_actr_fn_method_opusencoder_frame_size(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Short
external fun uniffi_actr_fn_clone_actrnode(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_free_actrnode(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_constructor_actrnode_new_from_linked_workload(`configPath`: RustBuffer.ByValue,`actorType`: RustBuffer.ByValue,`workload`: Long,
): Long
external fun uniffi_actr_fn_constructor_actrnode_new_from_package_file(`configPath`: RustBuffer.ByValue,`packagePath`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_constructor_actrnode_new_from_package_file_with_observers(`configPath`: RustBuffer.ByValue,`packagePath`: RustBuffer.ByValue,`observers`: Long,
): Long
external fun uniffi_actr_fn_method_actrnode_create_network_event_handle(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_method_actrnode_start(`ptr`: Long,
): Long
external fun uniffi_actr_fn_clone_actrrefwrapper(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_free_actrrefwrapper(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_method_actrrefwrapper_actor_id(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_actr_fn_method_actrrefwrapper_call(`ptr`: Long,`routeKey`: RustBuffer.ByValue,`payloadType`: RustBuffer.ByValue,`requestPayload`: RustBuffer.ByValue,`timeoutMs`: Long,
): Long
external fun uniffi_actr_fn_method_actrrefwrapper_discover(`ptr`: Long,`targetType`: RustBuffer.ByValue,`count`: Int,
): Long
external fun uniffi_actr_fn_method_actrrefwrapper_is_shutting_down(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_actr_fn_method_actrrefwrapper_shutdown(`ptr`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_method_actrrefwrapper_tell(`ptr`: Long,`routeKey`: RustBuffer.ByValue,`payloadType`: RustBuffer.ByValue,`messagePayload`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_actrrefwrapper_wait_for_shutdown(`ptr`: Long,
): Long
external fun uniffi_actr_fn_clone_networkeventhandlewrapper(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_free_networkeventhandlewrapper(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_method_networkeventhandlewrapper_cleanup_connections(`ptr`: Long,`reason`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_networkeventhandlewrapper_force_reconnect(`ptr`: Long,`reason`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_networkeventhandlewrapper_handle_app_lifecycle_changed(`ptr`: Long,`state`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_method_networkeventhandlewrapper_handle_network_path_changed(`ptr`: Long,`snapshot`: RustBuffer.ByValue,
): Long
external fun uniffi_actr_fn_clone_dynamicworkload(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_free_dynamicworkload(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_constructor_dynamicworkload_new(`lifecycle`: Long,`signaling`: RustBuffer.ByValue,`websocket`: RustBuffer.ByValue,`webrtc`: RustBuffer.ByValue,`credential`: RustBuffer.ByValue,`mailbox`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_clone_runtimeobservers(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_free_runtimeobservers(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_constructor_runtimeobservers_new(`signaling`: RustBuffer.ByValue,`websocket`: RustBuffer.ByValue,`webrtc`: RustBuffer.ByValue,`credential`: RustBuffer.ByValue,`mailbox`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun uniffi_actr_fn_init_callback_vtable_datastreamcallback(`vtable`: UniffiVTableCallbackInterfaceDataStreamCallback,
): Unit
external fun uniffi_actr_fn_init_callback_vtable_mediatrackcallback(`vtable`: UniffiVTableCallbackInterfaceMediaTrackCallback,
): Unit
external fun uniffi_actr_fn_init_callback_vtable_logcallback(`vtable`: UniffiVTableCallbackInterfaceLogCallback,
): Unit
external fun uniffi_actr_fn_init_callback_vtable_credentialobserverbridge(`vtable`: UniffiVTableCallbackInterfaceCredentialObserverBridge,
): Unit
external fun uniffi_actr_fn_init_callback_vtable_mailboxobserverbridge(`vtable`: UniffiVTableCallbackInterfaceMailboxObserverBridge,
): Unit
external fun uniffi_actr_fn_init_callback_vtable_signalingobserverbridge(`vtable`: UniffiVTableCallbackInterfaceSignalingObserverBridge,
): Unit
external fun uniffi_actr_fn_init_callback_vtable_webrtcobserverbridge(`vtable`: UniffiVTableCallbackInterfaceWebRtcObserverBridge,
): Unit
external fun uniffi_actr_fn_init_callback_vtable_websocketobserverbridge(`vtable`: UniffiVTableCallbackInterfaceWebSocketObserverBridge,
): Unit
external fun uniffi_actr_fn_init_callback_vtable_workloadlifecyclebridge(`vtable`: UniffiVTableCallbackInterfaceWorkloadLifecycleBridge,
): Unit
external fun uniffi_actr_fn_func_actr_error_is_retryable(`err`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_actr_fn_func_actr_error_kind(`err`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_actr_fn_func_actr_error_requires_dlq(`err`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun uniffi_actr_fn_func_set_log_callback(`callback`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun uniffi_actr_fn_func_resolve_manifest_dependency(`manifestPath`: RustBuffer.ByValue,`dependencyAlias`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_actr_fn_func_resolve_manifest_dependency_alias_list(`manifestPath`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun uniffi_actr_fn_func_resolve_manifest_package_actr_type(`manifestPath`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_actr_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_actr_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_actr_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Unit
external fun ffi_actr_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_actr_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_u8(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_u8(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun ffi_actr_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_i8(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_i8(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Byte
external fun ffi_actr_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_u16(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_u16(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Short
external fun ffi_actr_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_i16(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_i16(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Short
external fun ffi_actr_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_u32(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_u32(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun ffi_actr_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_i32(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_i32(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Int
external fun ffi_actr_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_u64(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_u64(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun ffi_actr_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_i64(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_i64(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Long
external fun ffi_actr_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_f32(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_f32(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Float
external fun ffi_actr_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_f64(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_f64(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Double
external fun ffi_actr_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_rust_buffer(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_rust_buffer(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
external fun ffi_actr_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
): Unit
external fun ffi_actr_rust_future_cancel_void(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_free_void(`handle`: Long,
): Unit
external fun ffi_actr_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
}
private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
// Get the bindings contract version from our ComponentInterface
val bindings_contract_version = 30
// Get the scaffolding contract version by calling the into the dylib
val scaffolding_contract_version = lib.ffi_actr_uniffi_contract_version()
if (bindings_contract_version != scaffolding_contract_version) {
throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
}
}
@Suppress("UNUSED_PARAMETER")
private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
if (lib.uniffi_actr_checksum_func_actr_error_is_retryable() != 34175.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_func_actr_error_kind() != 40651.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_func_actr_error_requires_dlq() != 62057.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_func_set_log_callback() != 22627.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_func_resolve_manifest_dependency() != 20704.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_func_resolve_manifest_dependency_alias_list() != 45756.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_func_resolve_manifest_package_actr_type() != 16114.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_add_media_track() != 37665.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_call_raw() != 51062.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_discover() != 38410.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_register_media_track() != 43039.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_register_stream() != 21623.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_remove_media_track() != 43937.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_send_data_stream() != 33554.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_send_media_sample() != 63657.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_tell_raw() != 46175.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_unregister_media_track() != 52187.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_contextbridge_unregister_stream() != 65290.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_opusencoder_encode() != 35920.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_opusencoder_frame_size() != 18284.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrnode_create_network_event_handle() != 24690.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrnode_start() != 22494.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrrefwrapper_actor_id() != 23881.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrrefwrapper_call() != 24018.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrrefwrapper_discover() != 21192.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrrefwrapper_is_shutting_down() != 50332.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrrefwrapper_shutdown() != 60173.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrrefwrapper_tell() != 38430.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_actrrefwrapper_wait_for_shutdown() != 12482.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_networkeventhandlewrapper_cleanup_connections() != 10838.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_networkeventhandlewrapper_force_reconnect() != 14546.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_networkeventhandlewrapper_handle_app_lifecycle_changed() != 7773.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_networkeventhandlewrapper_handle_network_path_changed() != 24952.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_constructor_opusencoder_new() != 34824.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_constructor_actrnode_new_from_linked_workload() != 10568.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_constructor_actrnode_new_from_package_file() != 59585.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_constructor_actrnode_new_from_package_file_with_observers() != 60905.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_constructor_dynamicworkload_new() != 1634.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_constructor_runtimeobservers_new() != 44140.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_datastreamcallback_on_stream() != 53144.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_mediatrackcallback_on_sample() != 56040.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_logcallback_on_log() != 3599.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_credentialobserverbridge_on_renewed() != 1839.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_credentialobserverbridge_on_expiring() != 44972.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_mailboxobserverbridge_on_backpressure() != 54800.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_signalingobserverbridge_on_connecting() != 19209.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_signalingobserverbridge_on_connected() != 4846.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_signalingobserverbridge_on_disconnected() != 42197.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_webrtcobserverbridge_on_connecting() != 29294.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_webrtcobserverbridge_on_connected() != 40934.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_webrtcobserverbridge_on_disconnected() != 44359.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_websocketobserverbridge_on_connecting() != 31917.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_websocketobserverbridge_on_connected() != 11292.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_websocketobserverbridge_on_disconnected() != 4256.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_workloadlifecyclebridge_on_start() != 17867.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_workloadlifecyclebridge_on_ready() != 46460.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_workloadlifecyclebridge_on_stop() != 64064.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_workloadlifecyclebridge_on_error() != 55342.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_actr_checksum_method_workloadlifecyclebridge_dispatch() != 33960.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}
/**
* @suppress
*/
public fun uniffiEnsureInitialized() {
IntegrityCheckingUniffiLib
// UniffiLib() initialized as objects are used, but we still need to explicitly
// reference it so initialization across crates works as expected.
UniffiLib
}
// Async support
// Async return type handlers
internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toByte()
internal const val UNIFFI_RUST_FUTURE_POLL_WAKE = 1.toByte()
internal val uniffiContinuationHandleMap = UniffiHandleMap<CancellableContinuation<Byte>>()
// FFI type for Rust future continuations
internal object uniffiRustFutureContinuationCallbackImpl: UniffiRustFutureContinuationCallback {
override fun callback(data: Long, pollResult: Byte) {
uniffiContinuationHandleMap.remove(data).resume(pollResult)
}
}
internal suspend fun<T, F, E: kotlin.Exception> uniffiRustCallAsync(
rustFuture: Long,
pollFunc: (Long, UniffiRustFutureContinuationCallback, Long) -> Unit,
completeFunc: (Long, UniffiRustCallStatus) -> F,
freeFunc: (Long) -> Unit,
liftFunc: (F) -> T,
errorHandler: UniffiRustCallStatusErrorHandler<E>
): T {
try {
do {
val pollResult = suspendCancellableCoroutine<Byte> { continuation ->
pollFunc(
rustFuture,
uniffiRustFutureContinuationCallbackImpl,
uniffiContinuationHandleMap.insert(continuation)
)
}
} while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY);
return liftFunc(
uniffiRustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) })
)
} finally {
freeFunc(rustFuture)
}
}
internal inline fun<T> uniffiTraitInterfaceCallAsync(
crossinline makeCall: suspend () -> T,
crossinline handleSuccess: (T) -> Unit,
crossinline handleError: (UniffiRustCallStatus.ByValue) -> Unit,
uniffiOutDroppedCallback: UniffiForeignFutureDroppedCallbackStruct,
) {
// Using `GlobalScope` is labeled as a "delicate API" and generally discouraged in Kotlin programs, since it breaks structured concurrency.
// However, our parent task is a Rust future, so we're going to need to break structure concurrency in any case.
//
// Uniffi does its best to support structured concurrency across the FFI.
// If the Rust future is dropped, `uniffiForeignFutureDroppedCallbackImpl` is called, which will cancel the Kotlin coroutine if it's still running.
@OptIn(DelicateCoroutinesApi::class)
val job = GlobalScope.launch coroutineBlock@ {
// Note: it's important we call either `handleSuccess` or `handleError` exactly once. Each
// call consumes an Arc reference, which means there should be no possibility of a double
// call. The following code is structured so that will will never call both `handleSuccess`
// and `handleError`, even in the face of weird exceptions.
//
// In extreme circumstances we may not call either, for example if we fail to make the JNA
// call to `handleSuccess`. This means we will leak the Arc reference, which is better than
// double-freeing it.
val callResult = try {
makeCall()
} catch(e: kotlin.Exception) {
handleError(
UniffiRustCallStatus.create(
UNIFFI_CALL_UNEXPECTED_ERROR,
FfiConverterString.lower(e.toString()),
)
)
return@coroutineBlock
}
handleSuccess(callResult)
}
val handle = uniffiForeignFutureHandleMap.insert(job)
uniffiOutDroppedCallback.uniffiSetValue(UniffiForeignFutureDroppedCallbackStruct(handle, uniffiForeignFutureDroppedCallbackImpl))
}
internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallAsyncWithError(
crossinline makeCall: suspend () -> T,
crossinline handleSuccess: (T) -> Unit,
crossinline handleError: (UniffiRustCallStatus.ByValue) -> Unit,
crossinline lowerError: (E) -> RustBuffer.ByValue,
uniffiOutDroppedCallback: UniffiForeignFutureDroppedCallbackStruct,
) {
// See uniffiTraitInterfaceCallAsync for details on `DelicateCoroutinesApi`
@OptIn(DelicateCoroutinesApi::class)
val job = GlobalScope.launch coroutineBlock@ {
// See the note in uniffiTraitInterfaceCallAsync for details on `handleSuccess` and
// `handleError`.
val callResult = try {
makeCall()
} catch(e: kotlin.Exception) {
if (e is E) {
handleError(
UniffiRustCallStatus.create(
UNIFFI_CALL_ERROR,
lowerError(e),
)
)
} else {
handleError(
UniffiRustCallStatus.create(
UNIFFI_CALL_UNEXPECTED_ERROR,
FfiConverterString.lower(e.toString()),
)
)
}
return@coroutineBlock
}
handleSuccess(callResult)
}
val handle = uniffiForeignFutureHandleMap.insert(job)
uniffiOutDroppedCallback.uniffiSetValue(UniffiForeignFutureDroppedCallbackStruct(handle, uniffiForeignFutureDroppedCallbackImpl))
}
internal val uniffiForeignFutureHandleMap = UniffiHandleMap<Job>()
internal object uniffiForeignFutureDroppedCallbackImpl: UniffiForeignFutureDroppedCallback {
override fun callback(handle: Long) {
val job = uniffiForeignFutureHandleMap.remove(handle)
if (!job.isCompleted) {
job.cancel()
}
}
}
// For testing
public fun uniffiForeignFutureHandleCount() = uniffiForeignFutureHandleMap.size
// Public interface members begin here.
// Interface implemented by anything that can contain an object reference.
//
// Such types expose a `destroy()` method that must be called to cleanly
// dispose of the contained objects. Failure to call this method may result
// in memory leaks.
//
// The easiest way to ensure this method is called is to use the `.use`
// helper method to execute a block and destroy the object at the end.
interface Disposable {
fun destroy()
companion object {
fun destroy(vararg args: Any?) {
for (arg in args) {
when (arg) {
is Disposable -> arg.destroy()
is ArrayList<*> -> {
for (idx in arg.indices) {
val element = arg[idx]
if (element is Disposable) {
element.destroy()
}
}
}
is Map<*, *> -> {
for (element in arg.values) {
if (element is Disposable) {
element.destroy()
}
}
}
is Iterable<*> -> {
for (element in arg) {
if (element is Disposable) {
element.destroy()
}
}
}
}
}
}
}
}
/**
* @suppress
*/
inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
try {
block(this)
} finally {
try {
// N.B. our implementation is on the nullable type `Disposable?`.
this?.destroy()
} catch (e: Throwable) {
// swallow
}
}
/**
* Placeholder object used to signal that we're constructing an interface with a FFI handle.
*
* This is the first argument for interface constructors that input a raw handle. It exists is that
* so we can avoid signature conflicts when an interface has a regular constructor than inputs a
* Long.
*
* @suppress
* */
object UniffiWithHandle
/**
* Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
*
* @suppress
* */
object NoHandle// Magic number for the Rust proxy to call using the same mechanism as every other method,
// to free the callback once it's dropped by Rust.
internal const val IDX_CALLBACK_FREE = 0
// Callback return codes
internal const val UNIFFI_CALLBACK_SUCCESS = 0
internal const val UNIFFI_CALLBACK_ERROR = 1
internal const val UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2
/**
* @suppress
*/
public abstract class FfiConverterCallbackInterface<CallbackInterface: Any>: FfiConverter<CallbackInterface, Long> {
internal val handleMap = UniffiHandleMap<CallbackInterface>()
internal fun drop(handle: Long) {
handleMap.remove(handle)
}
override fun lift(value: Long): CallbackInterface {
return handleMap.get(value)
}
override fun read(buf: ByteBuffer) = lift(buf.getLong())
override fun lower(value: CallbackInterface) = handleMap.insert(value)
override fun allocationSize(value: CallbackInterface) = 8UL
override fun write(value: CallbackInterface, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
/**
* The cleaner interface for Object finalization code to run.
* This is the entry point to any implementation that we're using.
*
* The cleaner registers objects and returns cleanables, so now we are
* defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
* different implmentations available at compile time.
*
* @suppress
*/
interface UniffiCleaner {
interface Cleanable {
fun clean()
}
fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable
companion object
}
// The fallback Jna cleaner, which is available for both Android, and the JVM.
private class UniffiJnaCleaner : UniffiCleaner {
private val cleaner = com.sun.jna.internal.Cleaner.getCleaner()
override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
UniffiJnaCleanable(cleaner.register(value, cleanUpTask))
}
private class UniffiJnaCleanable(
private val cleanable: com.sun.jna.internal.Cleaner.Cleanable,
) : UniffiCleaner.Cleanable {
override fun clean() = cleanable.clean()
}
// We decide at uniffi binding generation time whether we were
// using Android or not.
// There are further runtime checks to chose the correct implementation
// of the cleaner.
private fun UniffiCleaner.Companion.create(): UniffiCleaner =
try {
// For safety's sake: if the library hasn't been run in android_cleaner = true
// mode, but is being run on Android, then we still need to think about
// Android API versions.
// So we check if java.lang.ref.Cleaner is there, and use that…
java.lang.Class.forName("java.lang.ref.Cleaner")
JavaLangRefCleaner()
} catch (e: ClassNotFoundException) {
// … otherwise, fallback to the JNA cleaner.
UniffiJnaCleaner()
}
private class JavaLangRefCleaner : UniffiCleaner {
val cleaner = java.lang.ref.Cleaner.create()
override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
}
private class JavaLangRefCleanable(
val cleanable: java.lang.ref.Cleaner.Cleanable
) : UniffiCleaner.Cleanable {
override fun clean() = cleanable.clean()
}
/**
* @suppress
*/
public object FfiConverterUByte: FfiConverter<UByte, Byte> {
override fun lift(value: Byte): UByte {
return value.toUByte()
}
override fun read(buf: ByteBuffer): UByte {
return lift(buf.get())
}
override fun lower(value: UByte): Byte {
return value.toByte()
}
override fun allocationSize(value: UByte) = 1UL
override fun write(value: UByte, buf: ByteBuffer) {
buf.put(value.toByte())
}
}
/**
* @suppress
*/
public object FfiConverterUShort: FfiConverter<UShort, Short> {
override fun lift(value: Short): UShort {
return value.toUShort()
}
override fun read(buf: ByteBuffer): UShort {
return lift(buf.getShort())
}
override fun lower(value: UShort): Short {
return value.toShort()
}
override fun allocationSize(value: UShort) = 2UL
override fun write(value: UShort, buf: ByteBuffer) {
buf.putShort(value.toShort())
}
}
/**
* @suppress
*/
public object FfiConverterUInt: FfiConverter<UInt, Int> {
override fun lift(value: Int): UInt {
return value.toUInt()
}
override fun read(buf: ByteBuffer): UInt {
return lift(buf.getInt())
}
override fun lower(value: UInt): Int {
return value.toInt()
}
override fun allocationSize(value: UInt) = 4UL
override fun write(value: UInt, buf: ByteBuffer) {
buf.putInt(value.toInt())
}
}
/**
* @suppress
*/
public object FfiConverterULong: FfiConverter<ULong, Long> {
override fun lift(value: Long): ULong {
return value.toULong()
}
override fun read(buf: ByteBuffer): ULong {
return lift(buf.getLong())
}
override fun lower(value: ULong): Long {
return value.toLong()
}
override fun allocationSize(value: ULong) = 8UL
override fun write(value: ULong, buf: ByteBuffer) {
buf.putLong(value.toLong())
}
}
/**
* @suppress
*/
public object FfiConverterLong: FfiConverter<Long, Long> {
override fun lift(value: Long): Long {
return value
}
override fun read(buf: ByteBuffer): Long {
return buf.getLong()
}
override fun lower(value: Long): Long {
return value
}
override fun allocationSize(value: Long) = 8UL
override fun write(value: Long, buf: ByteBuffer) {
buf.putLong(value)
}
}
/**
* @suppress
*/
public object FfiConverterFloat: FfiConverter<Float, Float> {
override fun lift(value: Float): Float {
return value
}
override fun read(buf: ByteBuffer): Float {
return buf.getFloat()
}
override fun lower(value: Float): Float {
return value
}
override fun allocationSize(value: Float) = 4UL
override fun write(value: Float, buf: ByteBuffer) {
buf.putFloat(value)
}
}
/**
* @suppress
*/
public object FfiConverterBoolean: FfiConverter<Boolean, Byte> {
override fun lift(value: Byte): Boolean {
return value.toInt() != 0
}
override fun read(buf: ByteBuffer): Boolean {
return lift(buf.get())
}
override fun lower(value: Boolean): Byte {
return if (value) 1.toByte() else 0.toByte()
}
override fun allocationSize(value: Boolean) = 1UL
override fun write(value: Boolean, buf: ByteBuffer) {
buf.put(lower(value))
}
}
/**
* @suppress
*/
public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
// Note: we don't inherit from FfiConverterRustBuffer, because we use a
// special encoding when lowering/lifting. We can use `RustBuffer.len` to
// store our length and avoid writing it out to the buffer.
override fun lift(value: RustBuffer.ByValue): String {
try {
val byteArr = ByteArray(value.len.toInt())
value.asByteBuffer()!!.get(byteArr)
return byteArr.toString(Charsets.UTF_8)
} finally {
RustBuffer.free(value)
}
}
override fun read(buf: ByteBuffer): String {
val len = buf.getInt()
val byteArr = ByteArray(len)
buf.get(byteArr)
return byteArr.toString(Charsets.UTF_8)
}
fun toUtf8(value: String): ByteBuffer {
// Make sure we don't have invalid UTF-16, check for lone surrogates.
return Charsets.UTF_8.newEncoder().run {
onMalformedInput(CodingErrorAction.REPORT)
encode(CharBuffer.wrap(value))
}
}
override fun lower(value: String): RustBuffer.ByValue {
val byteBuf = toUtf8(value)
// Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
// to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
rbuf.asByteBuffer()!!.put(byteBuf)
return rbuf
}
// We aren't sure exactly how many bytes our string will be once it's UTF-8
// encoded. Allocate 3 bytes per UTF-16 code unit which will always be
// enough.
override fun allocationSize(value: String): ULong {
val sizeForLength = 4UL
val sizeForString = value.length.toULong() * 3UL
return sizeForLength + sizeForString
}
override fun write(value: String, buf: ByteBuffer) {
val byteBuf = toUtf8(value)
buf.putInt(byteBuf.limit())
buf.put(byteBuf)
}
}
/**
* @suppress
*/
public object FfiConverterByteArray: FfiConverterRustBuffer<ByteArray> {
override fun read(buf: ByteBuffer): ByteArray {
val len = buf.getInt()
val byteArr = ByteArray(len)
buf.get(byteArr)
return byteArr
}
override fun allocationSize(value: ByteArray): ULong {
return 4UL + value.size.toULong()
}
override fun write(value: ByteArray, buf: ByteBuffer) {
buf.putInt(value.size)
buf.put(value)
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Wrapper for a package-backed runtime before startup.
*/
public interface ActrNodeInterface {
/**
* Create a network event handle for platform callbacks.
*
* This must be called before `start()`.
*/
fun `createNetworkEventHandle`(): NetworkEventHandleWrapper
/**
* Start the package-backed node and return a running actor reference.
*/
suspend fun `start`(): ActrRefWrapper
companion object
}
/**
* Wrapper for a package-backed runtime before startup.
*/
open class ActrNode: Disposable, AutoCloseable, ActrNodeInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_actr_fn_free_actrnode(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_actr_fn_clone_actrnode(handle, status)
}
}
/**
* Create a network event handle for platform callbacks.
*
* This must be called before `start()`.
*/
@Throws(ActrException::class)override fun `createNetworkEventHandle`(): NetworkEventHandleWrapper {
return FfiConverterTypeNetworkEventHandleWrapper.lift(
callWithHandle {
uniffiRustCallWithError(ActrException) { _status ->
UniffiLib.uniffi_actr_fn_method_actrnode_create_network_event_handle(
it,
_status)
}
}
)
}
/**
* Start the package-backed node and return a running actor reference.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `start`() : ActrRefWrapper {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_actrnode_start(
uniffiHandle,
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_u64(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_u64(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_u64(future) },
// lift function
{ FfiConverterTypeActrRefWrapper.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
companion object {
/**
* Create a linked/static runtime from a foreign-language workload.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
suspend fun `newFromLinkedWorkload`(`configPath`: kotlin.String, `actorType`: ActrType, `workload`: DynamicWorkload) : ActrNode {
return uniffiRustCallAsync(
UniffiLib.uniffi_actr_fn_constructor_actrnode_new_from_linked_workload(FfiConverterString.lower(`configPath`),FfiConverterTypeActrType.lower(`actorType`),FfiConverterTypeDynamicWorkload.lower(`workload`),),
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_u64(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_u64(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_u64(future) },
// lift function
{ FfiConverterTypeActrNode.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Create a new runtime wrapper from config and a verified `.actr` package file.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
suspend fun `newFromPackageFile`(`configPath`: kotlin.String, `packagePath`: kotlin.String) : ActrNode {
return uniffiRustCallAsync(
UniffiLib.uniffi_actr_fn_constructor_actrnode_new_from_package_file(FfiConverterString.lower(`configPath`),FfiConverterString.lower(`packagePath`),),
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_u64(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_u64(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_u64(future) },
// lift function
{ FfiConverterTypeActrNode.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Create a package-backed runtime and install host-side observers.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
suspend fun `newFromPackageFileWithObservers`(`configPath`: kotlin.String, `packagePath`: kotlin.String, `observers`: RuntimeObservers) : ActrNode {
return uniffiRustCallAsync(
UniffiLib.uniffi_actr_fn_constructor_actrnode_new_from_package_file_with_observers(FfiConverterString.lower(`configPath`),FfiConverterString.lower(`packagePath`),FfiConverterTypeRuntimeObservers.lower(`observers`),),
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_u64(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_u64(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_u64(future) },
// lift function
{ FfiConverterTypeActrNode.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
}
}
/**
* @suppress
*/
public object FfiConverterTypeActrNode: FfiConverter<ActrNode, Long> {
override fun lower(value: ActrNode): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): ActrNode {
return ActrNode(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): ActrNode {
return lift(buf.getLong())
}
override fun allocationSize(value: ActrNode) = 8UL
override fun write(value: ActrNode, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Wrapper for a running actor reference.
*/
public interface ActrRefWrapperInterface {
/**
* Get the actor's ID.
*/
fun `actorId`(): ActrId
/**
* Call the local guest workload via RPC.
*/
suspend fun `call`(`routeKey`: kotlin.String, `payloadType`: PayloadType, `requestPayload`: kotlin.ByteArray, `timeoutMs`: kotlin.Long): kotlin.ByteArray
/**
* Discover actors of the specified type.
*/
suspend fun `discover`(`targetType`: ActrType, `count`: kotlin.UInt): List<ActrId>
/**
* Check if shutdown is already in progress.
*/
fun `isShuttingDown`(): kotlin.Boolean
/**
* Trigger shutdown.
*/
fun `shutdown`()
/**
* Send a one-way message to the local guest workload.
*/
suspend fun `tell`(`routeKey`: kotlin.String, `payloadType`: PayloadType, `messagePayload`: kotlin.ByteArray)
/**
* Wait for shutdown to complete.
*/
suspend fun `waitForShutdown`()
companion object
}
/**
* Wrapper for a running actor reference.
*/
open class ActrRefWrapper: Disposable, AutoCloseable, ActrRefWrapperInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_actr_fn_free_actrrefwrapper(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_actr_fn_clone_actrrefwrapper(handle, status)
}
}
/**
* Get the actor's ID.
*/override fun `actorId`(): ActrId {
return FfiConverterTypeActrId.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_method_actrrefwrapper_actor_id(
it,
_status)
}
}
)
}
/**
* Call the local guest workload via RPC.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `call`(`routeKey`: kotlin.String, `payloadType`: PayloadType, `requestPayload`: kotlin.ByteArray, `timeoutMs`: kotlin.Long) : kotlin.ByteArray {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_actrrefwrapper_call(
uniffiHandle,
FfiConverterString.lower(`routeKey`),FfiConverterTypePayloadType.lower(`payloadType`),FfiConverterByteArray.lower(`requestPayload`),FfiConverterLong.lower(`timeoutMs`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterByteArray.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Discover actors of the specified type.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `discover`(`targetType`: ActrType, `count`: kotlin.UInt) : List<ActrId> {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_actrrefwrapper_discover(
uniffiHandle,
FfiConverterTypeActrType.lower(`targetType`),FfiConverterUInt.lower(`count`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterSequenceTypeActrId.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Check if shutdown is already in progress.
*/override fun `isShuttingDown`(): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_method_actrrefwrapper_is_shutting_down(
it,
_status)
}
}
)
}
/**
* Trigger shutdown.
*/override fun `shutdown`()
=
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_method_actrrefwrapper_shutdown(
it,
_status)
}
}
/**
* Send a one-way message to the local guest workload.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `tell`(`routeKey`: kotlin.String, `payloadType`: PayloadType, `messagePayload`: kotlin.ByteArray) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_actrrefwrapper_tell(
uniffiHandle,
FfiConverterString.lower(`routeKey`),FfiConverterTypePayloadType.lower(`payloadType`),FfiConverterByteArray.lower(`messagePayload`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Wait for shutdown to complete.
*/
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `waitForShutdown`() {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_actrrefwrapper_wait_for_shutdown(
uniffiHandle,
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
UniffiNullRustCallStatusErrorHandler,
)
}
/**
* @suppress
*/
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeActrRefWrapper: FfiConverter<ActrRefWrapper, Long> {
override fun lower(value: ActrRefWrapper): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): ActrRefWrapper {
return ActrRefWrapper(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): ActrRefWrapper {
return lift(buf.getLong())
}
override fun allocationSize(value: ActrRefWrapper) = 8UL
override fun write(value: ActrRefWrapper, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Context provided to the workload
*/
public interface ContextBridgeInterface {
/**
* Add a media track to the WebRTC connection with the target
*/
suspend fun `addMediaTrack`(`target`: ActrId, `trackId`: kotlin.String, `codec`: kotlin.String, `mediaType`: kotlin.String)
/**
* Call a remote actor via RPC (simplified for FFI)
*
* # Arguments
* - `target`: Target actor ID
* - `route_key`: RPC route key (e.g., "echo.EchoService.Echo")
* - `payload_type`: Payload transmission type (RpcReliable, RpcSignal, etc.)
* - `payload`: Request payload bytes (protobuf encoded)
* - `timeout_ms`: Timeout in milliseconds
*
* # Returns
* Response payload bytes (protobuf encoded)
*/
suspend fun `callRaw`(`target`: ActrId, `routeKey`: kotlin.String, `payloadType`: PayloadType, `payload`: kotlin.ByteArray, `timeoutMs`: kotlin.Long): kotlin.ByteArray
/**
* Discover an actor of the specified type
*
* # Arguments
* - `target_type`: Actor type to discover (manufacturer + name)
*
* # Returns
* The ActrId of a discovered actor
*/
suspend fun `discover`(`targetType`: ActrType): ActrId
/**
* Register a callback for incoming media track samples
*/
suspend fun `registerMediaTrack`(`trackId`: kotlin.String, `callback`: MediaTrackCallback)
/**
* Register a DataStream callback for a stream ID.
*/
suspend fun `registerStream`(`streamId`: kotlin.String, `callback`: DataStreamCallback)
/**
* Remove a media track from the WebRTC connection with the target.
*/
suspend fun `removeMediaTrack`(`target`: ActrId, `trackId`: kotlin.String)
/**
* Send a DataStream to a remote actor (Fast Path)
*
* # Arguments
* - `target`: Target actor ID
* - `chunk`: DataStream containing stream_id, sequence, payload, etc.
* - `payload_type`: Stream lane selection for delivery guarantees.
*/
suspend fun `sendDataStream`(`target`: ActrId, `chunk`: DataStream, `payloadType`: PayloadType)
/**
* Send a media sample via WebRTC native RTP track
*/
suspend fun `sendMediaSample`(`target`: ActrId, `trackId`: kotlin.String, `sample`: MediaSample)
/**
* Send a one-way message to an actor (fire-and-forget)
*
* # Arguments
* - `target`: Target actor ID
* - `route_key`: RPC route key (e.g., "echo.EchoService.Echo")
* - `payload_type`: Payload transmission type (RpcReliable, RpcSignal, etc.)
* - `payload`: Message payload bytes (protobuf encoded)
*/
suspend fun `tellRaw`(`target`: ActrId, `routeKey`: kotlin.String, `payloadType`: PayloadType, `payload`: kotlin.ByteArray)
/**
* Unregister a media track callback
*/
suspend fun `unregisterMediaTrack`(`trackId`: kotlin.String)
/**
* Unregister a DataStream callback for a stream ID.
*/
suspend fun `unregisterStream`(`streamId`: kotlin.String)
companion object
}
/**
* Context provided to the workload
*/
open class ContextBridge: Disposable, AutoCloseable, ContextBridgeInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_actr_fn_free_contextbridge(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_actr_fn_clone_contextbridge(handle, status)
}
}
/**
* Add a media track to the WebRTC connection with the target
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `addMediaTrack`(`target`: ActrId, `trackId`: kotlin.String, `codec`: kotlin.String, `mediaType`: kotlin.String) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_add_media_track(
uniffiHandle,
FfiConverterTypeActrId.lower(`target`),FfiConverterString.lower(`trackId`),FfiConverterString.lower(`codec`),FfiConverterString.lower(`mediaType`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Call a remote actor via RPC (simplified for FFI)
*
* # Arguments
* - `target`: Target actor ID
* - `route_key`: RPC route key (e.g., "echo.EchoService.Echo")
* - `payload_type`: Payload transmission type (RpcReliable, RpcSignal, etc.)
* - `payload`: Request payload bytes (protobuf encoded)
* - `timeout_ms`: Timeout in milliseconds
*
* # Returns
* Response payload bytes (protobuf encoded)
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `callRaw`(`target`: ActrId, `routeKey`: kotlin.String, `payloadType`: PayloadType, `payload`: kotlin.ByteArray, `timeoutMs`: kotlin.Long) : kotlin.ByteArray {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_call_raw(
uniffiHandle,
FfiConverterTypeActrId.lower(`target`),FfiConverterString.lower(`routeKey`),FfiConverterTypePayloadType.lower(`payloadType`),FfiConverterByteArray.lower(`payload`),FfiConverterLong.lower(`timeoutMs`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterByteArray.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Discover an actor of the specified type
*
* # Arguments
* - `target_type`: Actor type to discover (manufacturer + name)
*
* # Returns
* The ActrId of a discovered actor
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `discover`(`targetType`: ActrType) : ActrId {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_discover(
uniffiHandle,
FfiConverterTypeActrType.lower(`targetType`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterTypeActrId.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Register a callback for incoming media track samples
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `registerMediaTrack`(`trackId`: kotlin.String, `callback`: MediaTrackCallback) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_register_media_track(
uniffiHandle,
FfiConverterString.lower(`trackId`),FfiConverterTypeMediaTrackCallback.lower(`callback`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Register a DataStream callback for a stream ID.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `registerStream`(`streamId`: kotlin.String, `callback`: DataStreamCallback) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_register_stream(
uniffiHandle,
FfiConverterString.lower(`streamId`),FfiConverterTypeDataStreamCallback.lower(`callback`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Remove a media track from the WebRTC connection with the target.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `removeMediaTrack`(`target`: ActrId, `trackId`: kotlin.String) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_remove_media_track(
uniffiHandle,
FfiConverterTypeActrId.lower(`target`),FfiConverterString.lower(`trackId`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Send a DataStream to a remote actor (Fast Path)
*
* # Arguments
* - `target`: Target actor ID
* - `chunk`: DataStream containing stream_id, sequence, payload, etc.
* - `payload_type`: Stream lane selection for delivery guarantees.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `sendDataStream`(`target`: ActrId, `chunk`: DataStream, `payloadType`: PayloadType) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_send_data_stream(
uniffiHandle,
FfiConverterTypeActrId.lower(`target`),FfiConverterTypeDataStream.lower(`chunk`),FfiConverterTypePayloadType.lower(`payloadType`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Send a media sample via WebRTC native RTP track
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `sendMediaSample`(`target`: ActrId, `trackId`: kotlin.String, `sample`: MediaSample) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_send_media_sample(
uniffiHandle,
FfiConverterTypeActrId.lower(`target`),FfiConverterString.lower(`trackId`),FfiConverterTypeMediaSample.lower(`sample`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Send a one-way message to an actor (fire-and-forget)
*
* # Arguments
* - `target`: Target actor ID
* - `route_key`: RPC route key (e.g., "echo.EchoService.Echo")
* - `payload_type`: Payload transmission type (RpcReliable, RpcSignal, etc.)
* - `payload`: Message payload bytes (protobuf encoded)
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `tellRaw`(`target`: ActrId, `routeKey`: kotlin.String, `payloadType`: PayloadType, `payload`: kotlin.ByteArray) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_tell_raw(
uniffiHandle,
FfiConverterTypeActrId.lower(`target`),FfiConverterString.lower(`routeKey`),FfiConverterTypePayloadType.lower(`payloadType`),FfiConverterByteArray.lower(`payload`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Unregister a media track callback
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `unregisterMediaTrack`(`trackId`: kotlin.String) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_unregister_media_track(
uniffiHandle,
FfiConverterString.lower(`trackId`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Unregister a DataStream callback for a stream ID.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `unregisterStream`(`streamId`: kotlin.String) {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_contextbridge_unregister_stream(
uniffiHandle,
FfiConverterString.lower(`streamId`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_void(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_void(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_void(future) },
// lift function
{ Unit },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* @suppress
*/
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeContextBridge: FfiConverter<ContextBridge, Long> {
override fun lower(value: ContextBridge): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): ContextBridge {
return ContextBridge(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): ContextBridge {
return lift(buf.getLong())
}
override fun allocationSize(value: ContextBridge) = 8UL
override fun write(value: ContextBridge, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Dynamic workload composed of one mandatory [`WorkloadLifecycleBridge`]
* and up to five optional category observers.
*
* Categories left as `None` fall back to the framework's built-in tracing
* defaults when the hook fires.
*/
public interface DynamicWorkloadInterface {
companion object
}
/**
* Dynamic workload composed of one mandatory [`WorkloadLifecycleBridge`]
* and up to five optional category observers.
*
* Categories left as `None` fall back to the framework's built-in tracing
* defaults when the hook fires.
*/
open class DynamicWorkload: Disposable, AutoCloseable, DynamicWorkloadInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
/**
* Construct a `DynamicWorkload` from a mandatory lifecycle bridge and
* a variadic set of optional per-category observers.
*/
constructor(`lifecycle`: WorkloadLifecycleBridge, `signaling`: SignalingObserverBridge?, `websocket`: WebSocketObserverBridge?, `webrtc`: WebRtcObserverBridge?, `credential`: CredentialObserverBridge?, `mailbox`: MailboxObserverBridge?) :
this(UniffiWithHandle,
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_constructor_dynamicworkload_new(
FfiConverterTypeWorkloadLifecycleBridge.lower(`lifecycle`),FfiConverterOptionalTypeSignalingObserverBridge.lower(`signaling`),FfiConverterOptionalTypeWebSocketObserverBridge.lower(`websocket`),FfiConverterOptionalTypeWebRtcObserverBridge.lower(`webrtc`),FfiConverterOptionalTypeCredentialObserverBridge.lower(`credential`),FfiConverterOptionalTypeMailboxObserverBridge.lower(`mailbox`),_status)
}
)
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_actr_fn_free_dynamicworkload(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_actr_fn_clone_dynamicworkload(handle, status)
}
}
/**
* @suppress
*/
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeDynamicWorkload: FfiConverter<DynamicWorkload, Long> {
override fun lower(value: DynamicWorkload): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): DynamicWorkload {
return DynamicWorkload(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): DynamicWorkload {
return lift(buf.getLong())
}
override fun allocationSize(value: DynamicWorkload) = 8UL
override fun write(value: DynamicWorkload, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Wrapper for `NetworkEventHandle` - network lifecycle callbacks.
*/
public interface NetworkEventHandleWrapperInterface {
/**
* Cleanup all connections without reconnecting.
*/
suspend fun `cleanupConnections`(`reason`: CleanupReason): NetworkEventResult
/**
* Force cleanup and reconnect.
*/
suspend fun `forceReconnect`(`reason`: ReconnectReason): NetworkEventResult
/**
* Handle an app lifecycle change.
*/
suspend fun `handleAppLifecycleChanged`(`state`: AppLifecycleState): NetworkEventResult
/**
* Handle a full network path change.
*/
suspend fun `handleNetworkPathChanged`(`snapshot`: NetworkSnapshot): NetworkEventResult
companion object
}
/**
* Wrapper for `NetworkEventHandle` - network lifecycle callbacks.
*/
open class NetworkEventHandleWrapper: Disposable, AutoCloseable, NetworkEventHandleWrapperInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_actr_fn_free_networkeventhandlewrapper(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_actr_fn_clone_networkeventhandlewrapper(handle, status)
}
}
/**
* Cleanup all connections without reconnecting.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `cleanupConnections`(`reason`: CleanupReason) : NetworkEventResult {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_networkeventhandlewrapper_cleanup_connections(
uniffiHandle,
FfiConverterTypeCleanupReason.lower(`reason`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterTypeNetworkEventResult.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Force cleanup and reconnect.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `forceReconnect`(`reason`: ReconnectReason) : NetworkEventResult {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_networkeventhandlewrapper_force_reconnect(
uniffiHandle,
FfiConverterTypeReconnectReason.lower(`reason`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterTypeNetworkEventResult.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Handle an app lifecycle change.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `handleAppLifecycleChanged`(`state`: AppLifecycleState) : NetworkEventResult {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_networkeventhandlewrapper_handle_app_lifecycle_changed(
uniffiHandle,
FfiConverterTypeAppLifecycleState.lower(`state`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterTypeNetworkEventResult.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* Handle a full network path change.
*/
@Throws(ActrException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `handleNetworkPathChanged`(`snapshot`: NetworkSnapshot) : NetworkEventResult {
return uniffiRustCallAsync(
callWithHandle { uniffiHandle ->
UniffiLib.uniffi_actr_fn_method_networkeventhandlewrapper_handle_network_path_changed(
uniffiHandle,
FfiConverterTypeNetworkSnapshot.lower(`snapshot`),
)
},
{ future, callback, continuation -> UniffiLib.ffi_actr_rust_future_poll_rust_buffer(future, callback, continuation) },
{ future, continuation -> UniffiLib.ffi_actr_rust_future_complete_rust_buffer(future, continuation) },
{ future -> UniffiLib.ffi_actr_rust_future_free_rust_buffer(future) },
// lift function
{ FfiConverterTypeNetworkEventResult.lift(it) },
// Error FFI converter
ActrException.ErrorHandler,
)
}
/**
* @suppress
*/
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeNetworkEventHandleWrapper: FfiConverter<NetworkEventHandleWrapper, Long> {
override fun lower(value: NetworkEventHandleWrapper): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): NetworkEventHandleWrapper {
return NetworkEventHandleWrapper(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): NetworkEventHandleWrapper {
return lift(buf.getLong())
}
override fun allocationSize(value: NetworkEventHandleWrapper) = 8UL
override fun write(value: NetworkEventHandleWrapper, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Reusable Opus encoder for Swift audio capture.
*/
public interface OpusEncoderInterface {
/**
* Encode one PCM float frame into one Opus packet.
*/
fun `encode`(`pcm`: List<kotlin.Float>): kotlin.ByteArray
fun `frameSize`(): kotlin.UShort
companion object
}
/**
* Reusable Opus encoder for Swift audio capture.
*/
open class OpusEncoder: Disposable, AutoCloseable, OpusEncoderInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
/**
* Create an Opus encoder for fixed-size PCM float frames.
*/
constructor(`sampleRate`: kotlin.UInt, `channels`: kotlin.UByte, `frameSize`: kotlin.UShort) :
this(UniffiWithHandle,
uniffiRustCallWithError(ActrException) { _status ->
UniffiLib.uniffi_actr_fn_constructor_opusencoder_new(
FfiConverterUInt.lower(`sampleRate`),FfiConverterUByte.lower(`channels`),FfiConverterUShort.lower(`frameSize`),_status)
}
)
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_actr_fn_free_opusencoder(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_actr_fn_clone_opusencoder(handle, status)
}
}
/**
* Encode one PCM float frame into one Opus packet.
*/
@Throws(ActrException::class)override fun `encode`(`pcm`: List<kotlin.Float>): kotlin.ByteArray {
return FfiConverterByteArray.lift(
callWithHandle {
uniffiRustCallWithError(ActrException) { _status ->
UniffiLib.uniffi_actr_fn_method_opusencoder_encode(
it,
FfiConverterSequenceFloat.lower(`pcm`),_status)
}
}
)
}
override fun `frameSize`(): kotlin.UShort {
return FfiConverterUShort.lift(
callWithHandle {
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_method_opusencoder_frame_size(
it,
_status)
}
}
)
}
/**
* @suppress
*/
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeOpusEncoder: FfiConverter<OpusEncoder, Long> {
override fun lower(value: OpusEncoder): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): OpusEncoder {
return OpusEncoder(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): OpusEncoder {
return lift(buf.getLong())
}
override fun allocationSize(value: OpusEncoder) = 8UL
override fun write(value: OpusEncoder, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
// This template implements a class for working with a Rust struct via a handle
// to the live Rust struct on the other side of the FFI.
//
// There's some subtlety here, because we have to be careful not to operate on a Rust
// struct after it has been dropped, and because we must expose a public API for freeing
// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
//
// * Each instance holds an opaque handle to the underlying Rust struct.
// Method calls need to read this handle from the object's state and pass it in to
// the Rust FFI.
//
// * When an instance is no longer needed, its handle should be passed to a
// special destructor function provided by the Rust FFI, which will drop the
// underlying Rust struct.
//
// * Given an instance, calling code is expected to call the special
// `destroy` method in order to free it after use, either by calling it explicitly
// or by using a higher-level helper like the `use` method. Failing to do so risks
// leaking the underlying Rust struct.
//
// * We can't assume that calling code will do the right thing, and must be prepared
// to handle Kotlin method calls executing concurrently with or even after a call to
// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
//
// * We must never allow Rust code to operate on the underlying Rust struct after
// the destructor has been called, and must never call the destructor more than once.
// Doing so may trigger memory unsafety.
//
// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
// is implemented to call the destructor when the Kotlin object becomes unreachable.
// This is done in a background thread. This is not a panacea, and client code should be aware that
// 1. the thread may starve if some there are objects that have poorly performing
// `drop` methods or do significant work in their `drop` methods.
// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
//
// If we try to implement this with mutual exclusion on access to the handle, there is the
// possibility of a race between a method call and a concurrent call to `destroy`:
//
// * Thread A starts a method call, reads the value of the handle, but is interrupted
// before it can pass the handle over the FFI to Rust.
// * Thread B calls `destroy` and frees the underlying Rust struct.
// * Thread A resumes, passing the already-read handle value to Rust and triggering
// a use-after-free.
//
// One possible solution would be to use a `ReadWriteLock`, with each method call taking
// a read lock (and thus allowed to run concurrently) and the special `destroy` method
// taking a write lock (and thus blocking on live method calls). However, we aim not to
// generate methods with any hidden blocking semantics, and a `destroy` method that might
// block if called incorrectly seems to meet that bar.
//
// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
// has been called. These are updated according to the following rules:
//
// * The initial value of the counter is 1, indicating a live object with no in-flight calls.
// The initial value for the flag is false.
//
// * At the start of each method call, we atomically check the counter.
// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
// If it is nonzero them we atomically increment it by 1 and proceed with the method call.
//
// * At the end of each method call, we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// * When `destroy` is called, we atomically flip the flag from false to true.
// If the flag was already true we silently fail.
// Otherwise we atomically decrement and check the counter.
// If it has reached zero then we destroy the underlying Rust struct.
//
// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
//
// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
// called *and* all in-flight method calls have completed, avoiding violating any of the expectations
// of the underlying Rust code.
//
// This makes a cleaner a better alternative to _not_ calling `destroy()` as
// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
// thread may be starved, and the app will leak memory.
//
// In this case, `destroy`ing manually may be a better solution.
//
// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
// with Rust peers are reclaimed:
//
// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
// 3. The memory is reclaimed when the process terminates.
//
// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
//
/**
* Runtime-only observers for package-backed hosts.
*
* Unlike [`DynamicWorkload`], this object does not represent actor business
* logic and does not need lifecycle or dispatch callbacks. Mobile shells use
* it to observe transport readiness for UI state and intent retry decisions
* while the package guest continues to own actor dispatch.
*/
public interface RuntimeObserversInterface {
companion object
}
/**
* Runtime-only observers for package-backed hosts.
*
* Unlike [`DynamicWorkload`], this object does not represent actor business
* logic and does not need lifecycle or dispatch callbacks. Mobile shells use
* it to observe transport readiness for UI state and intent retry decisions
* while the package guest continues to own actor dispatch.
*/
open class RuntimeObservers: Disposable, AutoCloseable, RuntimeObserversInterface
{
@Suppress("UNUSED_PARAMETER")
/**
* @suppress
*/
constructor(withHandle: UniffiWithHandle, handle: Long) {
this.handle = handle
this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(handle))
}
/**
* @suppress
*
* This constructor can be used to instantiate a fake object. Only used for tests. Any
* attempt to actually use an object constructed this way will fail as there is no
* connected Rust object.
*/
@Suppress("UNUSED_PARAMETER")
constructor(noHandle: NoHandle) {
this.handle = 0
this.cleanable = null
}
/**
* Construct host-side observers for a package-backed runtime.
*/
constructor(`signaling`: SignalingObserverBridge?, `websocket`: WebSocketObserverBridge?, `webrtc`: WebRtcObserverBridge?, `credential`: CredentialObserverBridge?, `mailbox`: MailboxObserverBridge?) :
this(UniffiWithHandle,
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_constructor_runtimeobservers_new(
FfiConverterOptionalTypeSignalingObserverBridge.lower(`signaling`),FfiConverterOptionalTypeWebSocketObserverBridge.lower(`websocket`),FfiConverterOptionalTypeWebRtcObserverBridge.lower(`webrtc`),FfiConverterOptionalTypeCredentialObserverBridge.lower(`credential`),FfiConverterOptionalTypeMailboxObserverBridge.lower(`mailbox`),_status)
}
)
protected val handle: Long
protected val cleanable: UniffiCleaner.Cleanable?
private val wasDestroyed = AtomicBoolean(false)
private val callCounter = AtomicLong(1)
override fun destroy() {
// Only allow a single call to this method.
// TODO: maybe we should log a warning if called more than once?
if (this.wasDestroyed.compareAndSet(false, true)) {
// This decrement always matches the initial count of 1 given at creation time.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
@Synchronized
override fun close() {
this.destroy()
}
internal inline fun <R> callWithHandle(block: (handle: Long) -> R): R {
// Check and increment the call counter, to keep the object alive.
// This needs a compare-and-set retry loop in case of concurrent updates.
do {
val c = this.callCounter.get()
if (c == 0L) {
throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
}
if (c == Long.MAX_VALUE) {
throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
}
} while (! this.callCounter.compareAndSet(c, c + 1L))
// Now we can safely do the method call without the handle being freed concurrently.
try {
return block(this.uniffiCloneHandle())
} finally {
// This decrement always matches the increment we performed above.
if (this.callCounter.decrementAndGet() == 0L) {
cleanable?.clean()
}
}
}
// Use a static inner class instead of a closure so as not to accidentally
// capture `this` as part of the cleanable's action.
private class UniffiCleanAction(private val handle: Long) : Runnable {
override fun run() {
if (handle == 0.toLong()) {
// Fake object created with `NoHandle`, don't try to free.
return;
}
uniffiRustCall { status ->
UniffiLib.uniffi_actr_fn_free_runtimeobservers(handle, status)
}
}
}
/**
* @suppress
*/
fun uniffiCloneHandle(): Long {
if (handle == 0.toLong()) {
throw InternalException("uniffiCloneHandle() called on NoHandle object");
}
return uniffiRustCall() { status ->
UniffiLib.uniffi_actr_fn_clone_runtimeobservers(handle, status)
}
}
/**
* @suppress
*/
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeRuntimeObservers: FfiConverter<RuntimeObservers, Long> {
override fun lower(value: RuntimeObservers): Long {
return value.uniffiCloneHandle()
}
override fun lift(value: Long): RuntimeObservers {
return RuntimeObservers(UniffiWithHandle, value)
}
override fun read(buf: ByteBuffer): RuntimeObservers {
return lift(buf.getLong())
}
override fun allocationSize(value: RuntimeObservers) = 8UL
override fun write(value: RuntimeObservers, buf: ByteBuffer) {
buf.putLong(lower(value))
}
}
/**
* Actor identifier (realm + serial_number + type)
*/
data class ActrId (
var `realm`: Realm
,
var `serialNumber`: kotlin.ULong
,
var `type`: ActrType
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeActrId: FfiConverterRustBuffer<ActrId> {
override fun read(buf: ByteBuffer): ActrId {
return ActrId(
FfiConverterTypeRealm.read(buf),
FfiConverterULong.read(buf),
FfiConverterTypeActrType.read(buf),
)
}
override fun allocationSize(value: ActrId) = (
FfiConverterTypeRealm.allocationSize(value.`realm`) +
FfiConverterULong.allocationSize(value.`serialNumber`) +
FfiConverterTypeActrType.allocationSize(value.`type`)
)
override fun write(value: ActrId, buf: ByteBuffer) {
FfiConverterTypeRealm.write(value.`realm`, buf)
FfiConverterULong.write(value.`serialNumber`, buf)
FfiConverterTypeActrType.write(value.`type`, buf)
}
}
/**
* Actor type (manufacturer + name + version)
*/
data class ActrType (
var `manufacturer`: kotlin.String
,
var `name`: kotlin.String
,
var `version`: kotlin.String
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeActrType: FfiConverterRustBuffer<ActrType> {
override fun read(buf: ByteBuffer): ActrType {
return ActrType(
FfiConverterString.read(buf),
FfiConverterString.read(buf),
FfiConverterString.read(buf),
)
}
override fun allocationSize(value: ActrType) = (
FfiConverterString.allocationSize(value.`manufacturer`) +
FfiConverterString.allocationSize(value.`name`) +
FfiConverterString.allocationSize(value.`version`)
)
override fun write(value: ActrType, buf: ByteBuffer) {
FfiConverterString.write(value.`manufacturer`, buf)
FfiConverterString.write(value.`name`, buf)
FfiConverterString.write(value.`version`, buf)
}
}
/**
* Mailbox backpressure event.
*/
data class BackpressureEventBridge (
var `queueLen`: kotlin.ULong
,
var `threshold`: kotlin.ULong
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeBackpressureEventBridge: FfiConverterRustBuffer<BackpressureEventBridge> {
override fun read(buf: ByteBuffer): BackpressureEventBridge {
return BackpressureEventBridge(
FfiConverterULong.read(buf),
FfiConverterULong.read(buf),
)
}
override fun allocationSize(value: BackpressureEventBridge) = (
FfiConverterULong.allocationSize(value.`queueLen`) +
FfiConverterULong.allocationSize(value.`threshold`)
)
override fun write(value: BackpressureEventBridge, buf: ByteBuffer) {
FfiConverterULong.write(value.`queueLen`, buf)
FfiConverterULong.write(value.`threshold`, buf)
}
}
/**
* Public payload for send preflight failures.
*/
data class ConnectionNotReadyInfo (
var `retryAfterMs`: kotlin.ULong?
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeConnectionNotReadyInfo: FfiConverterRustBuffer<ConnectionNotReadyInfo> {
override fun read(buf: ByteBuffer): ConnectionNotReadyInfo {
return ConnectionNotReadyInfo(
FfiConverterOptionalULong.read(buf),
)
}
override fun allocationSize(value: ConnectionNotReadyInfo) = (
FfiConverterOptionalULong.allocationSize(value.`retryAfterMs`)
)
override fun write(value: ConnectionNotReadyInfo, buf: ByteBuffer) {
FfiConverterOptionalULong.write(value.`retryAfterMs`, buf)
}
}
/**
* Credential renewal / warning event.
*/
data class CredentialEventBridge (
/**
* New credential expiry as milliseconds since UNIX epoch.
*/
var `newExpiryMs`: kotlin.Long
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeCredentialEventBridge: FfiConverterRustBuffer<CredentialEventBridge> {
override fun read(buf: ByteBuffer): CredentialEventBridge {
return CredentialEventBridge(
FfiConverterLong.read(buf),
)
}
override fun allocationSize(value: CredentialEventBridge) = (
FfiConverterLong.allocationSize(value.`newExpiryMs`)
)
override fun write(value: CredentialEventBridge, buf: ByteBuffer) {
FfiConverterLong.write(value.`newExpiryMs`, buf)
}
}
/**
* DataStream for fast-path data transmission
*
* Used for streaming application data (non-media):
* - File transfer chunks
* - Game state updates
* - Custom protocol streams
*/
data class DataStream (
/**
* Stream identifier (globally unique)
*/
var `streamId`: kotlin.String
,
/**
* Sequence number for ordering
*/
var `sequence`: kotlin.ULong
,
/**
* Payload data
*/
var `payload`: kotlin.ByteArray
,
/**
* Optional metadata
*/
var `metadata`: List<MetadataEntry>
,
/**
* Optional timestamp in milliseconds
*/
var `timestampMs`: kotlin.Long?
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeDataStream: FfiConverterRustBuffer<DataStream> {
override fun read(buf: ByteBuffer): DataStream {
return DataStream(
FfiConverterString.read(buf),
FfiConverterULong.read(buf),
FfiConverterByteArray.read(buf),
FfiConverterSequenceTypeMetadataEntry.read(buf),
FfiConverterOptionalLong.read(buf),
)
}
override fun allocationSize(value: DataStream) = (
FfiConverterString.allocationSize(value.`streamId`) +
FfiConverterULong.allocationSize(value.`sequence`) +
FfiConverterByteArray.allocationSize(value.`payload`) +
FfiConverterSequenceTypeMetadataEntry.allocationSize(value.`metadata`) +
FfiConverterOptionalLong.allocationSize(value.`timestampMs`)
)
override fun write(value: DataStream, buf: ByteBuffer) {
FfiConverterString.write(value.`streamId`, buf)
FfiConverterULong.write(value.`sequence`, buf)
FfiConverterByteArray.write(value.`payload`, buf)
FfiConverterSequenceTypeMetadataEntry.write(value.`metadata`, buf)
FfiConverterOptionalLong.write(value.`timestampMs`, buf)
}
}
/**
* FFI-shaped error event.
*
* `source` is the `Display` of the underlying [`actr_protocol::ActrError`]
* (the enum itself cannot cross UniFFI unchanged), and `timestamp_ms` is
* the wall-clock time encoded as milliseconds since the UNIX epoch.
*/
data class ErrorEventBridge (
/**
* Stringified underlying error (see [`actr_protocol::ActrError`]).
*/
var `source`: kotlin.String
,
/**
* Error-domain classification.
*/
var `category`: ErrorCategoryBridge
,
/**
* Free-form context (route key, handler name, stage).
*/
var `context`: kotlin.String
,
/**
* Wall-clock timestamp (milliseconds since UNIX epoch).
*/
var `timestampMs`: kotlin.Long
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeErrorEventBridge: FfiConverterRustBuffer<ErrorEventBridge> {
override fun read(buf: ByteBuffer): ErrorEventBridge {
return ErrorEventBridge(
FfiConverterString.read(buf),
FfiConverterTypeErrorCategoryBridge.read(buf),
FfiConverterString.read(buf),
FfiConverterLong.read(buf),
)
}
override fun allocationSize(value: ErrorEventBridge) = (
FfiConverterString.allocationSize(value.`source`) +
FfiConverterTypeErrorCategoryBridge.allocationSize(value.`category`) +
FfiConverterString.allocationSize(value.`context`) +
FfiConverterLong.allocationSize(value.`timestampMs`)
)
override fun write(value: ErrorEventBridge, buf: ByteBuffer) {
FfiConverterString.write(value.`source`, buf)
FfiConverterTypeErrorCategoryBridge.write(value.`category`, buf)
FfiConverterString.write(value.`context`, buf)
FfiConverterLong.write(value.`timestampMs`, buf)
}
}
/**
* Media sample for WebRTC native track
*/
data class MediaSample (
var `data`: kotlin.ByteArray
,
var `timestamp`: kotlin.UInt
,
var `codec`: kotlin.String
,
var `mediaType`: MediaType
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeMediaSample: FfiConverterRustBuffer<MediaSample> {
override fun read(buf: ByteBuffer): MediaSample {
return MediaSample(
FfiConverterByteArray.read(buf),
FfiConverterUInt.read(buf),
FfiConverterString.read(buf),
FfiConverterTypeMediaType.read(buf),
)
}
override fun allocationSize(value: MediaSample) = (
FfiConverterByteArray.allocationSize(value.`data`) +
FfiConverterUInt.allocationSize(value.`timestamp`) +
FfiConverterString.allocationSize(value.`codec`) +
FfiConverterTypeMediaType.allocationSize(value.`mediaType`)
)
override fun write(value: MediaSample, buf: ByteBuffer) {
FfiConverterByteArray.write(value.`data`, buf)
FfiConverterUInt.write(value.`timestamp`, buf)
FfiConverterString.write(value.`codec`, buf)
FfiConverterTypeMediaType.write(value.`mediaType`, buf)
}
}
/**
* Metadata entry for DataStream
*/
data class MetadataEntry (
var `key`: kotlin.String
,
var `value`: kotlin.String
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeMetadataEntry: FfiConverterRustBuffer<MetadataEntry> {
override fun read(buf: ByteBuffer): MetadataEntry {
return MetadataEntry(
FfiConverterString.read(buf),
FfiConverterString.read(buf),
)
}
override fun allocationSize(value: MetadataEntry) = (
FfiConverterString.allocationSize(value.`key`) +
FfiConverterString.allocationSize(value.`value`)
)
override fun write(value: MetadataEntry, buf: ByteBuffer) {
FfiConverterString.write(value.`key`, buf)
FfiConverterString.write(value.`value`, buf)
}
}
/**
* Network event processing result returned by the runtime
*/
data class NetworkEventResult (
var `event`: NetworkEvent
,
var `success`: kotlin.Boolean
,
var `error`: kotlin.String?
,
var `durationMs`: kotlin.ULong
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeNetworkEventResult: FfiConverterRustBuffer<NetworkEventResult> {
override fun read(buf: ByteBuffer): NetworkEventResult {
return NetworkEventResult(
FfiConverterTypeNetworkEvent.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterULong.read(buf),
)
}
override fun allocationSize(value: NetworkEventResult) = (
FfiConverterTypeNetworkEvent.allocationSize(value.`event`) +
FfiConverterBoolean.allocationSize(value.`success`) +
FfiConverterOptionalString.allocationSize(value.`error`) +
FfiConverterULong.allocationSize(value.`durationMs`)
)
override fun write(value: NetworkEventResult, buf: ByteBuffer) {
FfiConverterTypeNetworkEvent.write(value.`event`, buf)
FfiConverterBoolean.write(value.`success`, buf)
FfiConverterOptionalString.write(value.`error`, buf)
FfiConverterULong.write(value.`durationMs`, buf)
}
}
data class NetworkSnapshot (
var `sequence`: kotlin.ULong
,
var `availability`: NetworkAvailability
,
var `transport`: NetworkTransportFlags
,
var `isExpensive`: kotlin.Boolean
,
var `isConstrained`: kotlin.Boolean
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeNetworkSnapshot: FfiConverterRustBuffer<NetworkSnapshot> {
override fun read(buf: ByteBuffer): NetworkSnapshot {
return NetworkSnapshot(
FfiConverterULong.read(buf),
FfiConverterTypeNetworkAvailability.read(buf),
FfiConverterTypeNetworkTransportFlags.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
)
}
override fun allocationSize(value: NetworkSnapshot) = (
FfiConverterULong.allocationSize(value.`sequence`) +
FfiConverterTypeNetworkAvailability.allocationSize(value.`availability`) +
FfiConverterTypeNetworkTransportFlags.allocationSize(value.`transport`) +
FfiConverterBoolean.allocationSize(value.`isExpensive`) +
FfiConverterBoolean.allocationSize(value.`isConstrained`)
)
override fun write(value: NetworkSnapshot, buf: ByteBuffer) {
FfiConverterULong.write(value.`sequence`, buf)
FfiConverterTypeNetworkAvailability.write(value.`availability`, buf)
FfiConverterTypeNetworkTransportFlags.write(value.`transport`, buf)
FfiConverterBoolean.write(value.`isExpensive`, buf)
FfiConverterBoolean.write(value.`isConstrained`, buf)
}
}
data class NetworkTransportFlags (
var `wifi`: kotlin.Boolean
,
var `cellular`: kotlin.Boolean
,
var `ethernet`: kotlin.Boolean
,
var `vpn`: kotlin.Boolean
,
var `other`: kotlin.Boolean
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeNetworkTransportFlags: FfiConverterRustBuffer<NetworkTransportFlags> {
override fun read(buf: ByteBuffer): NetworkTransportFlags {
return NetworkTransportFlags(
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
FfiConverterBoolean.read(buf),
)
}
override fun allocationSize(value: NetworkTransportFlags) = (
FfiConverterBoolean.allocationSize(value.`wifi`) +
FfiConverterBoolean.allocationSize(value.`cellular`) +
FfiConverterBoolean.allocationSize(value.`ethernet`) +
FfiConverterBoolean.allocationSize(value.`vpn`) +
FfiConverterBoolean.allocationSize(value.`other`)
)
override fun write(value: NetworkTransportFlags, buf: ByteBuffer) {
FfiConverterBoolean.write(value.`wifi`, buf)
FfiConverterBoolean.write(value.`cellular`, buf)
FfiConverterBoolean.write(value.`ethernet`, buf)
FfiConverterBoolean.write(value.`vpn`, buf)
FfiConverterBoolean.write(value.`other`, buf)
}
}
/**
* Peer-scoped event payload (WebSocket / WebRTC).
*/
data class PeerEventBridge (
/**
* Remote peer identity.
*/
var `peer`: ActrId
,
/**
* `Some(true)` for WebRTC TURN-relayed, `Some(false)` for direct P2P,
* `None` for WebSocket (not applicable).
*/
var `relayed`: kotlin.Boolean?
,
/**
* Coarse WebRTC send-readiness state. `None` for WebSocket and old
* compatibility paths where the status is not available.
*/
var `status`: WebRtcPeerStatusBridge?
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePeerEventBridge: FfiConverterRustBuffer<PeerEventBridge> {
override fun read(buf: ByteBuffer): PeerEventBridge {
return PeerEventBridge(
FfiConverterTypeActrId.read(buf),
FfiConverterOptionalBoolean.read(buf),
FfiConverterOptionalTypeWebRtcPeerStatusBridge.read(buf),
)
}
override fun allocationSize(value: PeerEventBridge) = (
FfiConverterTypeActrId.allocationSize(value.`peer`) +
FfiConverterOptionalBoolean.allocationSize(value.`relayed`) +
FfiConverterOptionalTypeWebRtcPeerStatusBridge.allocationSize(value.`status`)
)
override fun write(value: PeerEventBridge, buf: ByteBuffer) {
FfiConverterTypeActrId.write(value.`peer`, buf)
FfiConverterOptionalBoolean.write(value.`relayed`, buf)
FfiConverterOptionalTypeWebRtcPeerStatusBridge.write(value.`status`, buf)
}
}
/**
* Security realm identifier
*/
data class Realm (
var `realmId`: kotlin.UInt
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeRealm: FfiConverterRustBuffer<Realm> {
override fun read(buf: ByteBuffer): Realm {
return Realm(
FfiConverterUInt.read(buf),
)
}
override fun allocationSize(value: Realm) = (
FfiConverterUInt.allocationSize(value.`realmId`)
)
override fun write(value: Realm, buf: ByteBuffer) {
FfiConverterUInt.write(value.`realmId`, buf)
}
}
/**
* RPC Envelope exposed to FFI
*
* Contains the route key, payload, and request ID for an RPC message.
*/
data class RpcEnvelopeBridge (
/**
* Route key for the RPC method (e.g., "echo.EchoService.Echo")
*/
var `routeKey`: kotlin.String
,
/**
* Request payload bytes (protobuf encoded)
*/
var `payload`: kotlin.ByteArray
,
/**
* Request ID for correlation
*/
var `requestId`: kotlin.String
){
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeRpcEnvelopeBridge: FfiConverterRustBuffer<RpcEnvelopeBridge> {
override fun read(buf: ByteBuffer): RpcEnvelopeBridge {
return RpcEnvelopeBridge(
FfiConverterString.read(buf),
FfiConverterByteArray.read(buf),
FfiConverterString.read(buf),
)
}
override fun allocationSize(value: RpcEnvelopeBridge) = (
FfiConverterString.allocationSize(value.`routeKey`) +
FfiConverterByteArray.allocationSize(value.`payload`) +
FfiConverterString.allocationSize(value.`requestId`)
)
override fun write(value: RpcEnvelopeBridge, buf: ByteBuffer) {
FfiConverterString.write(value.`routeKey`, buf)
FfiConverterByteArray.write(value.`payload`, buf)
FfiConverterString.write(value.`requestId`, buf)
}
}
/**
* Error type for actr operations.
*
* The first ten variants mirror `actr_protocol::ActrError` exactly; the
* remaining binding-local variants capture pre-protocol failures that
* originate inside the FFI shell (config parsing, package loading, etc.).
*/
sealed class ActrException: kotlin.Exception() {
class Unavailable(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
class ConnectionNotReady(
val `info`: ConnectionNotReadyInfo
) : ActrException() {
override val message
get() = "info=${ `info` }"
}
class TimedOut(
) : ActrException() {
override val message
get() = ""
}
class NotFound(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
class PermissionDenied(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
class InvalidArgument(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
class UnknownRoute(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
class DependencyNotFound(
val `serviceName`: kotlin.String,
val `detail`: kotlin.String
) : ActrException() {
override val message
get() = "serviceName=${ `serviceName` }, detail=${ `detail` }"
}
class DecodeFailure(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
class NotImplemented(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
class Internal(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
/**
* Config file parsing / trust resolution failed before the runtime could
* hand the request over to the protocol layer.
*
* Classified as `ErrorKind::Client` — the caller supplied a bad manifest
* or runtime config.
*/
class Config(
val `msg`: kotlin.String
) : ActrException() {
override val message
get() = "msg=${ `msg` }"
}
companion object ErrorHandler : UniffiRustCallStatusErrorHandler<ActrException> {
override fun lift(error_buf: RustBuffer.ByValue): ActrException = FfiConverterTypeActrError.lift(error_buf)
}
}
/**
* @suppress
*/
public object FfiConverterTypeActrError : FfiConverterRustBuffer<ActrException> {
override fun read(buf: ByteBuffer): ActrException {
return when(buf.getInt()) {
1 -> ActrException.Unavailable(
FfiConverterString.read(buf),
)
2 -> ActrException.ConnectionNotReady(
FfiConverterTypeConnectionNotReadyInfo.read(buf),
)
3 -> ActrException.TimedOut()
4 -> ActrException.NotFound(
FfiConverterString.read(buf),
)
5 -> ActrException.PermissionDenied(
FfiConverterString.read(buf),
)
6 -> ActrException.InvalidArgument(
FfiConverterString.read(buf),
)
7 -> ActrException.UnknownRoute(
FfiConverterString.read(buf),
)
8 -> ActrException.DependencyNotFound(
FfiConverterString.read(buf),
FfiConverterString.read(buf),
)
9 -> ActrException.DecodeFailure(
FfiConverterString.read(buf),
)
10 -> ActrException.NotImplemented(
FfiConverterString.read(buf),
)
11 -> ActrException.Internal(
FfiConverterString.read(buf),
)
12 -> ActrException.Config(
FfiConverterString.read(buf),
)
else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
}
}
override fun allocationSize(value: ActrException): ULong {
return when(value) {
is ActrException.Unavailable -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
is ActrException.ConnectionNotReady -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterTypeConnectionNotReadyInfo.allocationSize(value.`info`)
)
is ActrException.TimedOut -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
)
is ActrException.NotFound -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
is ActrException.PermissionDenied -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
is ActrException.InvalidArgument -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
is ActrException.UnknownRoute -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
is ActrException.DependencyNotFound -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`serviceName`)
+ FfiConverterString.allocationSize(value.`detail`)
)
is ActrException.DecodeFailure -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
is ActrException.NotImplemented -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
is ActrException.Internal -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
is ActrException.Config -> (
// Add the size for the Int that specifies the variant plus the size needed for all fields
4UL
+ FfiConverterString.allocationSize(value.`msg`)
)
}
}
override fun write(value: ActrException, buf: ByteBuffer) {
when(value) {
is ActrException.Unavailable -> {
buf.putInt(1)
FfiConverterString.write(value.`msg`, buf)
Unit
}
is ActrException.ConnectionNotReady -> {
buf.putInt(2)
FfiConverterTypeConnectionNotReadyInfo.write(value.`info`, buf)
Unit
}
is ActrException.TimedOut -> {
buf.putInt(3)
Unit
}
is ActrException.NotFound -> {
buf.putInt(4)
FfiConverterString.write(value.`msg`, buf)
Unit
}
is ActrException.PermissionDenied -> {
buf.putInt(5)
FfiConverterString.write(value.`msg`, buf)
Unit
}
is ActrException.InvalidArgument -> {
buf.putInt(6)
FfiConverterString.write(value.`msg`, buf)
Unit
}
is ActrException.UnknownRoute -> {
buf.putInt(7)
FfiConverterString.write(value.`msg`, buf)
Unit
}
is ActrException.DependencyNotFound -> {
buf.putInt(8)
FfiConverterString.write(value.`serviceName`, buf)
FfiConverterString.write(value.`detail`, buf)
Unit
}
is ActrException.DecodeFailure -> {
buf.putInt(9)
FfiConverterString.write(value.`msg`, buf)
Unit
}
is ActrException.NotImplemented -> {
buf.putInt(10)
FfiConverterString.write(value.`msg`, buf)
Unit
}
is ActrException.Internal -> {
buf.putInt(11)
FfiConverterString.write(value.`msg`, buf)
Unit
}
is ActrException.Config -> {
buf.putInt(12)
FfiConverterString.write(value.`msg`, buf)
Unit
}
}.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
}
}
sealed class AppLifecycleState {
object Background : AppLifecycleState()
data class Foreground(
val `backgroundDurationMs`: kotlin.ULong) : AppLifecycleState()
{
companion object
}
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeAppLifecycleState : FfiConverterRustBuffer<AppLifecycleState>{
override fun read(buf: ByteBuffer): AppLifecycleState {
return when(buf.getInt()) {
1 -> AppLifecycleState.Background
2 -> AppLifecycleState.Foreground(
FfiConverterULong.read(buf),
)
else -> throw RuntimeException("invalid enum value, something is very wrong!!")
}
}
override fun allocationSize(value: AppLifecycleState) = when(value) {
is AppLifecycleState.Background -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
)
}
is AppLifecycleState.Foreground -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
+ FfiConverterULong.allocationSize(value.`backgroundDurationMs`)
)
}
}
override fun write(value: AppLifecycleState, buf: ByteBuffer) {
when(value) {
is AppLifecycleState.Background -> {
buf.putInt(1)
Unit
}
is AppLifecycleState.Foreground -> {
buf.putInt(2)
FfiConverterULong.write(value.`backgroundDurationMs`, buf)
Unit
}
}.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
}
}
enum class CleanupReason {
APP_TERMINATING,
USER_LOGOUT,
STALE_CONNECTION_SUSPECTED,
MANUAL_RESET;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeCleanupReason: FfiConverterRustBuffer<CleanupReason> {
override fun read(buf: ByteBuffer) = try {
CleanupReason.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: CleanupReason) = 4UL
override fun write(value: CleanupReason, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
/**
* Coarse error-event classification mirror of
* [`actr_framework::ErrorCategory`].
*/
enum class ErrorCategoryBridge {
HANDLER_PANIC,
HANDLER_ERROR,
SIGNALING_FAILURE,
TRANSPORT_FAILURE,
DATA_STREAM_DELIVERY_UNCERTAIN;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeErrorCategoryBridge: FfiConverterRustBuffer<ErrorCategoryBridge> {
override fun read(buf: ByteBuffer) = try {
ErrorCategoryBridge.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: ErrorCategoryBridge) = 4UL
override fun write(value: ErrorCategoryBridge, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
/**
* Fault domain classification exposed to UniFFI consumers.
*
* Mirrors `actr_protocol::ErrorKind` so downstream generic policy code
* (retry / DLQ routing / alerting) can be written once and reused across
* Swift, Kotlin, and any future UniFFI language target.
*/
enum class ErrorKind {
/**
* Environmental fluctuation — retry with exponential backoff.
*/
TRANSIENT,
/**
* Caller error — bad request or system state; do not retry.
*/
CLIENT,
/**
* Framework bug or panic — do not retry; alert.
*/
INTERNAL,
/**
* Data corruption — route to Dead Letter Queue; manual intervention.
*/
CORRUPT;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeErrorKind: FfiConverterRustBuffer<ErrorKind> {
override fun read(buf: ByteBuffer) = try {
ErrorKind.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: ErrorKind) = 4UL
override fun write(value: ErrorKind, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
/**
* Media type for MediaTrack
*/
enum class MediaType {
AUDIO,
VIDEO;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeMediaType: FfiConverterRustBuffer<MediaType> {
override fun read(buf: ByteBuffer) = try {
MediaType.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: MediaType) = 4UL
override fun write(value: MediaType, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
/**
* Network event types for runtime lifecycle callbacks
*/
enum class NetworkAvailability {
UNKNOWN,
AVAILABLE,
UNAVAILABLE;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeNetworkAvailability: FfiConverterRustBuffer<NetworkAvailability> {
override fun read(buf: ByteBuffer) = try {
NetworkAvailability.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: NetworkAvailability) = 4UL
override fun write(value: NetworkAvailability, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
sealed class NetworkEvent {
data class NetworkPathChanged(
val `snapshot`: io.actrium.actr.NetworkSnapshot) : NetworkEvent()
{
companion object
}
data class AppLifecycleChanged(
val `state`: io.actrium.actr.AppLifecycleState) : NetworkEvent()
{
companion object
}
data class CleanupConnections(
val `reason`: io.actrium.actr.CleanupReason) : NetworkEvent()
{
companion object
}
data class ForceReconnect(
val `reason`: io.actrium.actr.ReconnectReason) : NetworkEvent()
{
companion object
}
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeNetworkEvent : FfiConverterRustBuffer<NetworkEvent>{
override fun read(buf: ByteBuffer): NetworkEvent {
return when(buf.getInt()) {
1 -> NetworkEvent.NetworkPathChanged(
FfiConverterTypeNetworkSnapshot.read(buf),
)
2 -> NetworkEvent.AppLifecycleChanged(
FfiConverterTypeAppLifecycleState.read(buf),
)
3 -> NetworkEvent.CleanupConnections(
FfiConverterTypeCleanupReason.read(buf),
)
4 -> NetworkEvent.ForceReconnect(
FfiConverterTypeReconnectReason.read(buf),
)
else -> throw RuntimeException("invalid enum value, something is very wrong!!")
}
}
override fun allocationSize(value: NetworkEvent) = when(value) {
is NetworkEvent.NetworkPathChanged -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
+ FfiConverterTypeNetworkSnapshot.allocationSize(value.`snapshot`)
)
}
is NetworkEvent.AppLifecycleChanged -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
+ FfiConverterTypeAppLifecycleState.allocationSize(value.`state`)
)
}
is NetworkEvent.CleanupConnections -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
+ FfiConverterTypeCleanupReason.allocationSize(value.`reason`)
)
}
is NetworkEvent.ForceReconnect -> {
// Add the size for the Int that specifies the variant plus the size needed for all fields
(
4UL
+ FfiConverterTypeReconnectReason.allocationSize(value.`reason`)
)
}
}
override fun write(value: NetworkEvent, buf: ByteBuffer) {
when(value) {
is NetworkEvent.NetworkPathChanged -> {
buf.putInt(1)
FfiConverterTypeNetworkSnapshot.write(value.`snapshot`, buf)
Unit
}
is NetworkEvent.AppLifecycleChanged -> {
buf.putInt(2)
FfiConverterTypeAppLifecycleState.write(value.`state`, buf)
Unit
}
is NetworkEvent.CleanupConnections -> {
buf.putInt(3)
FfiConverterTypeCleanupReason.write(value.`reason`, buf)
Unit
}
is NetworkEvent.ForceReconnect -> {
buf.putInt(4)
FfiConverterTypeReconnectReason.write(value.`reason`, buf)
Unit
}
}.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
}
}
/**
* PayloadType enum for specifying transmission type
*
* Determines which WebRTC channel/track to use for data transmission:
* - `RpcReliable`: Reliable ordered channel (default for RPC)
* - `RpcSignal`: Signaling channel for RPC
* - `StreamReliable`: Reliable stream for DataStream
* - `StreamLatencyFirst`: Low-latency stream (may drop packets)
* - `MediaRtp`: Native RTP track for media
*/
enum class PayloadType {
RPC_RELIABLE,
RPC_SIGNAL,
STREAM_RELIABLE,
STREAM_LATENCY_FIRST,
MEDIA_RTP;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypePayloadType: FfiConverterRustBuffer<PayloadType> {
override fun read(buf: ByteBuffer) = try {
PayloadType.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: PayloadType) = 4UL
override fun write(value: PayloadType, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
enum class ReconnectReason {
NETWORK_PATH_CHANGED,
LONG_BACKGROUND,
PROBE_FAILED,
MANUAL_RECONNECT,
STALE_CONNECTION_SUSPECTED;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeReconnectReason: FfiConverterRustBuffer<ReconnectReason> {
override fun read(buf: ByteBuffer) = try {
ReconnectReason.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: ReconnectReason) = 4UL
override fun write(value: ReconnectReason, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
enum class WebRtcPeerStatusBridge {
IDLE,
CONNECTING,
CONNECTED,
RECOVERING;
companion object
}
/**
* @suppress
*/
public object FfiConverterTypeWebRtcPeerStatusBridge: FfiConverterRustBuffer<WebRtcPeerStatusBridge> {
override fun read(buf: ByteBuffer) = try {
WebRtcPeerStatusBridge.values()[buf.getInt() - 1]
} catch (e: IndexOutOfBoundsException) {
throw RuntimeException("invalid enum value, something is very wrong!!", e)
}
override fun allocationSize(value: WebRtcPeerStatusBridge) = 4UL
override fun write(value: WebRtcPeerStatusBridge, buf: ByteBuffer) {
buf.putInt(value.ordinal + 1)
}
}
/**
* Optional observer for credential lifecycle events.
*/
public interface CredentialObserverBridge {
suspend fun `onRenewed`(`ctx`: ContextBridge, `event`: CredentialEventBridge)
suspend fun `onExpiring`(`ctx`: ContextBridge, `event`: CredentialEventBridge)
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceCredentialObserverBridge {
internal object `onRenewed`: UniffiCallbackInterfaceCredentialObserverBridgeMethod0 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeCredentialObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onRenewed`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypeCredentialEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object `onExpiring`: UniffiCallbackInterfaceCredentialObserverBridgeMethod1 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeCredentialObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onExpiring`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypeCredentialEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeCredentialObserverBridge.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeCredentialObserverBridge.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceCredentialObserverBridge.UniffiByValue(
uniffiFree,
uniffiClone,
`onRenewed`,
`onExpiring`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_credentialobserverbridge(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeCredentialObserverBridge: FfiConverterCallbackInterface<CredentialObserverBridge>()
/**
* Callback interface for DataStream events.
*/
public interface DataStreamCallback {
/**
* Handle an incoming DataStream chunk.
*/
suspend fun `onStream`(`chunk`: DataStream, `sender`: ActrId)
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceDataStreamCallback {
internal object `onStream`: UniffiCallbackInterfaceDataStreamCallbackMethod0 {
override fun callback(`uniffiHandle`: Long,`chunk`: RustBuffer.ByValue,`sender`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeDataStreamCallback.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onStream`(
FfiConverterTypeDataStream.lift(`chunk`),
FfiConverterTypeActrId.lift(`sender`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsyncWithError(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
{ e: ActrException -> FfiConverterTypeActrError.lower(e) },
uniffiOutDroppedCallback
)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeDataStreamCallback.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeDataStreamCallback.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceDataStreamCallback.UniffiByValue(
uniffiFree,
uniffiClone,
`onStream`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_datastreamcallback(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeDataStreamCallback: FfiConverterCallbackInterface<DataStreamCallback>()
/**
* Callback interface for forwarding tracing log events to the host.
*
* Register via `set_log_callback()` before starting the actr node.
* Once set, every tracing event emitted by the runtime will be
* forwarded through this callback.
*/
public interface LogCallback {
/**
* Called for every tracing event emitted by the actr runtime.
*
* Parameters:
* - `level`: tracing level (TRACE, DEBUG, INFO, WARN, ERROR).
* - `target`: module path of the log source.
* - `message`: field values formatted as `key=value` pairs.
* - `timestamp_ms`: wall-clock milliseconds since UNIX epoch.
*/
fun `onLog`(`level`: kotlin.String, `target`: kotlin.String, `message`: kotlin.String, `timestampMs`: kotlin.Long)
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceLogCallback {
internal object `onLog`: UniffiCallbackInterfaceLogCallbackMethod0 {
override fun callback(`uniffiHandle`: Long,`level`: RustBuffer.ByValue,`target`: RustBuffer.ByValue,`message`: RustBuffer.ByValue,`timestampMs`: Long,`uniffiOutReturn`: Pointer,uniffiCallStatus: UniffiRustCallStatus,) {
val uniffiObj = FfiConverterTypeLogCallback.handleMap.get(uniffiHandle)
val makeCall = { ->
uniffiObj.`onLog`(
FfiConverterString.lift(`level`),
FfiConverterString.lift(`target`),
FfiConverterString.lift(`message`),
FfiConverterLong.lift(`timestampMs`),
)
}
val writeReturn = { _: Unit -> Unit }
uniffiTraitInterfaceCall(uniffiCallStatus, makeCall, writeReturn)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeLogCallback.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeLogCallback.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceLogCallback.UniffiByValue(
uniffiFree,
uniffiClone,
`onLog`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_logcallback(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeLogCallback: FfiConverterCallbackInterface<LogCallback>()
/**
* Optional observer for mailbox-backpressure events.
*/
public interface MailboxObserverBridge {
suspend fun `onBackpressure`(`ctx`: ContextBridge, `event`: BackpressureEventBridge)
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceMailboxObserverBridge {
internal object `onBackpressure`: UniffiCallbackInterfaceMailboxObserverBridgeMethod0 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeMailboxObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onBackpressure`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypeBackpressureEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeMailboxObserverBridge.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeMailboxObserverBridge.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceMailboxObserverBridge.UniffiByValue(
uniffiFree,
uniffiClone,
`onBackpressure`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_mailboxobserverbridge(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeMailboxObserverBridge: FfiConverterCallbackInterface<MailboxObserverBridge>()
/**
* Callback interface for MediaTrack events.
*/
public interface MediaTrackCallback {
/**
* Handle an incoming media sample from a WebRTC native track.
*/
suspend fun `onSample`(`sample`: MediaSample, `sender`: ActrId)
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceMediaTrackCallback {
internal object `onSample`: UniffiCallbackInterfaceMediaTrackCallbackMethod0 {
override fun callback(`uniffiHandle`: Long,`sample`: RustBuffer.ByValue,`sender`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeMediaTrackCallback.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onSample`(
FfiConverterTypeMediaSample.lift(`sample`),
FfiConverterTypeActrId.lift(`sender`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsyncWithError(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
{ e: ActrException -> FfiConverterTypeActrError.lower(e) },
uniffiOutDroppedCallback
)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeMediaTrackCallback.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeMediaTrackCallback.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceMediaTrackCallback.UniffiByValue(
uniffiFree,
uniffiClone,
`onSample`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_mediatrackcallback(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeMediaTrackCallback: FfiConverterCallbackInterface<MediaTrackCallback>()
/**
* Optional observer for signaling-layer events.
*/
public interface SignalingObserverBridge {
suspend fun `onConnecting`(`ctx`: ContextBridge?)
suspend fun `onConnected`(`ctx`: ContextBridge?)
suspend fun `onDisconnected`(`ctx`: ContextBridge)
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceSignalingObserverBridge {
internal object `onConnecting`: UniffiCallbackInterfaceSignalingObserverBridgeMethod0 {
override fun callback(`uniffiHandle`: Long,`ctx`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeSignalingObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onConnecting`(
FfiConverterOptionalTypeContextBridge.lift(`ctx`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object `onConnected`: UniffiCallbackInterfaceSignalingObserverBridgeMethod1 {
override fun callback(`uniffiHandle`: Long,`ctx`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeSignalingObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onConnected`(
FfiConverterOptionalTypeContextBridge.lift(`ctx`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object `onDisconnected`: UniffiCallbackInterfaceSignalingObserverBridgeMethod2 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeSignalingObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onDisconnected`(
FfiConverterTypeContextBridge.lift(`ctx`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeSignalingObserverBridge.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeSignalingObserverBridge.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceSignalingObserverBridge.UniffiByValue(
uniffiFree,
uniffiClone,
`onConnecting`,
`onConnected`,
`onDisconnected`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_signalingobserverbridge(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeSignalingObserverBridge: FfiConverterCallbackInterface<SignalingObserverBridge>()
/**
* Optional observer for WebRTC P2P peer events.
*/
public interface WebRtcObserverBridge {
suspend fun `onConnecting`(`ctx`: ContextBridge, `event`: PeerEventBridge)
suspend fun `onConnected`(`ctx`: ContextBridge, `event`: PeerEventBridge)
suspend fun `onDisconnected`(`ctx`: ContextBridge, `event`: PeerEventBridge)
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceWebRtcObserverBridge {
internal object `onConnecting`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod0 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWebRtcObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onConnecting`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypePeerEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object `onConnected`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod1 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWebRtcObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onConnected`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypePeerEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object `onDisconnected`: UniffiCallbackInterfaceWebRtcObserverBridgeMethod2 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWebRtcObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onDisconnected`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypePeerEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeWebRtcObserverBridge.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeWebRtcObserverBridge.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceWebRtcObserverBridge.UniffiByValue(
uniffiFree,
uniffiClone,
`onConnecting`,
`onConnected`,
`onDisconnected`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_webrtcobserverbridge(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeWebRtcObserverBridge: FfiConverterCallbackInterface<WebRtcObserverBridge>()
/**
* Optional observer for WebSocket peer events.
*/
public interface WebSocketObserverBridge {
suspend fun `onConnecting`(`ctx`: ContextBridge, `event`: PeerEventBridge)
suspend fun `onConnected`(`ctx`: ContextBridge, `event`: PeerEventBridge)
suspend fun `onDisconnected`(`ctx`: ContextBridge, `event`: PeerEventBridge)
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceWebSocketObserverBridge {
internal object `onConnecting`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod0 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWebSocketObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onConnecting`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypePeerEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object `onConnected`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod1 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWebSocketObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onConnected`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypePeerEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object `onDisconnected`: UniffiCallbackInterfaceWebSocketObserverBridgeMethod2 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWebSocketObserverBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onDisconnected`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypePeerEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsync(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
uniffiOutDroppedCallback
)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeWebSocketObserverBridge.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeWebSocketObserverBridge.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceWebSocketObserverBridge.UniffiByValue(
uniffiFree,
uniffiClone,
`onConnecting`,
`onConnected`,
`onDisconnected`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_websocketobserverbridge(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeWebSocketObserverBridge: FfiConverterCallbackInterface<WebSocketObserverBridge>()
/**
* Required lifecycle + dispatch bridge.
*
* The foreign-language code supplies exactly one implementation of this
* interface. It handles the four fallible lifecycle hooks and the core
* `dispatch` entry point.
*/
public interface WorkloadLifecycleBridge {
/**
* Called when the node has started.
*/
suspend fun `onStart`(`ctx`: ContextBridge)
/**
* Called when the node is ready to accept requests.
*/
suspend fun `onReady`(`ctx`: ContextBridge)
/**
* Called when the node receives a shutdown signal.
*/
suspend fun `onStop`(`ctx`: ContextBridge)
/**
* Called when the framework catches a runtime error.
*/
suspend fun `onError`(`ctx`: ContextBridge, `event`: ErrorEventBridge)
/**
* Dispatch an incoming RPC message and return the response bytes.
*/
suspend fun `dispatch`(`ctx`: ContextBridge, `envelope`: RpcEnvelopeBridge): kotlin.ByteArray
companion object
}
// Put the implementation in an object so we don't pollute the top-level namespace
internal object uniffiCallbackInterfaceWorkloadLifecycleBridge {
internal object `onStart`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod0 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWorkloadLifecycleBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onStart`(
FfiConverterTypeContextBridge.lift(`ctx`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsyncWithError(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
{ e: ActrException -> FfiConverterTypeActrError.lower(e) },
uniffiOutDroppedCallback
)
}
}
internal object `onReady`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod1 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWorkloadLifecycleBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onReady`(
FfiConverterTypeContextBridge.lift(`ctx`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsyncWithError(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
{ e: ActrException -> FfiConverterTypeActrError.lower(e) },
uniffiOutDroppedCallback
)
}
}
internal object `onStop`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod2 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWorkloadLifecycleBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onStop`(
FfiConverterTypeContextBridge.lift(`ctx`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsyncWithError(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
{ e: ActrException -> FfiConverterTypeActrError.lower(e) },
uniffiOutDroppedCallback
)
}
}
internal object `onError`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod3 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`event`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteVoid,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWorkloadLifecycleBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`onError`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypeErrorEventBridge.lift(`event`),
)
}
val uniffiHandleSuccess = { _: Unit ->
val uniffiResult = UniffiForeignFutureResultVoid.UniffiByValue(
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultVoid.UniffiByValue(
callStatus,
),
)
}
uniffiTraitInterfaceCallAsyncWithError(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
{ e: ActrException -> FfiConverterTypeActrError.lower(e) },
uniffiOutDroppedCallback
)
}
}
internal object `dispatch`: UniffiCallbackInterfaceWorkloadLifecycleBridgeMethod4 {
override fun callback(`uniffiHandle`: Long,`ctx`: Long,`envelope`: RustBuffer.ByValue,`uniffiFutureCallback`: UniffiForeignFutureCompleteRustBuffer,`uniffiCallbackData`: Long,`uniffiOutDroppedCallback`: UniffiForeignFutureDroppedCallbackStruct,) {
val uniffiObj = FfiConverterTypeWorkloadLifecycleBridge.handleMap.get(uniffiHandle)
val makeCall = suspend { ->
uniffiObj.`dispatch`(
FfiConverterTypeContextBridge.lift(`ctx`),
FfiConverterTypeRpcEnvelopeBridge.lift(`envelope`),
)
}
val uniffiHandleSuccess = { returnValue: kotlin.ByteArray ->
val uniffiResult = UniffiForeignFutureResultRustBuffer.UniffiByValue(
FfiConverterByteArray.lower(returnValue),
UniffiRustCallStatus.ByValue()
)
uniffiResult.write()
uniffiFutureCallback.callback(uniffiCallbackData, uniffiResult)
}
val uniffiHandleError = { callStatus: UniffiRustCallStatus.ByValue ->
uniffiFutureCallback.callback(
uniffiCallbackData,
UniffiForeignFutureResultRustBuffer.UniffiByValue(
RustBuffer.ByValue(),
callStatus,
),
)
}
uniffiTraitInterfaceCallAsyncWithError(
makeCall,
uniffiHandleSuccess,
uniffiHandleError,
{ e: ActrException -> FfiConverterTypeActrError.lower(e) },
uniffiOutDroppedCallback
)
}
}
internal object uniffiFree: UniffiCallbackInterfaceFree {
override fun callback(handle: Long) {
FfiConverterTypeWorkloadLifecycleBridge.handleMap.remove(handle)
}
}
internal object uniffiClone: UniffiCallbackInterfaceClone {
override fun callback(handle: Long): Long {
return FfiConverterTypeWorkloadLifecycleBridge.handleMap.clone(handle)
}
}
internal var vtable = UniffiVTableCallbackInterfaceWorkloadLifecycleBridge.UniffiByValue(
uniffiFree,
uniffiClone,
`onStart`,
`onReady`,
`onStop`,
`onError`,
`dispatch`,
)
// Registers the foreign callback with the Rust side.
// This method is generated for each callback interface.
internal fun register(lib: UniffiLib) {
lib.uniffi_actr_fn_init_callback_vtable_workloadlifecyclebridge(vtable)
}
}
/**
* The ffiConverter which transforms the Callbacks in to handles to pass to Rust.
*
* @suppress
*/
public object FfiConverterTypeWorkloadLifecycleBridge: FfiConverterCallbackInterface<WorkloadLifecycleBridge>()
/**
* @suppress
*/
public object FfiConverterOptionalULong: FfiConverterRustBuffer<kotlin.ULong?> {
override fun read(buf: ByteBuffer): kotlin.ULong? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterULong.read(buf)
}
override fun allocationSize(value: kotlin.ULong?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterULong.allocationSize(value)
}
}
override fun write(value: kotlin.ULong?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterULong.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalLong: FfiConverterRustBuffer<kotlin.Long?> {
override fun read(buf: ByteBuffer): kotlin.Long? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterLong.read(buf)
}
override fun allocationSize(value: kotlin.Long?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterLong.allocationSize(value)
}
}
override fun write(value: kotlin.Long?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterLong.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalBoolean: FfiConverterRustBuffer<kotlin.Boolean?> {
override fun read(buf: ByteBuffer): kotlin.Boolean? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterBoolean.read(buf)
}
override fun allocationSize(value: kotlin.Boolean?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterBoolean.allocationSize(value)
}
}
override fun write(value: kotlin.Boolean?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterBoolean.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalString: FfiConverterRustBuffer<kotlin.String?> {
override fun read(buf: ByteBuffer): kotlin.String? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterString.read(buf)
}
override fun allocationSize(value: kotlin.String?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterString.allocationSize(value)
}
}
override fun write(value: kotlin.String?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterString.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeContextBridge: FfiConverterRustBuffer<ContextBridge?> {
override fun read(buf: ByteBuffer): ContextBridge? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeContextBridge.read(buf)
}
override fun allocationSize(value: ContextBridge?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeContextBridge.allocationSize(value)
}
}
override fun write(value: ContextBridge?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeContextBridge.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeWebRtcPeerStatusBridge: FfiConverterRustBuffer<WebRtcPeerStatusBridge?> {
override fun read(buf: ByteBuffer): WebRtcPeerStatusBridge? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeWebRtcPeerStatusBridge.read(buf)
}
override fun allocationSize(value: WebRtcPeerStatusBridge?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeWebRtcPeerStatusBridge.allocationSize(value)
}
}
override fun write(value: WebRtcPeerStatusBridge?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeWebRtcPeerStatusBridge.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeCredentialObserverBridge: FfiConverterRustBuffer<CredentialObserverBridge?> {
override fun read(buf: ByteBuffer): CredentialObserverBridge? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeCredentialObserverBridge.read(buf)
}
override fun allocationSize(value: CredentialObserverBridge?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeCredentialObserverBridge.allocationSize(value)
}
}
override fun write(value: CredentialObserverBridge?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeCredentialObserverBridge.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeLogCallback: FfiConverterRustBuffer<LogCallback?> {
override fun read(buf: ByteBuffer): LogCallback? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeLogCallback.read(buf)
}
override fun allocationSize(value: LogCallback?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeLogCallback.allocationSize(value)
}
}
override fun write(value: LogCallback?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeLogCallback.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeMailboxObserverBridge: FfiConverterRustBuffer<MailboxObserverBridge?> {
override fun read(buf: ByteBuffer): MailboxObserverBridge? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeMailboxObserverBridge.read(buf)
}
override fun allocationSize(value: MailboxObserverBridge?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeMailboxObserverBridge.allocationSize(value)
}
}
override fun write(value: MailboxObserverBridge?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeMailboxObserverBridge.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeSignalingObserverBridge: FfiConverterRustBuffer<SignalingObserverBridge?> {
override fun read(buf: ByteBuffer): SignalingObserverBridge? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeSignalingObserverBridge.read(buf)
}
override fun allocationSize(value: SignalingObserverBridge?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeSignalingObserverBridge.allocationSize(value)
}
}
override fun write(value: SignalingObserverBridge?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeSignalingObserverBridge.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeWebRtcObserverBridge: FfiConverterRustBuffer<WebRtcObserverBridge?> {
override fun read(buf: ByteBuffer): WebRtcObserverBridge? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeWebRtcObserverBridge.read(buf)
}
override fun allocationSize(value: WebRtcObserverBridge?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeWebRtcObserverBridge.allocationSize(value)
}
}
override fun write(value: WebRtcObserverBridge?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeWebRtcObserverBridge.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterOptionalTypeWebSocketObserverBridge: FfiConverterRustBuffer<WebSocketObserverBridge?> {
override fun read(buf: ByteBuffer): WebSocketObserverBridge? {
if (buf.get().toInt() == 0) {
return null
}
return FfiConverterTypeWebSocketObserverBridge.read(buf)
}
override fun allocationSize(value: WebSocketObserverBridge?): ULong {
if (value == null) {
return 1UL
} else {
return 1UL + FfiConverterTypeWebSocketObserverBridge.allocationSize(value)
}
}
override fun write(value: WebSocketObserverBridge?, buf: ByteBuffer) {
if (value == null) {
buf.put(0)
} else {
buf.put(1)
FfiConverterTypeWebSocketObserverBridge.write(value, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceFloat: FfiConverterRustBuffer<List<kotlin.Float>> {
override fun read(buf: ByteBuffer): List<kotlin.Float> {
val len = buf.getInt()
return List<kotlin.Float>(len) {
FfiConverterFloat.read(buf)
}
}
override fun allocationSize(value: List<kotlin.Float>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterFloat.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<kotlin.Float>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterFloat.write(it, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceString: FfiConverterRustBuffer<List<kotlin.String>> {
override fun read(buf: ByteBuffer): List<kotlin.String> {
val len = buf.getInt()
return List<kotlin.String>(len) {
FfiConverterString.read(buf)
}
}
override fun allocationSize(value: List<kotlin.String>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<kotlin.String>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterString.write(it, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceTypeActrId: FfiConverterRustBuffer<List<ActrId>> {
override fun read(buf: ByteBuffer): List<ActrId> {
val len = buf.getInt()
return List<ActrId>(len) {
FfiConverterTypeActrId.read(buf)
}
}
override fun allocationSize(value: List<ActrId>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypeActrId.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<ActrId>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypeActrId.write(it, buf)
}
}
}
/**
* @suppress
*/
public object FfiConverterSequenceTypeMetadataEntry: FfiConverterRustBuffer<List<MetadataEntry>> {
override fun read(buf: ByteBuffer): List<MetadataEntry> {
val len = buf.getInt()
return List<MetadataEntry>(len) {
FfiConverterTypeMetadataEntry.read(buf)
}
}
override fun allocationSize(value: List<MetadataEntry>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypeMetadataEntry.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}
override fun write(value: List<MetadataEntry>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypeMetadataEntry.write(it, buf)
}
}
}
/**
* `true` iff the error is in the Transient fault domain — safe to retry.
*/ fun `actrErrorIsRetryable`(`err`: ActrException): kotlin.Boolean {
return FfiConverterBoolean.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_func_actr_error_is_retryable(
FfiConverterTypeActrError.lower(`err`),_status)
}
)
}
/**
* Fault-domain classification of `err` (see [`ErrorKind`]).
*/ fun `actrErrorKind`(`err`: ActrException): ErrorKind {
return FfiConverterTypeErrorKind.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_func_actr_error_kind(
FfiConverterTypeActrError.lower(`err`),_status)
}
)
}
/**
* `true` iff the error is in the Corrupt fault domain — route to DLQ.
*/ fun `actrErrorRequiresDlq`(`err`: ActrException): kotlin.Boolean {
return FfiConverterBoolean.lift(
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_func_actr_error_requires_dlq(
FfiConverterTypeActrError.lower(`err`),_status)
}
)
}
/**
* Set or clear the global log callback.
*
* Must be called **before** the actr node is created. The tracing subscriber
* is locked during node initialization; calls after that point are ignored.
* Pass `None` to disable forwarding.
*/ fun `setLogCallback`(`callback`: LogCallback?)
=
uniffiRustCall() { _status ->
UniffiLib.uniffi_actr_fn_func_set_log_callback(
FfiConverterOptionalTypeLogCallback.lower(`callback`),_status)
}
/**
* Resolve a dependency's ActrType from a manifest.toml file.
*
* Parses the manifest, looks up the dependency by alias, and returns its
* `actr_type` field as a structured `ActrType` record. This is the canonical
* way for linked-runtime hosts (iOS, Android) to discover which remote actor
* type a dependency resolves to, without hardcoding `"manufacturer:name:version"`
* strings in application code.
*/
@Throws(ActrException::class) fun `resolveManifestDependency`(`manifestPath`: kotlin.String, `dependencyAlias`: kotlin.String): ActrType {
return FfiConverterTypeActrType.lift(
uniffiRustCallWithError(ActrException) { _status ->
UniffiLib.uniffi_actr_fn_func_resolve_manifest_dependency(
FfiConverterString.lower(`manifestPath`),FfiConverterString.lower(`dependencyAlias`),_status)
}
)
}
/**
* List all dependency aliases from a manifest.toml file.
*
* Parses the manifest and returns the alias of every `[[dependency]]` entry.
* Linked-runtime hosts (iOS, Android) use this to discover which dependencies
* are declared in the manifest without hardcoding alias strings.
*/
@Throws(ActrException::class) fun `resolveManifestDependencyAliasList`(`manifestPath`: kotlin.String): List<kotlin.String> {
return FfiConverterSequenceString.lift(
uniffiRustCallWithError(ActrException) { _status ->
UniffiLib.uniffi_actr_fn_func_resolve_manifest_dependency_alias_list(
FfiConverterString.lower(`manifestPath`),_status)
}
)
}
/**
* Resolve the package's own ActrType from a manifest.toml file.
*
* Parses the manifest and returns the `[package]` block's actr_type fields
* as a structured `ActrType` record. Linked-runtime hosts (iOS, Android) use
* this to determine their own actor type without hardcoding
* `"manufacturer:name:version"` strings.
*/
@Throws(ActrException::class) fun `resolveManifestPackageActrType`(`manifestPath`: kotlin.String): ActrType {
return FfiConverterTypeActrType.lift(
uniffiRustCallWithError(ActrException) { _status ->
UniffiLib.uniffi_actr_fn_func_resolve_manifest_package_actr_type(
FfiConverterString.lower(`manifestPath`),_status)
}
)
}