capacitor-wasm-agent-tools 0.1.0

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