@rhq/rover 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/Rover.podspec +32 -0
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +77 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/cpp/rover-jni.cpp +15 -0
- package/android/src/main/java/com/relayhq/rover/RoverJsiModule.kt +16 -0
- package/android/src/main/java/com/relayhq/rover/RoverModule.kt +56 -0
- package/android/src/main/java/com/relayhq/rover/RoverNativeBridge.kt +45 -0
- package/android/src/main/java/com/relayhq/rover/RoverNativeModule.kt +73 -0
- package/android/src/main/java/com/relayhq/rover/RoverPackage.kt +16 -0
- package/android/src/main/java/uniffi/relay_rover/relay_rover.kt +1089 -0
- package/android/src/main/jniLibs/arm64-v8a/librelay_rover.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/librelay_rover.so +0 -0
- package/android/src/main/jniLibs/x86_64/librelay_rover.so +0 -0
- package/cpp/RoverJsi.cpp +156 -0
- package/cpp/RoverJsi.h +20 -0
- package/expo-module.config.json +10 -0
- package/index.d.ts +12 -0
- package/index.js +5 -5
- package/index.native.js +476 -0
- package/ios/Rover-Bridging-Header.h +1 -0
- package/ios/RoverBridge.mm +117 -0
- package/ios/RoverModule.swift +54 -0
- package/ios/relay_rover.swift +623 -0
- package/ios/relay_roverFFI.h +589 -0
- package/ios/relay_roverFFI.modulemap +7 -0
- package/package.json +26 -3
|
@@ -0,0 +1,1089 @@
|
|
|
1
|
+
// This file was autogenerated by some hot garbage in the `uniffi` crate.
|
|
2
|
+
// Trust me, you don't want to mess with it!
|
|
3
|
+
|
|
4
|
+
@file:Suppress("NAME_SHADOWING")
|
|
5
|
+
|
|
6
|
+
package uniffi.relay_rover
|
|
7
|
+
|
|
8
|
+
// Common helper code.
|
|
9
|
+
//
|
|
10
|
+
// Ideally this would live in a separate .kt file where it can be unittested etc
|
|
11
|
+
// in isolation, and perhaps even published as a re-useable package.
|
|
12
|
+
//
|
|
13
|
+
// However, it's important that the details of how this helper code works (e.g. the
|
|
14
|
+
// way that different builtin types are passed across the FFI) exactly match what's
|
|
15
|
+
// expected by the Rust code on the other side of the interface. In practice right
|
|
16
|
+
// now that means coming from the exact some version of `uniffi` that was used to
|
|
17
|
+
// compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
|
|
18
|
+
// helpers directly inline like we're doing here.
|
|
19
|
+
|
|
20
|
+
import com.sun.jna.Library
|
|
21
|
+
import com.sun.jna.IntegerType
|
|
22
|
+
import com.sun.jna.Native
|
|
23
|
+
import com.sun.jna.Pointer
|
|
24
|
+
import com.sun.jna.Structure
|
|
25
|
+
import com.sun.jna.Callback
|
|
26
|
+
import com.sun.jna.ptr.*
|
|
27
|
+
import java.nio.ByteBuffer
|
|
28
|
+
import java.nio.ByteOrder
|
|
29
|
+
import java.nio.CharBuffer
|
|
30
|
+
import java.nio.charset.CodingErrorAction
|
|
31
|
+
import java.util.concurrent.atomic.AtomicLong
|
|
32
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
33
|
+
|
|
34
|
+
// This is a helper for safely working with byte buffers returned from the Rust code.
|
|
35
|
+
// A rust-owned buffer is represented by its capacity, its current length, and a
|
|
36
|
+
// pointer to the underlying data.
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @suppress
|
|
40
|
+
*/
|
|
41
|
+
@Structure.FieldOrder("capacity", "len", "data")
|
|
42
|
+
open class RustBuffer : Structure() {
|
|
43
|
+
// Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
|
|
44
|
+
// When dealing with these fields, make sure to call `toULong()`.
|
|
45
|
+
@JvmField var capacity: Long = 0
|
|
46
|
+
@JvmField var len: Long = 0
|
|
47
|
+
@JvmField var data: Pointer? = null
|
|
48
|
+
|
|
49
|
+
class ByValue: RustBuffer(), Structure.ByValue
|
|
50
|
+
class ByReference: RustBuffer(), Structure.ByReference
|
|
51
|
+
|
|
52
|
+
internal fun setValue(other: RustBuffer) {
|
|
53
|
+
capacity = other.capacity
|
|
54
|
+
len = other.len
|
|
55
|
+
data = other.data
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
companion object {
|
|
59
|
+
internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
|
|
60
|
+
// Note: need to convert the size to a `Long` value to make this work with JVM.
|
|
61
|
+
UniffiLib.ffi_relay_rover_rustbuffer_alloc(size.toLong(), status)
|
|
62
|
+
}.also {
|
|
63
|
+
if(it.data == null) {
|
|
64
|
+
throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
|
|
69
|
+
var buf = RustBuffer.ByValue()
|
|
70
|
+
buf.capacity = capacity.toLong()
|
|
71
|
+
buf.len = len.toLong()
|
|
72
|
+
buf.data = data
|
|
73
|
+
return buf
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
|
|
77
|
+
UniffiLib.ffi_relay_rover_rustbuffer_free(buf, status)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Suppress("TooGenericExceptionThrown")
|
|
82
|
+
fun asByteBuffer() =
|
|
83
|
+
this.data?.getByteBuffer(0, this.len)?.also {
|
|
84
|
+
it.order(ByteOrder.BIG_ENDIAN)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// This is a helper for safely passing byte references into the rust code.
|
|
89
|
+
// It's not actually used at the moment, because there aren't many things that you
|
|
90
|
+
// can take a direct pointer to in the JVM, and if we're going to copy something
|
|
91
|
+
// then we might as well copy it into a `RustBuffer`. But it's here for API
|
|
92
|
+
// completeness.
|
|
93
|
+
|
|
94
|
+
@Structure.FieldOrder("len", "data")
|
|
95
|
+
internal open class ForeignBytes : Structure() {
|
|
96
|
+
@JvmField var len: Int = 0
|
|
97
|
+
@JvmField var data: Pointer? = null
|
|
98
|
+
|
|
99
|
+
class ByValue : ForeignBytes(), Structure.ByValue
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Converter for `&[u8]` / `[ByRef] bytes` arguments.
|
|
103
|
+
//
|
|
104
|
+
// Only `lower` is valid — zero-copy byte buffers only flow foreign -> Rust,
|
|
105
|
+
// and only in argument position. `lift`, `read`, `write`, and
|
|
106
|
+
// `allocationSize` have no sound implementation here and all panic at
|
|
107
|
+
// runtime. The `FfiConverter` interface is implemented so that the
|
|
108
|
+
// compiler enforces the full method set (rather than relying on eyeball).
|
|
109
|
+
//
|
|
110
|
+
// The provided `ByteBuffer` MUST be direct — only direct buffers have a
|
|
111
|
+
// stable native address that JNA can expose via `getDirectBufferPointer`.
|
|
112
|
+
// The returned `ForeignBytes.ByValue` is only valid for the duration of
|
|
113
|
+
// the FFI call; the Rust side treats it as a borrow.
|
|
114
|
+
internal object FfiConverterByRefBytes : FfiConverter<java.nio.ByteBuffer, ForeignBytes.ByValue> {
|
|
115
|
+
override fun lower(value: java.nio.ByteBuffer): ForeignBytes.ByValue {
|
|
116
|
+
require(value.isDirect) { "UniFFI zero-copy &[u8] requires a direct ByteBuffer. Use ByteBuffer.allocateDirect()." }
|
|
117
|
+
val remaining = value.remaining()
|
|
118
|
+
val fb = ForeignBytes.ByValue()
|
|
119
|
+
fb.len = remaining
|
|
120
|
+
// Zero-length direct buffers: skip getDirectBufferPointer (platform-variable behavior)
|
|
121
|
+
// and pass null. The Rust side treats (null, 0) as &[].
|
|
122
|
+
fb.data = if (remaining == 0) null else com.sun.jna.Native.getDirectBufferPointer(value)
|
|
123
|
+
return fb
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
override fun lift(value: ForeignBytes.ByValue): java.nio.ByteBuffer =
|
|
127
|
+
error("ByRef bytes cannot be lifted: zero-copy &[u8] only flows foreign->Rust")
|
|
128
|
+
|
|
129
|
+
override fun read(buf: java.nio.ByteBuffer): java.nio.ByteBuffer =
|
|
130
|
+
error("ByRef bytes cannot be read from a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
|
|
131
|
+
|
|
132
|
+
override fun write(value: java.nio.ByteBuffer, buf: java.nio.ByteBuffer): Unit =
|
|
133
|
+
error("ByRef bytes cannot be written to a buffer: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
|
|
134
|
+
|
|
135
|
+
override fun allocationSize(value: java.nio.ByteBuffer): ULong =
|
|
136
|
+
error("ByRef bytes have no RustBuffer allocation size: zero-copy &[u8] is only supported in argument position, not nested in records/options/etc.")
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The FfiConverter interface handles converter types to and from the FFI
|
|
140
|
+
*
|
|
141
|
+
* All implementing objects should be public to support external types. When a
|
|
142
|
+
* type is external we need to import it's FfiConverter.
|
|
143
|
+
*
|
|
144
|
+
* @suppress
|
|
145
|
+
*/
|
|
146
|
+
public interface FfiConverter<KotlinType, FfiType> {
|
|
147
|
+
// Convert an FFI type to a Kotlin type
|
|
148
|
+
fun lift(value: FfiType): KotlinType
|
|
149
|
+
|
|
150
|
+
// Convert an Kotlin type to an FFI type
|
|
151
|
+
fun lower(value: KotlinType): FfiType
|
|
152
|
+
|
|
153
|
+
// Read a Kotlin type from a `ByteBuffer`
|
|
154
|
+
fun read(buf: ByteBuffer): KotlinType
|
|
155
|
+
|
|
156
|
+
// Calculate bytes to allocate when creating a `RustBuffer`
|
|
157
|
+
//
|
|
158
|
+
// This must return at least as many bytes as the write() function will
|
|
159
|
+
// write. It can return more bytes than needed, for example when writing
|
|
160
|
+
// Strings we can't know the exact bytes needed until we the UTF-8
|
|
161
|
+
// encoding, so we pessimistically allocate the largest size possible (3
|
|
162
|
+
// bytes per codepoint). Allocating extra bytes is not really a big deal
|
|
163
|
+
// because the `RustBuffer` is short-lived.
|
|
164
|
+
fun allocationSize(value: KotlinType): ULong
|
|
165
|
+
|
|
166
|
+
// Write a Kotlin type to a `ByteBuffer`
|
|
167
|
+
fun write(value: KotlinType, buf: ByteBuffer)
|
|
168
|
+
|
|
169
|
+
// Lower a value into a `RustBuffer`
|
|
170
|
+
//
|
|
171
|
+
// This method lowers a value into a `RustBuffer` rather than the normal
|
|
172
|
+
// FfiType. It's used by the callback interface code. Callback interface
|
|
173
|
+
// returns are always serialized into a `RustBuffer` regardless of their
|
|
174
|
+
// normal FFI type.
|
|
175
|
+
fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
|
|
176
|
+
val rbuf = RustBuffer.alloc(allocationSize(value))
|
|
177
|
+
try {
|
|
178
|
+
val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
|
|
179
|
+
it.order(ByteOrder.BIG_ENDIAN)
|
|
180
|
+
}
|
|
181
|
+
write(value, bbuf)
|
|
182
|
+
rbuf.writeField("len", bbuf.position().toLong())
|
|
183
|
+
return rbuf
|
|
184
|
+
} catch (e: Throwable) {
|
|
185
|
+
RustBuffer.free(rbuf)
|
|
186
|
+
throw e
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Lift a value from a `RustBuffer`.
|
|
191
|
+
//
|
|
192
|
+
// This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
|
|
193
|
+
// It's currently only used by the `FfiConverterRustBuffer` class below.
|
|
194
|
+
fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
|
|
195
|
+
val byteBuf = rbuf.asByteBuffer()!!
|
|
196
|
+
try {
|
|
197
|
+
val item = read(byteBuf)
|
|
198
|
+
if (byteBuf.hasRemaining()) {
|
|
199
|
+
throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
|
|
200
|
+
}
|
|
201
|
+
return item
|
|
202
|
+
} finally {
|
|
203
|
+
RustBuffer.free(rbuf)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* FfiConverter that uses `RustBuffer` as the FfiType
|
|
210
|
+
*
|
|
211
|
+
* @suppress
|
|
212
|
+
*/
|
|
213
|
+
public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
|
|
214
|
+
override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
|
|
215
|
+
override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
|
|
216
|
+
}
|
|
217
|
+
// A handful of classes and functions to support the generated data structures.
|
|
218
|
+
// This would be a good candidate for isolating in its own ffi-support lib.
|
|
219
|
+
|
|
220
|
+
internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
|
|
221
|
+
internal const val UNIFFI_CALL_ERROR = 1.toByte()
|
|
222
|
+
internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
|
|
223
|
+
|
|
224
|
+
@Structure.FieldOrder("code", "error_buf")
|
|
225
|
+
internal open class UniffiRustCallStatus : Structure() {
|
|
226
|
+
@JvmField var code: Byte = 0
|
|
227
|
+
@JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
|
|
228
|
+
|
|
229
|
+
class ByValue: UniffiRustCallStatus(), Structure.ByValue
|
|
230
|
+
|
|
231
|
+
fun isSuccess(): Boolean {
|
|
232
|
+
return code == UNIFFI_CALL_SUCCESS
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
fun isError(): Boolean {
|
|
236
|
+
return code == UNIFFI_CALL_ERROR
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
fun isPanic(): Boolean {
|
|
240
|
+
return code == UNIFFI_CALL_UNEXPECTED_ERROR
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
companion object {
|
|
244
|
+
fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
|
|
245
|
+
val callStatus = UniffiRustCallStatus.ByValue()
|
|
246
|
+
callStatus.code = code
|
|
247
|
+
callStatus.error_buf = errorBuf
|
|
248
|
+
return callStatus
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
class InternalException(message: String) : kotlin.Exception(message)
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Each top-level error class has a companion object that can lift the error from the call status's rust buffer
|
|
257
|
+
*
|
|
258
|
+
* @suppress
|
|
259
|
+
*/
|
|
260
|
+
interface UniffiRustCallStatusErrorHandler<E> {
|
|
261
|
+
fun lift(error_buf: RustBuffer.ByValue): E;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Helpers for calling Rust
|
|
265
|
+
// In practice we usually need to be synchronized to call this safely, so it doesn't
|
|
266
|
+
// synchronize itself
|
|
267
|
+
|
|
268
|
+
// Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
|
|
269
|
+
private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
|
|
270
|
+
var status = UniffiRustCallStatus()
|
|
271
|
+
val return_value = callback(status)
|
|
272
|
+
uniffiCheckCallStatus(errorHandler, status)
|
|
273
|
+
return return_value
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Check UniffiRustCallStatus and throw an error if the call wasn't successful
|
|
277
|
+
private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
|
|
278
|
+
if (status.isSuccess()) {
|
|
279
|
+
return
|
|
280
|
+
} else if (status.isError()) {
|
|
281
|
+
throw errorHandler.lift(status.error_buf)
|
|
282
|
+
} else if (status.isPanic()) {
|
|
283
|
+
// when the rust code sees a panic, it tries to construct a rustbuffer
|
|
284
|
+
// with the message. but if that code panics, then it just sends back
|
|
285
|
+
// an empty buffer.
|
|
286
|
+
if (status.error_buf.len > 0) {
|
|
287
|
+
throw InternalException(FfiConverterString.lift(status.error_buf))
|
|
288
|
+
} else {
|
|
289
|
+
throw InternalException("Rust panic")
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
throw InternalException("Unknown rust call status: $status.code")
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
|
|
298
|
+
*
|
|
299
|
+
* @suppress
|
|
300
|
+
*/
|
|
301
|
+
object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
|
|
302
|
+
override fun lift(error_buf: RustBuffer.ByValue): InternalException {
|
|
303
|
+
RustBuffer.free(error_buf)
|
|
304
|
+
return InternalException("Unexpected CALL_ERROR")
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Call a rust function that returns a plain value
|
|
309
|
+
private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
|
|
310
|
+
return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
internal inline fun<T> uniffiTraitInterfaceCall(
|
|
314
|
+
callStatus: UniffiRustCallStatus,
|
|
315
|
+
makeCall: () -> T,
|
|
316
|
+
writeReturn: (T) -> Unit,
|
|
317
|
+
) {
|
|
318
|
+
try {
|
|
319
|
+
writeReturn(makeCall())
|
|
320
|
+
} catch(e: kotlin.Exception) {
|
|
321
|
+
val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
|
|
322
|
+
callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
|
|
323
|
+
callStatus.error_buf = FfiConverterString.lower(err)
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
|
|
328
|
+
callStatus: UniffiRustCallStatus,
|
|
329
|
+
makeCall: () -> T,
|
|
330
|
+
writeReturn: (T) -> Unit,
|
|
331
|
+
lowerError: (E) -> RustBuffer.ByValue
|
|
332
|
+
) {
|
|
333
|
+
try {
|
|
334
|
+
writeReturn(makeCall())
|
|
335
|
+
} catch(e: kotlin.Exception) {
|
|
336
|
+
if (e is E) {
|
|
337
|
+
callStatus.code = UNIFFI_CALL_ERROR
|
|
338
|
+
callStatus.error_buf = lowerError(e)
|
|
339
|
+
} else {
|
|
340
|
+
val err = try { e.stackTraceToString() } catch(_: Throwable) { "" }
|
|
341
|
+
callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
|
|
342
|
+
callStatus.error_buf = FfiConverterString.lower(err)
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// Initial value and increment amount for handles.
|
|
347
|
+
// These ensure that Kotlin-generated handles always have the lowest bit set
|
|
348
|
+
private const val UNIFFI_HANDLEMAP_INITIAL = 1.toLong()
|
|
349
|
+
private const val UNIFFI_HANDLEMAP_DELTA = 2.toLong()
|
|
350
|
+
|
|
351
|
+
// Map handles to objects
|
|
352
|
+
//
|
|
353
|
+
// This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
|
|
354
|
+
internal class UniffiHandleMap<T: Any> {
|
|
355
|
+
private val map = ConcurrentHashMap<Long, T>()
|
|
356
|
+
// Start
|
|
357
|
+
private val counter = java.util.concurrent.atomic.AtomicLong(UNIFFI_HANDLEMAP_INITIAL)
|
|
358
|
+
|
|
359
|
+
val size: Int
|
|
360
|
+
get() = map.size
|
|
361
|
+
|
|
362
|
+
// Insert a new object into the handle map and get a handle for it
|
|
363
|
+
fun insert(obj: T): Long {
|
|
364
|
+
val handle = counter.getAndAdd(UNIFFI_HANDLEMAP_DELTA)
|
|
365
|
+
map.put(handle, obj)
|
|
366
|
+
return handle
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Clone a handle, creating a new one
|
|
370
|
+
fun clone(handle: Long): Long {
|
|
371
|
+
val obj = map.get(handle) ?: throw InternalException("UniffiHandleMap.clone: Invalid handle")
|
|
372
|
+
return insert(obj)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Get an object from the handle map
|
|
376
|
+
fun get(handle: Long): T {
|
|
377
|
+
return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Remove an entry from the handlemap and get the Kotlin object back
|
|
381
|
+
fun remove(handle: Long): T {
|
|
382
|
+
return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Contains loading, initialization code,
|
|
387
|
+
// and the FFI Function declarations in a com.sun.jna.Library.
|
|
388
|
+
@Synchronized
|
|
389
|
+
private fun findLibraryName(componentName: String): String {
|
|
390
|
+
val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
|
|
391
|
+
if (libOverride != null) {
|
|
392
|
+
return libOverride
|
|
393
|
+
}
|
|
394
|
+
return "uniffi_relay_rover"
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Define FFI callback types
|
|
398
|
+
internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
|
|
399
|
+
fun callback(`data`: Long,`pollResult`: Byte,)
|
|
400
|
+
}
|
|
401
|
+
internal interface UniffiForeignFutureDroppedCallback : com.sun.jna.Callback {
|
|
402
|
+
fun callback(`handle`: Long,)
|
|
403
|
+
}
|
|
404
|
+
internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
|
|
405
|
+
fun callback(`handle`: Long,)
|
|
406
|
+
}
|
|
407
|
+
internal interface UniffiCallbackInterfaceClone : com.sun.jna.Callback {
|
|
408
|
+
fun callback(`handle`: Long,)
|
|
409
|
+
: Long
|
|
410
|
+
}
|
|
411
|
+
@Structure.FieldOrder("handle", "free")
|
|
412
|
+
internal open class UniffiForeignFutureDroppedCallbackStruct(
|
|
413
|
+
@JvmField internal var `handle`: Long = 0.toLong(),
|
|
414
|
+
@JvmField internal var `free`: UniffiForeignFutureDroppedCallback? = null,
|
|
415
|
+
) : Structure() {
|
|
416
|
+
class UniffiByValue(
|
|
417
|
+
`handle`: Long = 0.toLong(),
|
|
418
|
+
`free`: UniffiForeignFutureDroppedCallback? = null,
|
|
419
|
+
): UniffiForeignFutureDroppedCallbackStruct(`handle`,`free`,), Structure.ByValue
|
|
420
|
+
|
|
421
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureDroppedCallbackStruct) {
|
|
422
|
+
`handle` = other.`handle`
|
|
423
|
+
`free` = other.`free`
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
}
|
|
427
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
428
|
+
internal open class UniffiForeignFutureResultU8(
|
|
429
|
+
@JvmField internal var `returnValue`: Byte = 0.toByte(),
|
|
430
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
431
|
+
) : Structure() {
|
|
432
|
+
class UniffiByValue(
|
|
433
|
+
`returnValue`: Byte = 0.toByte(),
|
|
434
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
435
|
+
): UniffiForeignFutureResultU8(`returnValue`,`callStatus`,), Structure.ByValue
|
|
436
|
+
|
|
437
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultU8) {
|
|
438
|
+
`returnValue` = other.`returnValue`
|
|
439
|
+
`callStatus` = other.`callStatus`
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
}
|
|
443
|
+
internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
|
|
444
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU8.UniffiByValue,)
|
|
445
|
+
}
|
|
446
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
447
|
+
internal open class UniffiForeignFutureResultI8(
|
|
448
|
+
@JvmField internal var `returnValue`: Byte = 0.toByte(),
|
|
449
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
450
|
+
) : Structure() {
|
|
451
|
+
class UniffiByValue(
|
|
452
|
+
`returnValue`: Byte = 0.toByte(),
|
|
453
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
454
|
+
): UniffiForeignFutureResultI8(`returnValue`,`callStatus`,), Structure.ByValue
|
|
455
|
+
|
|
456
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultI8) {
|
|
457
|
+
`returnValue` = other.`returnValue`
|
|
458
|
+
`callStatus` = other.`callStatus`
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
}
|
|
462
|
+
internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
|
|
463
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI8.UniffiByValue,)
|
|
464
|
+
}
|
|
465
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
466
|
+
internal open class UniffiForeignFutureResultU16(
|
|
467
|
+
@JvmField internal var `returnValue`: Short = 0.toShort(),
|
|
468
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
469
|
+
) : Structure() {
|
|
470
|
+
class UniffiByValue(
|
|
471
|
+
`returnValue`: Short = 0.toShort(),
|
|
472
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
473
|
+
): UniffiForeignFutureResultU16(`returnValue`,`callStatus`,), Structure.ByValue
|
|
474
|
+
|
|
475
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultU16) {
|
|
476
|
+
`returnValue` = other.`returnValue`
|
|
477
|
+
`callStatus` = other.`callStatus`
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
}
|
|
481
|
+
internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
|
|
482
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU16.UniffiByValue,)
|
|
483
|
+
}
|
|
484
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
485
|
+
internal open class UniffiForeignFutureResultI16(
|
|
486
|
+
@JvmField internal var `returnValue`: Short = 0.toShort(),
|
|
487
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
488
|
+
) : Structure() {
|
|
489
|
+
class UniffiByValue(
|
|
490
|
+
`returnValue`: Short = 0.toShort(),
|
|
491
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
492
|
+
): UniffiForeignFutureResultI16(`returnValue`,`callStatus`,), Structure.ByValue
|
|
493
|
+
|
|
494
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultI16) {
|
|
495
|
+
`returnValue` = other.`returnValue`
|
|
496
|
+
`callStatus` = other.`callStatus`
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
}
|
|
500
|
+
internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
|
|
501
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI16.UniffiByValue,)
|
|
502
|
+
}
|
|
503
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
504
|
+
internal open class UniffiForeignFutureResultU32(
|
|
505
|
+
@JvmField internal var `returnValue`: Int = 0,
|
|
506
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
507
|
+
) : Structure() {
|
|
508
|
+
class UniffiByValue(
|
|
509
|
+
`returnValue`: Int = 0,
|
|
510
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
511
|
+
): UniffiForeignFutureResultU32(`returnValue`,`callStatus`,), Structure.ByValue
|
|
512
|
+
|
|
513
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultU32) {
|
|
514
|
+
`returnValue` = other.`returnValue`
|
|
515
|
+
`callStatus` = other.`callStatus`
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
}
|
|
519
|
+
internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
|
|
520
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU32.UniffiByValue,)
|
|
521
|
+
}
|
|
522
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
523
|
+
internal open class UniffiForeignFutureResultI32(
|
|
524
|
+
@JvmField internal var `returnValue`: Int = 0,
|
|
525
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
526
|
+
) : Structure() {
|
|
527
|
+
class UniffiByValue(
|
|
528
|
+
`returnValue`: Int = 0,
|
|
529
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
530
|
+
): UniffiForeignFutureResultI32(`returnValue`,`callStatus`,), Structure.ByValue
|
|
531
|
+
|
|
532
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultI32) {
|
|
533
|
+
`returnValue` = other.`returnValue`
|
|
534
|
+
`callStatus` = other.`callStatus`
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
}
|
|
538
|
+
internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
|
|
539
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI32.UniffiByValue,)
|
|
540
|
+
}
|
|
541
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
542
|
+
internal open class UniffiForeignFutureResultU64(
|
|
543
|
+
@JvmField internal var `returnValue`: Long = 0.toLong(),
|
|
544
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
545
|
+
) : Structure() {
|
|
546
|
+
class UniffiByValue(
|
|
547
|
+
`returnValue`: Long = 0.toLong(),
|
|
548
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
549
|
+
): UniffiForeignFutureResultU64(`returnValue`,`callStatus`,), Structure.ByValue
|
|
550
|
+
|
|
551
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultU64) {
|
|
552
|
+
`returnValue` = other.`returnValue`
|
|
553
|
+
`callStatus` = other.`callStatus`
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
}
|
|
557
|
+
internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
|
|
558
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultU64.UniffiByValue,)
|
|
559
|
+
}
|
|
560
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
561
|
+
internal open class UniffiForeignFutureResultI64(
|
|
562
|
+
@JvmField internal var `returnValue`: Long = 0.toLong(),
|
|
563
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
564
|
+
) : Structure() {
|
|
565
|
+
class UniffiByValue(
|
|
566
|
+
`returnValue`: Long = 0.toLong(),
|
|
567
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
568
|
+
): UniffiForeignFutureResultI64(`returnValue`,`callStatus`,), Structure.ByValue
|
|
569
|
+
|
|
570
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultI64) {
|
|
571
|
+
`returnValue` = other.`returnValue`
|
|
572
|
+
`callStatus` = other.`callStatus`
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
}
|
|
576
|
+
internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
|
|
577
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultI64.UniffiByValue,)
|
|
578
|
+
}
|
|
579
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
580
|
+
internal open class UniffiForeignFutureResultF32(
|
|
581
|
+
@JvmField internal var `returnValue`: Float = 0.0f,
|
|
582
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
583
|
+
) : Structure() {
|
|
584
|
+
class UniffiByValue(
|
|
585
|
+
`returnValue`: Float = 0.0f,
|
|
586
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
587
|
+
): UniffiForeignFutureResultF32(`returnValue`,`callStatus`,), Structure.ByValue
|
|
588
|
+
|
|
589
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultF32) {
|
|
590
|
+
`returnValue` = other.`returnValue`
|
|
591
|
+
`callStatus` = other.`callStatus`
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
}
|
|
595
|
+
internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
|
|
596
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF32.UniffiByValue,)
|
|
597
|
+
}
|
|
598
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
599
|
+
internal open class UniffiForeignFutureResultF64(
|
|
600
|
+
@JvmField internal var `returnValue`: Double = 0.0,
|
|
601
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
602
|
+
) : Structure() {
|
|
603
|
+
class UniffiByValue(
|
|
604
|
+
`returnValue`: Double = 0.0,
|
|
605
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
606
|
+
): UniffiForeignFutureResultF64(`returnValue`,`callStatus`,), Structure.ByValue
|
|
607
|
+
|
|
608
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultF64) {
|
|
609
|
+
`returnValue` = other.`returnValue`
|
|
610
|
+
`callStatus` = other.`callStatus`
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
}
|
|
614
|
+
internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
|
|
615
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultF64.UniffiByValue,)
|
|
616
|
+
}
|
|
617
|
+
@Structure.FieldOrder("returnValue", "callStatus")
|
|
618
|
+
internal open class UniffiForeignFutureResultRustBuffer(
|
|
619
|
+
@JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
|
|
620
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
621
|
+
) : Structure() {
|
|
622
|
+
class UniffiByValue(
|
|
623
|
+
`returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
|
|
624
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
625
|
+
): UniffiForeignFutureResultRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
|
|
626
|
+
|
|
627
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultRustBuffer) {
|
|
628
|
+
`returnValue` = other.`returnValue`
|
|
629
|
+
`callStatus` = other.`callStatus`
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
}
|
|
633
|
+
internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
|
|
634
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultRustBuffer.UniffiByValue,)
|
|
635
|
+
}
|
|
636
|
+
@Structure.FieldOrder("callStatus")
|
|
637
|
+
internal open class UniffiForeignFutureResultVoid(
|
|
638
|
+
@JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
639
|
+
) : Structure() {
|
|
640
|
+
class UniffiByValue(
|
|
641
|
+
`callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
|
|
642
|
+
): UniffiForeignFutureResultVoid(`callStatus`,), Structure.ByValue
|
|
643
|
+
|
|
644
|
+
internal fun uniffiSetValue(other: UniffiForeignFutureResultVoid) {
|
|
645
|
+
`callStatus` = other.`callStatus`
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
}
|
|
649
|
+
internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
|
|
650
|
+
fun callback(`callbackData`: Long,`result`: UniffiForeignFutureResultVoid.UniffiByValue,)
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// A JNA Library to expose the extern-C FFI definitions.
|
|
654
|
+
// This is an implementation detail which will be called internally by the public API.
|
|
655
|
+
|
|
656
|
+
// For large crates we prevent `MethodTooLargeException` (see #2340)
|
|
657
|
+
// N.B. the name of the extension is very misleading, since it is
|
|
658
|
+
// rather `InterfaceTooLargeException`, caused by too many methods
|
|
659
|
+
// in the interface for large crates.
|
|
660
|
+
//
|
|
661
|
+
// By splitting the otherwise huge interface into two parts
|
|
662
|
+
// * UniffiLib (this)
|
|
663
|
+
// * IntegrityCheckingUniffiLib
|
|
664
|
+
// And all checksum methods are put into `IntegrityCheckingUniffiLib`
|
|
665
|
+
// we allow for ~2x as many methods in the UniffiLib interface.
|
|
666
|
+
//
|
|
667
|
+
// Note: above all written when we used JNA's `loadIndirect` etc.
|
|
668
|
+
// We now use JNA's "direct mapping" - unclear if same considerations apply exactly.
|
|
669
|
+
internal object IntegrityCheckingUniffiLib {
|
|
670
|
+
init {
|
|
671
|
+
Native.register(IntegrityCheckingUniffiLib::class.java, findLibraryName(componentName = "relay_rover"))
|
|
672
|
+
uniffiCheckContractApiVersion(this)
|
|
673
|
+
uniffiCheckApiChecksums(this)
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
internal fun ensureInitialized() = Unit
|
|
677
|
+
external fun uniffi_relay_rover_checksum_func_classify(
|
|
678
|
+
): Int
|
|
679
|
+
external fun uniffi_relay_rover_checksum_func_clean_email_body(
|
|
680
|
+
): Int
|
|
681
|
+
external fun uniffi_relay_rover_checksum_func_generate_preview(
|
|
682
|
+
): Int
|
|
683
|
+
external fun uniffi_relay_rover_checksum_func_html_to_text(
|
|
684
|
+
): Int
|
|
685
|
+
external fun uniffi_relay_rover_checksum_func_process_batch_json(
|
|
686
|
+
): Int
|
|
687
|
+
external fun uniffi_relay_rover_checksum_func_process_email(
|
|
688
|
+
): Int
|
|
689
|
+
external fun uniffi_relay_rover_checksum_func_process_email_json(
|
|
690
|
+
): Int
|
|
691
|
+
external fun ffi_relay_rover_uniffi_contract_version(
|
|
692
|
+
): Int
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
internal object UniffiLib {
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
init {
|
|
701
|
+
Native.register(UniffiLib::class.java, findLibraryName(componentName = "relay_rover"))
|
|
702
|
+
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
internal fun ensureInitialized() = Unit
|
|
706
|
+
external fun uniffi_relay_rover_fn_func_classify(`subject`: RustBuffer.ByValue,`body`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
707
|
+
): RustBuffer.ByValue
|
|
708
|
+
external fun uniffi_relay_rover_fn_func_clean_email_body(`bodyOrHtml`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
709
|
+
): RustBuffer.ByValue
|
|
710
|
+
external fun uniffi_relay_rover_fn_func_generate_preview(`subject`: RustBuffer.ByValue,`body`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
711
|
+
): RustBuffer.ByValue
|
|
712
|
+
external fun uniffi_relay_rover_fn_func_html_to_text(`html`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
713
|
+
): RustBuffer.ByValue
|
|
714
|
+
external fun uniffi_relay_rover_fn_func_process_batch_json(`batchJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
715
|
+
): RustBuffer.ByValue
|
|
716
|
+
external fun uniffi_relay_rover_fn_func_process_email(`subject`: RustBuffer.ByValue,`body`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
717
|
+
): RustBuffer.ByValue
|
|
718
|
+
external fun uniffi_relay_rover_fn_func_process_email_json(`emailJson`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
719
|
+
): RustBuffer.ByValue
|
|
720
|
+
external fun ffi_relay_rover_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
721
|
+
): RustBuffer.ByValue
|
|
722
|
+
external fun ffi_relay_rover_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
723
|
+
): RustBuffer.ByValue
|
|
724
|
+
external fun ffi_relay_rover_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
|
|
725
|
+
): Unit
|
|
726
|
+
external fun ffi_relay_rover_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
727
|
+
): RustBuffer.ByValue
|
|
728
|
+
external fun ffi_relay_rover_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
729
|
+
): Unit
|
|
730
|
+
external fun ffi_relay_rover_rust_future_cancel_u8(`handle`: Long,
|
|
731
|
+
): Unit
|
|
732
|
+
external fun ffi_relay_rover_rust_future_free_u8(`handle`: Long,
|
|
733
|
+
): Unit
|
|
734
|
+
external fun ffi_relay_rover_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
735
|
+
): Int
|
|
736
|
+
external fun ffi_relay_rover_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
737
|
+
): Unit
|
|
738
|
+
external fun ffi_relay_rover_rust_future_cancel_i8(`handle`: Long,
|
|
739
|
+
): Unit
|
|
740
|
+
external fun ffi_relay_rover_rust_future_free_i8(`handle`: Long,
|
|
741
|
+
): Unit
|
|
742
|
+
external fun ffi_relay_rover_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
743
|
+
): Byte
|
|
744
|
+
external fun ffi_relay_rover_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
745
|
+
): Unit
|
|
746
|
+
external fun ffi_relay_rover_rust_future_cancel_u16(`handle`: Long,
|
|
747
|
+
): Unit
|
|
748
|
+
external fun ffi_relay_rover_rust_future_free_u16(`handle`: Long,
|
|
749
|
+
): Unit
|
|
750
|
+
external fun ffi_relay_rover_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
751
|
+
): Int
|
|
752
|
+
external fun ffi_relay_rover_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
753
|
+
): Unit
|
|
754
|
+
external fun ffi_relay_rover_rust_future_cancel_i16(`handle`: Long,
|
|
755
|
+
): Unit
|
|
756
|
+
external fun ffi_relay_rover_rust_future_free_i16(`handle`: Long,
|
|
757
|
+
): Unit
|
|
758
|
+
external fun ffi_relay_rover_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
759
|
+
): Short
|
|
760
|
+
external fun ffi_relay_rover_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
761
|
+
): Unit
|
|
762
|
+
external fun ffi_relay_rover_rust_future_cancel_u32(`handle`: Long,
|
|
763
|
+
): Unit
|
|
764
|
+
external fun ffi_relay_rover_rust_future_free_u32(`handle`: Long,
|
|
765
|
+
): Unit
|
|
766
|
+
external fun ffi_relay_rover_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
767
|
+
): Int
|
|
768
|
+
external fun ffi_relay_rover_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
769
|
+
): Unit
|
|
770
|
+
external fun ffi_relay_rover_rust_future_cancel_i32(`handle`: Long,
|
|
771
|
+
): Unit
|
|
772
|
+
external fun ffi_relay_rover_rust_future_free_i32(`handle`: Long,
|
|
773
|
+
): Unit
|
|
774
|
+
external fun ffi_relay_rover_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
775
|
+
): Int
|
|
776
|
+
external fun ffi_relay_rover_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
777
|
+
): Unit
|
|
778
|
+
external fun ffi_relay_rover_rust_future_cancel_u64(`handle`: Long,
|
|
779
|
+
): Unit
|
|
780
|
+
external fun ffi_relay_rover_rust_future_free_u64(`handle`: Long,
|
|
781
|
+
): Unit
|
|
782
|
+
external fun ffi_relay_rover_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
783
|
+
): Long
|
|
784
|
+
external fun ffi_relay_rover_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
785
|
+
): Unit
|
|
786
|
+
external fun ffi_relay_rover_rust_future_cancel_i64(`handle`: Long,
|
|
787
|
+
): Unit
|
|
788
|
+
external fun ffi_relay_rover_rust_future_free_i64(`handle`: Long,
|
|
789
|
+
): Unit
|
|
790
|
+
external fun ffi_relay_rover_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
791
|
+
): Long
|
|
792
|
+
external fun ffi_relay_rover_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
793
|
+
): Unit
|
|
794
|
+
external fun ffi_relay_rover_rust_future_cancel_f32(`handle`: Long,
|
|
795
|
+
): Unit
|
|
796
|
+
external fun ffi_relay_rover_rust_future_free_f32(`handle`: Long,
|
|
797
|
+
): Unit
|
|
798
|
+
external fun ffi_relay_rover_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
799
|
+
): Float
|
|
800
|
+
external fun ffi_relay_rover_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
801
|
+
): Unit
|
|
802
|
+
external fun ffi_relay_rover_rust_future_cancel_f64(`handle`: Long,
|
|
803
|
+
): Unit
|
|
804
|
+
external fun ffi_relay_rover_rust_future_free_f64(`handle`: Long,
|
|
805
|
+
): Unit
|
|
806
|
+
external fun ffi_relay_rover_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
807
|
+
): Double
|
|
808
|
+
external fun ffi_relay_rover_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
809
|
+
): Unit
|
|
810
|
+
external fun ffi_relay_rover_rust_future_cancel_rust_buffer(`handle`: Long,
|
|
811
|
+
): Unit
|
|
812
|
+
external fun ffi_relay_rover_rust_future_free_rust_buffer(`handle`: Long,
|
|
813
|
+
): Unit
|
|
814
|
+
external fun ffi_relay_rover_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
815
|
+
): RustBuffer.ByValue
|
|
816
|
+
external fun ffi_relay_rover_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
|
|
817
|
+
): Unit
|
|
818
|
+
external fun ffi_relay_rover_rust_future_cancel_void(`handle`: Long,
|
|
819
|
+
): Unit
|
|
820
|
+
external fun ffi_relay_rover_rust_future_free_void(`handle`: Long,
|
|
821
|
+
): Unit
|
|
822
|
+
external fun ffi_relay_rover_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
|
|
823
|
+
): Unit
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
|
|
829
|
+
// Get the bindings contract version from our ComponentInterface
|
|
830
|
+
val bindings_contract_version = 30
|
|
831
|
+
// Get the scaffolding contract version by calling the into the dylib
|
|
832
|
+
val scaffolding_contract_version = lib.ffi_relay_rover_uniffi_contract_version()
|
|
833
|
+
if (bindings_contract_version != scaffolding_contract_version) {
|
|
834
|
+
throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
@Suppress("UNUSED_PARAMETER")
|
|
838
|
+
private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
|
|
839
|
+
if ((lib.uniffi_relay_rover_checksum_func_classify() and 0xFFFF) != 931) {
|
|
840
|
+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
841
|
+
}
|
|
842
|
+
if ((lib.uniffi_relay_rover_checksum_func_clean_email_body() and 0xFFFF) != 34770) {
|
|
843
|
+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
844
|
+
}
|
|
845
|
+
if ((lib.uniffi_relay_rover_checksum_func_generate_preview() and 0xFFFF) != 60606) {
|
|
846
|
+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
847
|
+
}
|
|
848
|
+
if ((lib.uniffi_relay_rover_checksum_func_html_to_text() and 0xFFFF) != 37499) {
|
|
849
|
+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
850
|
+
}
|
|
851
|
+
if ((lib.uniffi_relay_rover_checksum_func_process_batch_json() and 0xFFFF) != 18304) {
|
|
852
|
+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
853
|
+
}
|
|
854
|
+
if ((lib.uniffi_relay_rover_checksum_func_process_email() and 0xFFFF) != 19912) {
|
|
855
|
+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
856
|
+
}
|
|
857
|
+
if ((lib.uniffi_relay_rover_checksum_func_process_email_json() and 0xFFFF) != 44892) {
|
|
858
|
+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* @suppress
|
|
864
|
+
*/
|
|
865
|
+
public fun uniffiEnsureInitialized() {
|
|
866
|
+
// Call arbitrary methods on IntegrityCheckingUniffiLib and UniffiLib to ensure that
|
|
867
|
+
// their init blocks run. This ensures initialization across crates works as expected.
|
|
868
|
+
IntegrityCheckingUniffiLib.ensureInitialized()
|
|
869
|
+
UniffiLib.ensureInitialized()
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// Async support
|
|
873
|
+
|
|
874
|
+
// Public interface members begin here.
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
// Interface implemented by anything that can contain an object reference.
|
|
878
|
+
//
|
|
879
|
+
// Such types expose a `destroy()` method that must be called to cleanly
|
|
880
|
+
// dispose of the contained objects. Failure to call this method may result
|
|
881
|
+
// in memory leaks.
|
|
882
|
+
//
|
|
883
|
+
// The easiest way to ensure this method is called is to use the `.use`
|
|
884
|
+
// helper method to execute a block and destroy the object at the end.
|
|
885
|
+
interface Disposable {
|
|
886
|
+
fun destroy()
|
|
887
|
+
companion object {
|
|
888
|
+
fun destroy(vararg args: Any?) {
|
|
889
|
+
for (arg in args) {
|
|
890
|
+
when (arg) {
|
|
891
|
+
is Disposable -> arg.destroy()
|
|
892
|
+
is ArrayList<*> -> {
|
|
893
|
+
for (idx in arg.indices) {
|
|
894
|
+
val element = arg[idx]
|
|
895
|
+
if (element is Disposable) {
|
|
896
|
+
element.destroy()
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
is Map<*, *> -> {
|
|
901
|
+
for (element in arg.values) {
|
|
902
|
+
if (element is Disposable) {
|
|
903
|
+
element.destroy()
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
is Iterable<*> -> {
|
|
908
|
+
for (element in arg) {
|
|
909
|
+
if (element is Disposable) {
|
|
910
|
+
element.destroy()
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* @suppress
|
|
922
|
+
*/
|
|
923
|
+
inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
|
|
924
|
+
try {
|
|
925
|
+
block(this)
|
|
926
|
+
} finally {
|
|
927
|
+
try {
|
|
928
|
+
// N.B. our implementation is on the nullable type `Disposable?`.
|
|
929
|
+
this?.destroy()
|
|
930
|
+
} catch (e: Throwable) {
|
|
931
|
+
// swallow
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* Placeholder object used to signal that we're constructing an interface with a FFI handle.
|
|
937
|
+
*
|
|
938
|
+
* This is the first argument for interface constructors that input a raw handle. It exists is that
|
|
939
|
+
* so we can avoid signature conflicts when an interface has a regular constructor than inputs a
|
|
940
|
+
* Long.
|
|
941
|
+
*
|
|
942
|
+
* @suppress
|
|
943
|
+
* */
|
|
944
|
+
object UniffiWithHandle
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
|
|
948
|
+
*
|
|
949
|
+
* @suppress
|
|
950
|
+
* */
|
|
951
|
+
object NoHandle
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* @suppress
|
|
955
|
+
*/
|
|
956
|
+
public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
|
|
957
|
+
// Note: we don't inherit from FfiConverterRustBuffer, because we use a
|
|
958
|
+
// special encoding when lowering/lifting. We can use `RustBuffer.len` to
|
|
959
|
+
// store our length and avoid writing it out to the buffer.
|
|
960
|
+
override fun lift(value: RustBuffer.ByValue): String {
|
|
961
|
+
try {
|
|
962
|
+
val byteArr = ByteArray(value.len.toInt())
|
|
963
|
+
value.asByteBuffer()!!.get(byteArr)
|
|
964
|
+
return byteArr.toString(Charsets.UTF_8)
|
|
965
|
+
} finally {
|
|
966
|
+
RustBuffer.free(value)
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
override fun read(buf: ByteBuffer): String {
|
|
971
|
+
val len = buf.getInt()
|
|
972
|
+
val byteArr = ByteArray(len)
|
|
973
|
+
buf.get(byteArr)
|
|
974
|
+
return byteArr.toString(Charsets.UTF_8)
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
fun toUtf8(value: String): ByteBuffer {
|
|
978
|
+
// Make sure we don't have invalid UTF-16, check for lone surrogates.
|
|
979
|
+
return Charsets.UTF_8.newEncoder().run {
|
|
980
|
+
onMalformedInput(CodingErrorAction.REPORT)
|
|
981
|
+
encode(CharBuffer.wrap(value))
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
override fun lower(value: String): RustBuffer.ByValue {
|
|
986
|
+
val byteBuf = toUtf8(value)
|
|
987
|
+
// Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
|
|
988
|
+
// to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
|
|
989
|
+
val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
|
|
990
|
+
rbuf.asByteBuffer()!!.put(byteBuf)
|
|
991
|
+
return rbuf
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// We aren't sure exactly how many bytes our string will be once it's UTF-8
|
|
995
|
+
// encoded. Allocate 3 bytes per UTF-16 code unit which will always be
|
|
996
|
+
// enough.
|
|
997
|
+
override fun allocationSize(value: String): ULong {
|
|
998
|
+
val sizeForLength = 4UL
|
|
999
|
+
val sizeForString = value.length.toULong() * 3UL
|
|
1000
|
+
return sizeForLength + sizeForString
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
override fun write(value: String, buf: ByteBuffer) {
|
|
1004
|
+
val byteBuf = toUtf8(value)
|
|
1005
|
+
buf.putInt(byteBuf.limit())
|
|
1006
|
+
buf.put(byteBuf)
|
|
1007
|
+
}
|
|
1008
|
+
} fun `classify`(`subject`: kotlin.String, `body`: kotlin.String): kotlin.String {
|
|
1009
|
+
return FfiConverterString.lift(
|
|
1010
|
+
uniffiRustCall() { _status ->
|
|
1011
|
+
UniffiLib.uniffi_relay_rover_fn_func_classify(
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
FfiConverterString.lower(`subject`),
|
|
1015
|
+
FfiConverterString.lower(`body`),_status)
|
|
1016
|
+
}
|
|
1017
|
+
)
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
fun `cleanEmailBody`(`bodyOrHtml`: kotlin.String): kotlin.String {
|
|
1021
|
+
return FfiConverterString.lift(
|
|
1022
|
+
uniffiRustCall() { _status ->
|
|
1023
|
+
UniffiLib.uniffi_relay_rover_fn_func_clean_email_body(
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
FfiConverterString.lower(`bodyOrHtml`),_status)
|
|
1027
|
+
}
|
|
1028
|
+
)
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
fun `generatePreview`(`subject`: kotlin.String, `body`: kotlin.String): kotlin.String {
|
|
1032
|
+
return FfiConverterString.lift(
|
|
1033
|
+
uniffiRustCall() { _status ->
|
|
1034
|
+
UniffiLib.uniffi_relay_rover_fn_func_generate_preview(
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
FfiConverterString.lower(`subject`),
|
|
1038
|
+
FfiConverterString.lower(`body`),_status)
|
|
1039
|
+
}
|
|
1040
|
+
)
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
fun `htmlToText`(`html`: kotlin.String): kotlin.String {
|
|
1044
|
+
return FfiConverterString.lift(
|
|
1045
|
+
uniffiRustCall() { _status ->
|
|
1046
|
+
UniffiLib.uniffi_relay_rover_fn_func_html_to_text(
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
FfiConverterString.lower(`html`),_status)
|
|
1050
|
+
}
|
|
1051
|
+
)
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
fun `processBatchJson`(`batchJson`: kotlin.String): kotlin.String {
|
|
1055
|
+
return FfiConverterString.lift(
|
|
1056
|
+
uniffiRustCall() { _status ->
|
|
1057
|
+
UniffiLib.uniffi_relay_rover_fn_func_process_batch_json(
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
FfiConverterString.lower(`batchJson`),_status)
|
|
1061
|
+
}
|
|
1062
|
+
)
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
fun `processEmail`(`subject`: kotlin.String, `body`: kotlin.String): kotlin.String {
|
|
1066
|
+
return FfiConverterString.lift(
|
|
1067
|
+
uniffiRustCall() { _status ->
|
|
1068
|
+
UniffiLib.uniffi_relay_rover_fn_func_process_email(
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
FfiConverterString.lower(`subject`),
|
|
1072
|
+
FfiConverterString.lower(`body`),_status)
|
|
1073
|
+
}
|
|
1074
|
+
)
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
fun `processEmailJson`(`emailJson`: kotlin.String): kotlin.String {
|
|
1078
|
+
return FfiConverterString.lift(
|
|
1079
|
+
uniffiRustCall() { _status ->
|
|
1080
|
+
UniffiLib.uniffi_relay_rover_fn_func_process_email_json(
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
FfiConverterString.lower(`emailJson`),_status)
|
|
1084
|
+
}
|
|
1085
|
+
)
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|