diff --git a/README.md b/README.md index 1819a41b7..27a8b940a 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,13 @@ Some internal libraries are distributed via GitHub Packages. Configure credentia - `GITHUB_ACTOR` (your username) - `GITHUB_TOKEN` (token with `read:packages`) - - Or `~/.gradle/local.properties` + - `PROJECT_ROOT/local.properties` or `~/.gradle/gradle.properties` - `gpr.user=YOUR_GITHUB_USERNAME` - `gpr.key=YOUR_GITHUB_TOKEN` See also: - [bitkit-core android bindings](https://github.com/synonymdev/bitkit-core/tree/master/bindings/android#installation) +- [vss-rust-client-ffi android bindings](https://github.com/synonymdev/vss-rust-client-ffi/tree/master/bindings/android#installation) ### References diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7bbe251c2..eb6ea5f5f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -176,7 +176,6 @@ tasks.withType().configureEach { } dependencies { - implementation(project(":libs:vss-client")) implementation(fileTree("libs") { include("*.aar") }) implementation(libs.jna) { artifact { type = "aar" } } implementation(platform(libs.kotlin.bom)) @@ -198,6 +197,7 @@ dependencies { implementation(libs.bouncycastle.provider.jdk) implementation(libs.ldk.node.android) { exclude(group = "net.java.dev.jna", module = "jna") } implementation(libs.bitkitcore) + implementation(libs.vss) // Firebase implementation(platform(libs.firebase.bom)) implementation(libs.firebase.messaging) @@ -227,7 +227,6 @@ dependencies { implementation(libs.charts) implementation(libs.haze) implementation(libs.haze.materials) - // Compose Navigation implementation(libs.navigation.compose) androidTestImplementation(libs.navigation.testing) diff --git a/app/src/main/java/to/bitkit/data/backup/VssBackupClient.kt b/app/src/main/java/to/bitkit/data/backup/VssBackupClient.kt index b03f3326d..7352d82cb 100644 --- a/app/src/main/java/to/bitkit/data/backup/VssBackupClient.kt +++ b/app/src/main/java/to/bitkit/data/backup/VssBackupClient.kt @@ -1,5 +1,9 @@ package to.bitkit.data.backup +import com.synonym.vssclient.VssItem +import com.synonym.vssclient.vssGet +import com.synonym.vssclient.vssNewClient +import com.synonym.vssclient.vssStore import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext @@ -7,10 +11,6 @@ import kotlinx.coroutines.withTimeout import to.bitkit.di.BgDispatcher import to.bitkit.env.Env import to.bitkit.utils.Logger -import uniffi.vss_rust_client_ffi.VssItem -import uniffi.vss_rust_client_ffi.vssGet -import uniffi.vss_rust_client_ffi.vssNewClient -import uniffi.vss_rust_client_ffi.vssStore import javax.inject.Inject import javax.inject.Singleton import kotlin.time.Duration.Companion.seconds diff --git a/app/src/main/java/to/bitkit/repositories/BackupRepo.kt b/app/src/main/java/to/bitkit/repositories/BackupRepo.kt index effd408e8..cd79b34b0 100644 --- a/app/src/main/java/to/bitkit/repositories/BackupRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/BackupRepo.kt @@ -1,6 +1,7 @@ package to.bitkit.repositories import android.content.Context +import com.synonym.vssclient.VssItem import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope @@ -29,7 +30,6 @@ import to.bitkit.models.BackupItemStatus import to.bitkit.models.Toast import to.bitkit.ui.shared.toast.ToastEventBus import to.bitkit.utils.Logger -import uniffi.vss_rust_client_ffi.VssItem import javax.inject.Inject import javax.inject.Singleton diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 019f426b8..63f655c54 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -109,6 +109,7 @@ test-junit-ext = { module = "androidx.test.ext:junit", version.ref = "junitExt" test-mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "mockitoKotlin" } test-robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" } test-turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" } +vss = { module = "com.synonym:vss-client-android", version = "0.1.0" } work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "workRuntimeKtx" } zxing = { module = "com.google.zxing:core", version.ref = "zxing" } lottie = { module = "com.airbnb.android:lottie-compose", version.ref = "lottieVersion" } diff --git a/libs/vss-client/.gitignore b/libs/vss-client/.gitignore deleted file mode 100644 index 4c28e408d..000000000 --- a/libs/vss-client/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/build -*.iml -.gradle -/local.properties -.DS_Store \ No newline at end of file diff --git a/libs/vss-client/README.md b/libs/vss-client/README.md deleted file mode 100644 index 7e68a5df0..000000000 --- a/libs/vss-client/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# VSS Rust Client FFI Module - -This module contains the uniffi bindings from [vss-rust-client-ffi](https://github.com/synonymdev/vss-rust-client-ffi). - -## Notes - -- **DO NOT** manually edit the content of the files in this module - they are auto-generated -- Detekt is disabled for this module in `build.gradle.kts` - -## Updating - -When updating the with new binding: -1. Replace the `vss_rust_client_ffi.kt` with the one from `bidnings/android` -2. Overwrite the entire `jniLibs` directory and its contents with the one from `bidnings/android`. -3. Ensure the module builds successfully by rebuilding & running the app. diff --git a/libs/vss-client/build.gradle.kts b/libs/vss-client/build.gradle.kts deleted file mode 100644 index 5023bcb55..000000000 --- a/libs/vss-client/build.gradle.kts +++ /dev/null @@ -1,45 +0,0 @@ -plugins { - id("com.android.library") - id("org.jetbrains.kotlin.android") -} - -// Disable detekt for this module to avoid formatting auto-generated code -tasks.matching { it.name.contains("detekt", ignoreCase = true) }.configureEach { - enabled = false -} - -android { - namespace = "uniffi.vss_rust_client_ffi" - compileSdk = 36 - - defaultConfig { - minSdk = 26 - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - isMinifyEnabled = false - } - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - - kotlinOptions { - jvmTarget = "11" - } - - sourceSets { - getByName("main") { - jniLibs.srcDirs("src/main/jniLibs") - } - } -} - -dependencies { - compileOnly(libs.jna) - compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2") -} diff --git a/libs/vss-client/src/main/java/uniffi/vss_rust_client_ffi/vss_rust_client_ffi.kt b/libs/vss-client/src/main/java/uniffi/vss_rust_client_ffi/vss_rust_client_ffi.kt deleted file mode 100644 index 896768c70..000000000 --- a/libs/vss-client/src/main/java/uniffi/vss_rust_client_ffi/vss_rust_client_ffi.kt +++ /dev/null @@ -1,1366 +0,0 @@ -// This file was autogenerated by some hot garbage in the `uniffi` crate. -// Trust me, you don't want to mess with it! - -@file:Suppress("NAME_SHADOWING") - -package uniffi.vss_rust_client_ffi; - -// 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.ConcurrentHashMap -import kotlin.coroutines.resume -import kotlinx.coroutines.CancellableContinuation -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. - -@Structure.FieldOrder("capacity", "len", "data") -open class RustBuffer : Structure() { - @JvmField var capacity: Int = 0 - @JvmField var len: Int = 0 - @JvmField var data: Pointer? = null - - class ByValue: RustBuffer(), Structure.ByValue - class ByReference: RustBuffer(), Structure.ByReference - - companion object { - internal fun alloc(size: Int = 0) = rustCall() { status -> - _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rustbuffer_alloc(size, status) - }.also { - if(it.data == null) { - throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})") - } - } - - internal fun create(capacity: Int, len: Int, data: Pointer?): RustBuffer.ByValue { - var buf = RustBuffer.ByValue() - buf.capacity = capacity - buf.len = len - buf.data = data - return buf - } - - internal fun free(buf: RustBuffer.ByValue) = rustCall() { status -> - _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rustbuffer_free(buf, status) - } - } - - @Suppress("TooGenericExceptionThrown") - fun asByteBuffer() = - this.data?.getByteBuffer(0, this.len.toLong())?.also { - it.order(ByteOrder.BIG_ENDIAN) - } -} - -/** - * The equivalent of the `*mut RustBuffer` type. - * Required for callbacks taking in an out pointer. - * - * Size is the sum of all values in the struct. - */ -class RustBufferByReference : ByReference(16) { - /** - * Set the pointed-to `RustBuffer` to the given value. - */ - fun setValue(value: RustBuffer.ByValue) { - // NOTE: The offsets are as they are in the C-like struct. - val pointer = getPointer() - pointer.setInt(0, value.capacity) - pointer.setInt(4, value.len) - pointer.setPointer(8, value.data) - } - - /** - * Get a `RustBuffer.ByValue` from this reference. - */ - fun getValue(): RustBuffer.ByValue { - val pointer = getPointer() - val value = RustBuffer.ByValue() - value.writeField("capacity", pointer.getInt(0)) - value.writeField("len", pointer.getInt(4)) - value.writeField("data", pointer.getPointer(8)) - - return value - } -} - -// 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") -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. -public interface FfiConverter { - // 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): Int - - // 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.toLong()).also { - it.order(ByteOrder.BIG_ENDIAN) - } - write(value, bbuf) - rbuf.writeField("len", bbuf.position()) - 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 -public interface FfiConverterRustBuffer: FfiConverter { - 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. -// Error runtime. -@Structure.FieldOrder("code", "error_buf") -internal open class RustCallStatus : Structure() { - @JvmField var code: Byte = 0 - @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue() - - class ByValue: RustCallStatus(), Structure.ByValue - - fun isSuccess(): Boolean { - return code == 0.toByte() - } - - fun isError(): Boolean { - return code == 1.toByte() - } - - fun isPanic(): Boolean { - return code == 2.toByte() - } -} - -class InternalException(message: String) : Exception(message) - -// Each top-level error class has a companion object that can lift the error from the call status's rust buffer -interface CallStatusErrorHandler { - 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 rustCallWithError(errorHandler: CallStatusErrorHandler, callback: (RustCallStatus) -> U): U { - var status = RustCallStatus(); - val return_value = callback(status) - checkCallStatus(errorHandler, status) - return return_value -} - -// Check RustCallStatus and throw an error if the call wasn't successful -private fun checkCallStatus(errorHandler: CallStatusErrorHandler, status: RustCallStatus) { - 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") - } -} - -// CallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR -object NullCallStatusErrorHandler: CallStatusErrorHandler { - 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 rustCall(callback: (RustCallStatus) -> U): U { - return rustCallWithError(NullCallStatusErrorHandler, callback); -} - -// IntegerType that matches Rust's `usize` / C's `size_t` -public class USize(value: Long = 0) : IntegerType(Native.SIZE_T_SIZE, value, true) { - // This is needed to fill in the gaps of IntegerType's implementation of Number for Kotlin. - override fun toByte() = toInt().toByte() - // Needed until https://youtrack.jetbrains.com/issue/KT-47902 is fixed. - @Deprecated("`toInt().toChar()` is deprecated") - override fun toChar() = toInt().toChar() - override fun toShort() = toInt().toShort() - - fun writeToBuffer(buf: ByteBuffer) { - // Make sure we always write usize integers using native byte-order, since they may be - // casted to pointer values - buf.order(ByteOrder.nativeOrder()) - try { - when (Native.SIZE_T_SIZE) { - 4 -> buf.putInt(toInt()) - 8 -> buf.putLong(toLong()) - else -> throw RuntimeException("Invalid SIZE_T_SIZE: ${Native.SIZE_T_SIZE}") - } - } finally { - buf.order(ByteOrder.BIG_ENDIAN) - } - } - - companion object { - val size: Int - get() = Native.SIZE_T_SIZE - - fun readFromBuffer(buf: ByteBuffer) : USize { - // Make sure we always read usize integers using native byte-order, since they may be - // casted from pointer values - buf.order(ByteOrder.nativeOrder()) - try { - return when (Native.SIZE_T_SIZE) { - 4 -> USize(buf.getInt().toLong()) - 8 -> USize(buf.getLong()) - else -> throw RuntimeException("Invalid SIZE_T_SIZE: ${Native.SIZE_T_SIZE}") - } - } finally { - buf.order(ByteOrder.BIG_ENDIAN) - } - } - } -} - - -// Map handles to objects -// -// This is used when the Rust code expects an opaque pointer to represent some foreign object. -// Normally we would pass a pointer to the object, but JNA doesn't support getting a pointer from an -// object reference , nor does it support leaking a reference to Rust. -// -// Instead, this class maps USize values to objects so that we can pass a pointer-sized type to -// Rust when it needs an opaque pointer. -// -// TODO: refactor callbacks to use this class -internal class UniFfiHandleMap { - private val map = ConcurrentHashMap() - // Use AtomicInteger for our counter, since we may be on a 32-bit system. 4 billion possible - // values seems like enough. If somehow we generate 4 billion handles, then this will wrap - // around back to zero and we can assume the first handle generated will have been dropped by - // then. - private val counter = java.util.concurrent.atomic.AtomicInteger(0) - - val size: Int - get() = map.size - - fun insert(obj: T): USize { - val handle = USize(counter.getAndAdd(1).toLong()) - map.put(handle, obj) - return handle - } - - fun get(handle: USize): T? { - return map.get(handle) - } - - fun remove(handle: USize): T? { - return map.remove(handle) - } -} - -// FFI type for Rust future continuations -internal interface UniFffiRustFutureContinuationCallbackType : com.sun.jna.Callback { - fun callback(continuationHandle: USize, pollResult: Short); -} - -// 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 "vss_rust_client_ffi" -} - -private inline fun loadIndirect( - componentName: String -): Lib { - return Native.load(findLibraryName(componentName), Lib::class.java) -} - -// A JNA Library to expose the extern-C FFI definitions. -// This is an implementation detail which will be called internally by the public API. - -internal interface _UniFFILib : Library { - companion object { - internal val INSTANCE: _UniFFILib by lazy { - loadIndirect<_UniFFILib>(componentName = "vss_rust_client_ffi") - .also { lib: _UniFFILib -> - uniffiCheckContractApiVersion(lib) - uniffiCheckApiChecksums(lib) - uniffiRustFutureContinuationCallback.register(lib) - } - } - } - - fun uniffi_vss_rust_client_ffi_fn_func_vss_delete(`key`: RustBuffer.ByValue, - ): Pointer - fun uniffi_vss_rust_client_ffi_fn_func_vss_get(`key`: RustBuffer.ByValue, - ): Pointer - fun uniffi_vss_rust_client_ffi_fn_func_vss_list(`prefix`: RustBuffer.ByValue, - ): Pointer - fun uniffi_vss_rust_client_ffi_fn_func_vss_list_keys(`prefix`: RustBuffer.ByValue, - ): Pointer - fun uniffi_vss_rust_client_ffi_fn_func_vss_new_client(`baseUrl`: RustBuffer.ByValue,`storeId`: RustBuffer.ByValue, - ): Pointer - fun uniffi_vss_rust_client_ffi_fn_func_vss_put_with_key_prefix(`items`: RustBuffer.ByValue, - ): Pointer - fun uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_client(_uniffi_out_err: RustCallStatus, - ): Unit - fun uniffi_vss_rust_client_ffi_fn_func_vss_store(`key`: RustBuffer.ByValue,`value`: RustBuffer.ByValue, - ): Pointer - fun ffi_vss_rust_client_ffi_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus, - ): RustBuffer.ByValue - fun ffi_vss_rust_client_ffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus, - ): RustBuffer.ByValue - fun ffi_vss_rust_client_ffi_rustbuffer_free(`buf`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, - ): Unit - fun ffi_vss_rust_client_ffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Int,_uniffi_out_err: RustCallStatus, - ): RustBuffer.ByValue - fun ffi_vss_rust_client_ffi_rust_future_continuation_callback_set(`callback`: UniFffiRustFutureContinuationCallbackType, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_poll_u8(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_u8(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_u8(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_u8(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Byte - fun ffi_vss_rust_client_ffi_rust_future_poll_i8(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_i8(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_i8(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_i8(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Byte - fun ffi_vss_rust_client_ffi_rust_future_poll_u16(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_u16(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_u16(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_u16(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Short - fun ffi_vss_rust_client_ffi_rust_future_poll_i16(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_i16(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_i16(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_i16(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Short - fun ffi_vss_rust_client_ffi_rust_future_poll_u32(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_u32(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_u32(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_u32(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Int - fun ffi_vss_rust_client_ffi_rust_future_poll_i32(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_i32(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_i32(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_i32(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Int - fun ffi_vss_rust_client_ffi_rust_future_poll_u64(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_u64(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_u64(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_u64(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Long - fun ffi_vss_rust_client_ffi_rust_future_poll_i64(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_i64(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_i64(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_i64(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Long - fun ffi_vss_rust_client_ffi_rust_future_poll_f32(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_f32(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_f32(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_f32(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Float - fun ffi_vss_rust_client_ffi_rust_future_poll_f64(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_f64(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_f64(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_f64(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Double - fun ffi_vss_rust_client_ffi_rust_future_poll_pointer(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_pointer(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_pointer(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_pointer(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Pointer - fun ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_rust_buffer(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): RustBuffer.ByValue - fun ffi_vss_rust_client_ffi_rust_future_poll_void(`handle`: Pointer,`uniffiCallback`: USize, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_cancel_void(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_free_void(`handle`: Pointer, - ): Unit - fun ffi_vss_rust_client_ffi_rust_future_complete_void(`handle`: Pointer,_uniffi_out_err: RustCallStatus, - ): Unit - fun uniffi_vss_rust_client_ffi_checksum_func_vss_delete( - ): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_get( - ): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_list( - ): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_list_keys( - ): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_new_client( - ): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_put_with_key_prefix( - ): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_shutdown_client( - ): Short - fun uniffi_vss_rust_client_ffi_checksum_func_vss_store( - ): Short - fun ffi_vss_rust_client_ffi_uniffi_contract_version( - ): Int - -} - -private fun uniffiCheckContractApiVersion(lib: _UniFFILib) { - // Get the bindings contract version from our ComponentInterface - val bindings_contract_version = 24 - // Get the scaffolding contract version by calling the into the dylib - val scaffolding_contract_version = lib.ffi_vss_rust_client_ffi_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: _UniFFILib) { - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_delete() != 46571.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_get() != 59657.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_list() != 16435.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_list_keys() != 31884.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_new_client() != 949.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_put_with_key_prefix() != 15750.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_shutdown_client() != 27474.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_vss_rust_client_ffi_checksum_func_vss_store() != 42761.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } -} - -// Async support -// Async return type handlers - -internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toShort() -internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toShort() - -internal val uniffiContinuationHandleMap = UniFfiHandleMap>() - -// FFI type for Rust future continuations -internal object uniffiRustFutureContinuationCallback: UniFffiRustFutureContinuationCallbackType { - override fun callback(continuationHandle: USize, pollResult: Short) { - uniffiContinuationHandleMap.remove(continuationHandle)?.resume(pollResult) - } - - internal fun register(lib: _UniFFILib) { - lib.ffi_vss_rust_client_ffi_rust_future_continuation_callback_set(this) - } -} - -internal suspend fun uniffiRustCallAsync( - rustFuture: Pointer, - pollFunc: (Pointer, USize) -> Unit, - completeFunc: (Pointer, RustCallStatus) -> F, - freeFunc: (Pointer) -> Unit, - liftFunc: (F) -> T, - errorHandler: CallStatusErrorHandler -): T { - try { - do { - val pollResult = suspendCancellableCoroutine { continuation -> - pollFunc( - rustFuture, - uniffiContinuationHandleMap.insert(continuation) - ) - } - } while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY); - - return liftFunc( - rustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) }) - ) - } finally { - freeFunc(rustFuture) - } -} - - -// Public interface members begin here. - - -public object FfiConverterLong: FfiConverter { - 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) = 8 - - override fun write(value: Long, buf: ByteBuffer) { - buf.putLong(value) - } -} - -public object FfiConverterBoolean: FfiConverter { - 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) = 1 - - override fun write(value: Boolean, buf: ByteBuffer) { - buf.put(lower(value)) - } -} - -public object FfiConverterString: FfiConverter { - // 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) - 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()) - 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): Int { - val sizeForLength = 4 - val sizeForString = value.length * 3 - return sizeForLength + sizeForString - } - - override fun write(value: String, buf: ByteBuffer) { - val byteBuf = toUtf8(value) - buf.putInt(byteBuf.limit()) - buf.put(byteBuf) - } -} - -public object FfiConverterByteArray: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): ByteArray { - val len = buf.getInt() - val byteArr = ByteArray(len) - buf.get(byteArr) - return byteArr - } - override fun allocationSize(value: ByteArray): Int { - return 4 + value.size - } - override fun write(value: ByteArray, buf: ByteBuffer) { - buf.putInt(value.size) - buf.put(value) - } -} - - - - -data class KeyValue ( - var `key`: String, - var `value`: ByteArray -) { - - companion object -} - -public object FfiConverterTypeKeyValue: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): KeyValue { - return KeyValue( - FfiConverterString.read(buf), - FfiConverterByteArray.read(buf), - ) - } - - override fun allocationSize(value: KeyValue) = ( - FfiConverterString.allocationSize(value.`key`) + - FfiConverterByteArray.allocationSize(value.`value`) - ) - - override fun write(value: KeyValue, buf: ByteBuffer) { - FfiConverterString.write(value.`key`, buf) - FfiConverterByteArray.write(value.`value`, buf) - } -} - - - - -data class KeyVersion ( - var `key`: String, - var `version`: Long -) { - - companion object -} - -public object FfiConverterTypeKeyVersion: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): KeyVersion { - return KeyVersion( - FfiConverterString.read(buf), - FfiConverterLong.read(buf), - ) - } - - override fun allocationSize(value: KeyVersion) = ( - FfiConverterString.allocationSize(value.`key`) + - FfiConverterLong.allocationSize(value.`version`) - ) - - override fun write(value: KeyVersion, buf: ByteBuffer) { - FfiConverterString.write(value.`key`, buf) - FfiConverterLong.write(value.`version`, buf) - } -} - - - - -data class ListKeyVersionsResponse ( - var `keyVersions`: List -) { - - companion object -} - -public object FfiConverterTypeListKeyVersionsResponse: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): ListKeyVersionsResponse { - return ListKeyVersionsResponse( - FfiConverterSequenceTypeKeyVersion.read(buf), - ) - } - - override fun allocationSize(value: ListKeyVersionsResponse) = ( - FfiConverterSequenceTypeKeyVersion.allocationSize(value.`keyVersions`) - ) - - override fun write(value: ListKeyVersionsResponse, buf: ByteBuffer) { - FfiConverterSequenceTypeKeyVersion.write(value.`keyVersions`, buf) - } -} - - - - -data class VssItem ( - var `key`: String, - var `value`: ByteArray, - var `version`: Long -) { - - companion object -} - -public object FfiConverterTypeVssItem: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): VssItem { - return VssItem( - FfiConverterString.read(buf), - FfiConverterByteArray.read(buf), - FfiConverterLong.read(buf), - ) - } - - override fun allocationSize(value: VssItem) = ( - FfiConverterString.allocationSize(value.`key`) + - FfiConverterByteArray.allocationSize(value.`value`) + - FfiConverterLong.allocationSize(value.`version`) - ) - - override fun write(value: VssItem, buf: ByteBuffer) { - FfiConverterString.write(value.`key`, buf) - FfiConverterByteArray.write(value.`value`, buf) - FfiConverterLong.write(value.`version`, buf) - } -} - - - - - -sealed class VssException: Exception() { - // Each variant is a nested class - - class ConnectionException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class AuthException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class StoreException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class GetException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class ListException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class PutException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class DeleteException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class InvalidData( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class NetworkException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - class UnknownException( - val `errorDetails`: String - ) : VssException() { - override val message - get() = "errorDetails=${ `errorDetails` }" - } - - - companion object ErrorHandler : CallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): VssException = FfiConverterTypeVssError.lift(error_buf) - } - - -} - -public object FfiConverterTypeVssError : FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): VssException { - - - return when(buf.getInt()) { - 1 -> VssException.ConnectionException( - FfiConverterString.read(buf), - ) - 2 -> VssException.AuthException( - FfiConverterString.read(buf), - ) - 3 -> VssException.StoreException( - FfiConverterString.read(buf), - ) - 4 -> VssException.GetException( - FfiConverterString.read(buf), - ) - 5 -> VssException.ListException( - FfiConverterString.read(buf), - ) - 6 -> VssException.PutException( - FfiConverterString.read(buf), - ) - 7 -> VssException.DeleteException( - FfiConverterString.read(buf), - ) - 8 -> VssException.InvalidData( - FfiConverterString.read(buf), - ) - 9 -> VssException.NetworkException( - FfiConverterString.read(buf), - ) - 10 -> VssException.UnknownException( - FfiConverterString.read(buf), - ) - else -> throw RuntimeException("invalid error enum value, something is very wrong!!") - } - } - - override fun allocationSize(value: VssException): Int { - return when(value) { - is VssException.ConnectionException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.AuthException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.StoreException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.GetException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.ListException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.PutException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.DeleteException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.InvalidData -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.NetworkException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - is VssException.UnknownException -> ( - // Add the size for the Int that specifies the variant plus the size needed for all fields - 4 - + FfiConverterString.allocationSize(value.`errorDetails`) - ) - } - } - - override fun write(value: VssException, buf: ByteBuffer) { - when(value) { - is VssException.ConnectionException -> { - buf.putInt(1) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.AuthException -> { - buf.putInt(2) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.StoreException -> { - buf.putInt(3) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.GetException -> { - buf.putInt(4) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.ListException -> { - buf.putInt(5) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.PutException -> { - buf.putInt(6) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.DeleteException -> { - buf.putInt(7) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.InvalidData -> { - buf.putInt(8) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.NetworkException -> { - buf.putInt(9) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - is VssException.UnknownException -> { - buf.putInt(10) - FfiConverterString.write(value.`errorDetails`, buf) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } - -} - - - - -enum class VssFilterType { - PREFIX,EXACT; - companion object -} - -public object FfiConverterTypeVssFilterType: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer) = try { - VssFilterType.values()[buf.getInt() - 1] - } catch (e: IndexOutOfBoundsException) { - throw RuntimeException("invalid enum value, something is very wrong!!", e) - } - - override fun allocationSize(value: VssFilterType) = 4 - - override fun write(value: VssFilterType, buf: ByteBuffer) { - buf.putInt(value.ordinal + 1) - } -} - - - - - - -public object FfiConverterOptionalString: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): String? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterString.read(buf) - } - - override fun allocationSize(value: String?): Int { - if (value == null) { - return 1 - } else { - return 1 + FfiConverterString.allocationSize(value) - } - } - - override fun write(value: String?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterString.write(value, buf) - } - } -} - - - - -public object FfiConverterOptionalTypeVssItem: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): VssItem? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterTypeVssItem.read(buf) - } - - override fun allocationSize(value: VssItem?): Int { - if (value == null) { - return 1 - } else { - return 1 + FfiConverterTypeVssItem.allocationSize(value) - } - } - - override fun write(value: VssItem?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterTypeVssItem.write(value, buf) - } - } -} - - - - -public object FfiConverterSequenceTypeKeyValue: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterTypeKeyValue.read(buf) - } - } - - override fun allocationSize(value: List): Int { - val sizeForLength = 4 - val sizeForItems = value.map { FfiConverterTypeKeyValue.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.forEach { - FfiConverterTypeKeyValue.write(it, buf) - } - } -} - - - - -public object FfiConverterSequenceTypeKeyVersion: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterTypeKeyVersion.read(buf) - } - } - - override fun allocationSize(value: List): Int { - val sizeForLength = 4 - val sizeForItems = value.map { FfiConverterTypeKeyVersion.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.forEach { - FfiConverterTypeKeyVersion.write(it, buf) - } - } -} - - - - -public object FfiConverterSequenceTypeVssItem: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterTypeVssItem.read(buf) - } - } - - override fun allocationSize(value: List): Int { - val sizeForLength = 4 - val sizeForItems = value.map { FfiConverterTypeVssItem.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.forEach { - FfiConverterTypeVssItem.write(it, buf) - } - } -} - - - - -@Throws(VssException::class) - -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssDelete`(`key`: String) : Boolean { - return uniffiRustCallAsync( - _UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_delete(FfiConverterString.lower(`key`),), - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_i8(future, continuation) }, - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_i8(future, continuation) }, - { future -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_i8(future) }, - // lift function - { FfiConverterBoolean.lift(it) }, - // Error FFI converter - VssException.ErrorHandler, - ) -} -@Throws(VssException::class) - -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssGet`(`key`: String) : VssItem? { - return uniffiRustCallAsync( - _UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_get(FfiConverterString.lower(`key`),), - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, continuation) }, - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, - { future -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, - // lift function - { FfiConverterOptionalTypeVssItem.lift(it) }, - // Error FFI converter - VssException.ErrorHandler, - ) -} -@Throws(VssException::class) - -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssList`(`prefix`: String?) : List { - return uniffiRustCallAsync( - _UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_list(FfiConverterOptionalString.lower(`prefix`),), - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, continuation) }, - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, - { future -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, - // lift function - { FfiConverterSequenceTypeVssItem.lift(it) }, - // Error FFI converter - VssException.ErrorHandler, - ) -} -@Throws(VssException::class) - -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssListKeys`(`prefix`: String?) : List { - return uniffiRustCallAsync( - _UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_list_keys(FfiConverterOptionalString.lower(`prefix`),), - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, continuation) }, - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, - { future -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, - // lift function - { FfiConverterSequenceTypeKeyVersion.lift(it) }, - // Error FFI converter - VssException.ErrorHandler, - ) -} -@Throws(VssException::class) - -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssNewClient`(`baseUrl`: String, `storeId`: String) { - return uniffiRustCallAsync( - _UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_new_client(FfiConverterString.lower(`baseUrl`),FfiConverterString.lower(`storeId`),), - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_void(future, continuation) }, - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_void(future, continuation) }, - { future -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_void(future) }, - // lift function - { Unit }, - - // Error FFI converter - VssException.ErrorHandler, - ) -} -@Throws(VssException::class) - -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssPutWithKeyPrefix`(`items`: List) : List { - return uniffiRustCallAsync( - _UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_put_with_key_prefix(FfiConverterSequenceTypeKeyValue.lower(`items`),), - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, continuation) }, - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, - { future -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, - // lift function - { FfiConverterSequenceTypeVssItem.lift(it) }, - // Error FFI converter - VssException.ErrorHandler, - ) -} - -fun `vssShutdownClient`() = - - rustCall() { _status -> - _UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_shutdown_client(_status) -} - - -@Throws(VssException::class) - -@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") -suspend fun `vssStore`(`key`: String, `value`: ByteArray) : VssItem { - return uniffiRustCallAsync( - _UniFFILib.INSTANCE.uniffi_vss_rust_client_ffi_fn_func_vss_store(FfiConverterString.lower(`key`),FfiConverterByteArray.lower(`value`),), - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_poll_rust_buffer(future, continuation) }, - { future, continuation -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_complete_rust_buffer(future, continuation) }, - { future -> _UniFFILib.INSTANCE.ffi_vss_rust_client_ffi_rust_future_free_rust_buffer(future) }, - // lift function - { FfiConverterTypeVssItem.lift(it) }, - // Error FFI converter - VssException.ErrorHandler, - ) -} - diff --git a/libs/vss-client/src/main/jniLibs/arm64-v8a/libvss_rust_client_ffi.so b/libs/vss-client/src/main/jniLibs/arm64-v8a/libvss_rust_client_ffi.so deleted file mode 100755 index c0604b882..000000000 Binary files a/libs/vss-client/src/main/jniLibs/arm64-v8a/libvss_rust_client_ffi.so and /dev/null differ diff --git a/libs/vss-client/src/main/jniLibs/armeabi-v7a/libvss_rust_client_ffi.so b/libs/vss-client/src/main/jniLibs/armeabi-v7a/libvss_rust_client_ffi.so deleted file mode 100755 index 8bc25db0f..000000000 Binary files a/libs/vss-client/src/main/jniLibs/armeabi-v7a/libvss_rust_client_ffi.so and /dev/null differ diff --git a/libs/vss-client/src/main/jniLibs/x86/libvss_rust_client_ffi.so b/libs/vss-client/src/main/jniLibs/x86/libvss_rust_client_ffi.so deleted file mode 100755 index d29d9d67a..000000000 Binary files a/libs/vss-client/src/main/jniLibs/x86/libvss_rust_client_ffi.so and /dev/null differ diff --git a/libs/vss-client/src/main/jniLibs/x86_64/libvss_rust_client_ffi.so b/libs/vss-client/src/main/jniLibs/x86_64/libvss_rust_client_ffi.so deleted file mode 100755 index 888676148..000000000 Binary files a/libs/vss-client/src/main/jniLibs/x86_64/libvss_rust_client_ffi.so and /dev/null differ diff --git a/settings.gradle.kts b/settings.gradle.kts index 698720575..49c424185 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,25 @@ -import java.io.FileInputStream -import java.util.Properties +import java.util.* +val localProperties by lazy { + Properties().apply { + val file = rootDir.resolve("local.properties") + if (file.exists()) { + file.inputStream().use { load(it) } + } + } +} +fun getGithubCredentials( + passKey: String = "gpr.key", + userKey: String = "gpr.user", +): Pair { + val user = System.getenv("GITHUB_ACTOR") + ?: providers.gradleProperty(userKey).orNull + ?: localProperties.getProperty(userKey) + val key = System.getenv("GITHUB_TOKEN") + ?: providers.gradleProperty(passKey).orNull + ?: localProperties.getProperty(passKey) + return user to key +} pluginManagement { repositories { google() @@ -19,26 +38,20 @@ dependencyResolutionManagement { maven { url = uri("https://maven.pkg.github.com/synonymdev/bitkit-core") credentials { - - val localPropertiesFile = File(rootDir, "gradle.properties") - val localProperties = Properties() - - if (localPropertiesFile.exists()) { - localProperties.load(FileInputStream(localPropertiesFile)) - } - - username = System.getenv("GITHUB_ACTOR") - ?: localProperties.getProperty("gpr.user") - ?: providers.gradleProperty("gpr.user").orNull - - - password = System.getenv("GITHUB_TOKEN") - ?: localProperties.getProperty("gpr.key") - ?: providers.gradleProperty("gpr.key").orNull + val (user, pass) = getGithubCredentials() + username = user + password = pass + } + } + maven { + url = uri("https://maven.pkg.github.com/synonymdev/vss-rust-client-ffi") + credentials { + val (user, pass) = getGithubCredentials() + username = user + password = pass } } } } rootProject.name = "bitkit-android" include(":app") -include(":libs:vss-client")