edge-intelligence-sdk 0.3.7

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.
@@ -0,0 +1,2668 @@
1
+ // This file was autogenerated by some hot garbage in the `uniffi-bindgen-react-native` crate.
2
+ // Trust me, you don't want to mess with it!
3
+ #include "el_ffi.hpp"
4
+
5
+ #include "UniffiJsiTypes.h"
6
+ #include <stdexcept>
7
+ #include <map>
8
+ #include <utility>
9
+ #include <iostream>
10
+ #include <thread>
11
+
12
+ namespace react = facebook::react;
13
+ namespace jsi = facebook::jsi;
14
+
15
+ // Calling into Rust.
16
+ extern "C" {
17
+ typedef void
18
+ (*UniffiRustFutureContinuationCallback)(
19
+ uint64_t data,
20
+ int8_t poll_result
21
+ );
22
+ typedef void
23
+ (*UniffiForeignFutureDroppedCallback)(
24
+ uint64_t handle
25
+ );
26
+ typedef void
27
+ (*UniffiCallbackInterfaceFree)(
28
+ uint64_t handle
29
+ );
30
+ typedef uint64_t
31
+ (*UniffiCallbackInterfaceClone)(
32
+ uint64_t handle
33
+ );typedef struct UniffiForeignFutureDroppedCallbackStruct {
34
+ uint64_t handle;
35
+ UniffiForeignFutureDroppedCallback free;
36
+ } UniffiForeignFutureDroppedCallbackStruct;typedef struct UniffiForeignFutureResultU8 {
37
+ uint8_t return_value;
38
+ RustCallStatus call_status;
39
+ } UniffiForeignFutureResultU8;
40
+ typedef void
41
+ (*UniffiForeignFutureCompleteU8)(
42
+ uint64_t callback_data,
43
+ UniffiForeignFutureResultU8 result
44
+ );typedef struct UniffiForeignFutureResultI8 {
45
+ int8_t return_value;
46
+ RustCallStatus call_status;
47
+ } UniffiForeignFutureResultI8;
48
+ typedef void
49
+ (*UniffiForeignFutureCompleteI8)(
50
+ uint64_t callback_data,
51
+ UniffiForeignFutureResultI8 result
52
+ );typedef struct UniffiForeignFutureResultU16 {
53
+ uint16_t return_value;
54
+ RustCallStatus call_status;
55
+ } UniffiForeignFutureResultU16;
56
+ typedef void
57
+ (*UniffiForeignFutureCompleteU16)(
58
+ uint64_t callback_data,
59
+ UniffiForeignFutureResultU16 result
60
+ );typedef struct UniffiForeignFutureResultI16 {
61
+ int16_t return_value;
62
+ RustCallStatus call_status;
63
+ } UniffiForeignFutureResultI16;
64
+ typedef void
65
+ (*UniffiForeignFutureCompleteI16)(
66
+ uint64_t callback_data,
67
+ UniffiForeignFutureResultI16 result
68
+ );typedef struct UniffiForeignFutureResultU32 {
69
+ uint32_t return_value;
70
+ RustCallStatus call_status;
71
+ } UniffiForeignFutureResultU32;
72
+ typedef void
73
+ (*UniffiForeignFutureCompleteU32)(
74
+ uint64_t callback_data,
75
+ UniffiForeignFutureResultU32 result
76
+ );typedef struct UniffiForeignFutureResultI32 {
77
+ int32_t return_value;
78
+ RustCallStatus call_status;
79
+ } UniffiForeignFutureResultI32;
80
+ typedef void
81
+ (*UniffiForeignFutureCompleteI32)(
82
+ uint64_t callback_data,
83
+ UniffiForeignFutureResultI32 result
84
+ );typedef struct UniffiForeignFutureResultU64 {
85
+ uint64_t return_value;
86
+ RustCallStatus call_status;
87
+ } UniffiForeignFutureResultU64;
88
+ typedef void
89
+ (*UniffiForeignFutureCompleteU64)(
90
+ uint64_t callback_data,
91
+ UniffiForeignFutureResultU64 result
92
+ );typedef struct UniffiForeignFutureResultI64 {
93
+ int64_t return_value;
94
+ RustCallStatus call_status;
95
+ } UniffiForeignFutureResultI64;
96
+ typedef void
97
+ (*UniffiForeignFutureCompleteI64)(
98
+ uint64_t callback_data,
99
+ UniffiForeignFutureResultI64 result
100
+ );typedef struct UniffiForeignFutureResultF32 {
101
+ float return_value;
102
+ RustCallStatus call_status;
103
+ } UniffiForeignFutureResultF32;
104
+ typedef void
105
+ (*UniffiForeignFutureCompleteF32)(
106
+ uint64_t callback_data,
107
+ UniffiForeignFutureResultF32 result
108
+ );typedef struct UniffiForeignFutureResultF64 {
109
+ double return_value;
110
+ RustCallStatus call_status;
111
+ } UniffiForeignFutureResultF64;
112
+ typedef void
113
+ (*UniffiForeignFutureCompleteF64)(
114
+ uint64_t callback_data,
115
+ UniffiForeignFutureResultF64 result
116
+ );typedef struct UniffiForeignFutureResultRustBuffer {
117
+ RustBuffer return_value;
118
+ RustCallStatus call_status;
119
+ } UniffiForeignFutureResultRustBuffer;
120
+ typedef void
121
+ (*UniffiForeignFutureCompleteRustBuffer)(
122
+ uint64_t callback_data,
123
+ UniffiForeignFutureResultRustBuffer result
124
+ );typedef struct UniffiForeignFutureResultVoid {
125
+ RustCallStatus call_status;
126
+ } UniffiForeignFutureResultVoid;
127
+ typedef void
128
+ (*UniffiForeignFutureCompleteVoid)(
129
+ uint64_t callback_data,
130
+ UniffiForeignFutureResultVoid result
131
+ );
132
+ typedef void
133
+ (*UniffiCallbackInterfaceStreamHandlerMethod0)(
134
+ uint64_t uniffi_handle,
135
+ RustBuffer token,
136
+ void * uniffi_out_return, RustCallStatus* rust_call_status
137
+ );typedef struct UniffiVTableCallbackInterfaceStreamHandler {
138
+ UniffiCallbackInterfaceFree uniffi_free;
139
+ UniffiCallbackInterfaceClone uniffi_clone;
140
+ UniffiCallbackInterfaceStreamHandlerMethod0 on_token;
141
+ } UniffiVTableCallbackInterfaceStreamHandler;
142
+ /*handle*/ uint64_t uniffi_el_ffi_fn_clone_edgellm(
143
+ /*handle*/ uint64_t handle,
144
+ RustCallStatus *uniffi_out_err
145
+ );
146
+ void uniffi_el_ffi_fn_free_edgellm(
147
+ /*handle*/ uint64_t handle,
148
+ RustCallStatus *uniffi_out_err
149
+ );
150
+ /*handle*/ uint64_t uniffi_el_ffi_fn_constructor_edgellm_cloud(
151
+ RustBuffer model,
152
+ RustBuffer api_key,
153
+ RustCallStatus *uniffi_out_err
154
+ );
155
+ /*handle*/ uint64_t uniffi_el_ffi_fn_constructor_edgellm_local(
156
+ RustBuffer model_uri,
157
+ RustCallStatus *uniffi_out_err
158
+ );
159
+ RustBuffer uniffi_el_ffi_fn_method_edgellm_ask(
160
+ /*handle*/ uint64_t ptr,
161
+ RustBuffer prompt,
162
+ RustCallStatus *uniffi_out_err
163
+ );
164
+ void uniffi_el_ffi_fn_method_edgellm_ask_stream_cb(
165
+ /*handle*/ uint64_t ptr,
166
+ RustBuffer prompt,
167
+ uint64_t handler,
168
+ RustCallStatus *uniffi_out_err
169
+ );
170
+ void uniffi_el_ffi_fn_method_edgellm_reset(
171
+ /*handle*/ uint64_t ptr,
172
+ RustCallStatus *uniffi_out_err
173
+ );
174
+ void uniffi_el_ffi_fn_init_callback_vtable_streamhandler(
175
+ UniffiVTableCallbackInterfaceStreamHandler * vtable
176
+ );
177
+ RustBuffer ffi_el_ffi_rustbuffer_alloc(
178
+ uint64_t size,
179
+ RustCallStatus *uniffi_out_err
180
+ );
181
+ RustBuffer ffi_el_ffi_rustbuffer_from_bytes(
182
+ ForeignBytes bytes,
183
+ RustCallStatus *uniffi_out_err
184
+ );
185
+ void ffi_el_ffi_rustbuffer_free(
186
+ RustBuffer buf,
187
+ RustCallStatus *uniffi_out_err
188
+ );
189
+ RustBuffer ffi_el_ffi_rustbuffer_reserve(
190
+ RustBuffer buf,
191
+ uint64_t additional,
192
+ RustCallStatus *uniffi_out_err
193
+ );
194
+ void ffi_el_ffi_rust_future_poll_u8(
195
+ /*handle*/ uint64_t handle,
196
+ UniffiRustFutureContinuationCallback callback,
197
+ /*handle*/ uint64_t callback_data
198
+ );
199
+ void ffi_el_ffi_rust_future_cancel_u8(
200
+ /*handle*/ uint64_t handle
201
+ );
202
+ void ffi_el_ffi_rust_future_free_u8(
203
+ /*handle*/ uint64_t handle
204
+ );
205
+ uint8_t ffi_el_ffi_rust_future_complete_u8(
206
+ /*handle*/ uint64_t handle,
207
+ RustCallStatus *uniffi_out_err
208
+ );
209
+ void ffi_el_ffi_rust_future_poll_i8(
210
+ /*handle*/ uint64_t handle,
211
+ UniffiRustFutureContinuationCallback callback,
212
+ /*handle*/ uint64_t callback_data
213
+ );
214
+ void ffi_el_ffi_rust_future_cancel_i8(
215
+ /*handle*/ uint64_t handle
216
+ );
217
+ void ffi_el_ffi_rust_future_free_i8(
218
+ /*handle*/ uint64_t handle
219
+ );
220
+ int8_t ffi_el_ffi_rust_future_complete_i8(
221
+ /*handle*/ uint64_t handle,
222
+ RustCallStatus *uniffi_out_err
223
+ );
224
+ void ffi_el_ffi_rust_future_poll_u16(
225
+ /*handle*/ uint64_t handle,
226
+ UniffiRustFutureContinuationCallback callback,
227
+ /*handle*/ uint64_t callback_data
228
+ );
229
+ void ffi_el_ffi_rust_future_cancel_u16(
230
+ /*handle*/ uint64_t handle
231
+ );
232
+ void ffi_el_ffi_rust_future_free_u16(
233
+ /*handle*/ uint64_t handle
234
+ );
235
+ uint16_t ffi_el_ffi_rust_future_complete_u16(
236
+ /*handle*/ uint64_t handle,
237
+ RustCallStatus *uniffi_out_err
238
+ );
239
+ void ffi_el_ffi_rust_future_poll_i16(
240
+ /*handle*/ uint64_t handle,
241
+ UniffiRustFutureContinuationCallback callback,
242
+ /*handle*/ uint64_t callback_data
243
+ );
244
+ void ffi_el_ffi_rust_future_cancel_i16(
245
+ /*handle*/ uint64_t handle
246
+ );
247
+ void ffi_el_ffi_rust_future_free_i16(
248
+ /*handle*/ uint64_t handle
249
+ );
250
+ int16_t ffi_el_ffi_rust_future_complete_i16(
251
+ /*handle*/ uint64_t handle,
252
+ RustCallStatus *uniffi_out_err
253
+ );
254
+ void ffi_el_ffi_rust_future_poll_u32(
255
+ /*handle*/ uint64_t handle,
256
+ UniffiRustFutureContinuationCallback callback,
257
+ /*handle*/ uint64_t callback_data
258
+ );
259
+ void ffi_el_ffi_rust_future_cancel_u32(
260
+ /*handle*/ uint64_t handle
261
+ );
262
+ void ffi_el_ffi_rust_future_free_u32(
263
+ /*handle*/ uint64_t handle
264
+ );
265
+ uint32_t ffi_el_ffi_rust_future_complete_u32(
266
+ /*handle*/ uint64_t handle,
267
+ RustCallStatus *uniffi_out_err
268
+ );
269
+ void ffi_el_ffi_rust_future_poll_i32(
270
+ /*handle*/ uint64_t handle,
271
+ UniffiRustFutureContinuationCallback callback,
272
+ /*handle*/ uint64_t callback_data
273
+ );
274
+ void ffi_el_ffi_rust_future_cancel_i32(
275
+ /*handle*/ uint64_t handle
276
+ );
277
+ void ffi_el_ffi_rust_future_free_i32(
278
+ /*handle*/ uint64_t handle
279
+ );
280
+ int32_t ffi_el_ffi_rust_future_complete_i32(
281
+ /*handle*/ uint64_t handle,
282
+ RustCallStatus *uniffi_out_err
283
+ );
284
+ void ffi_el_ffi_rust_future_poll_u64(
285
+ /*handle*/ uint64_t handle,
286
+ UniffiRustFutureContinuationCallback callback,
287
+ /*handle*/ uint64_t callback_data
288
+ );
289
+ void ffi_el_ffi_rust_future_cancel_u64(
290
+ /*handle*/ uint64_t handle
291
+ );
292
+ void ffi_el_ffi_rust_future_free_u64(
293
+ /*handle*/ uint64_t handle
294
+ );
295
+ uint64_t ffi_el_ffi_rust_future_complete_u64(
296
+ /*handle*/ uint64_t handle,
297
+ RustCallStatus *uniffi_out_err
298
+ );
299
+ void ffi_el_ffi_rust_future_poll_i64(
300
+ /*handle*/ uint64_t handle,
301
+ UniffiRustFutureContinuationCallback callback,
302
+ /*handle*/ uint64_t callback_data
303
+ );
304
+ void ffi_el_ffi_rust_future_cancel_i64(
305
+ /*handle*/ uint64_t handle
306
+ );
307
+ void ffi_el_ffi_rust_future_free_i64(
308
+ /*handle*/ uint64_t handle
309
+ );
310
+ int64_t ffi_el_ffi_rust_future_complete_i64(
311
+ /*handle*/ uint64_t handle,
312
+ RustCallStatus *uniffi_out_err
313
+ );
314
+ void ffi_el_ffi_rust_future_poll_f32(
315
+ /*handle*/ uint64_t handle,
316
+ UniffiRustFutureContinuationCallback callback,
317
+ /*handle*/ uint64_t callback_data
318
+ );
319
+ void ffi_el_ffi_rust_future_cancel_f32(
320
+ /*handle*/ uint64_t handle
321
+ );
322
+ void ffi_el_ffi_rust_future_free_f32(
323
+ /*handle*/ uint64_t handle
324
+ );
325
+ float ffi_el_ffi_rust_future_complete_f32(
326
+ /*handle*/ uint64_t handle,
327
+ RustCallStatus *uniffi_out_err
328
+ );
329
+ void ffi_el_ffi_rust_future_poll_f64(
330
+ /*handle*/ uint64_t handle,
331
+ UniffiRustFutureContinuationCallback callback,
332
+ /*handle*/ uint64_t callback_data
333
+ );
334
+ void ffi_el_ffi_rust_future_cancel_f64(
335
+ /*handle*/ uint64_t handle
336
+ );
337
+ void ffi_el_ffi_rust_future_free_f64(
338
+ /*handle*/ uint64_t handle
339
+ );
340
+ double ffi_el_ffi_rust_future_complete_f64(
341
+ /*handle*/ uint64_t handle,
342
+ RustCallStatus *uniffi_out_err
343
+ );
344
+ void ffi_el_ffi_rust_future_poll_rust_buffer(
345
+ /*handle*/ uint64_t handle,
346
+ UniffiRustFutureContinuationCallback callback,
347
+ /*handle*/ uint64_t callback_data
348
+ );
349
+ void ffi_el_ffi_rust_future_cancel_rust_buffer(
350
+ /*handle*/ uint64_t handle
351
+ );
352
+ void ffi_el_ffi_rust_future_free_rust_buffer(
353
+ /*handle*/ uint64_t handle
354
+ );
355
+ RustBuffer ffi_el_ffi_rust_future_complete_rust_buffer(
356
+ /*handle*/ uint64_t handle,
357
+ RustCallStatus *uniffi_out_err
358
+ );
359
+ void ffi_el_ffi_rust_future_poll_void(
360
+ /*handle*/ uint64_t handle,
361
+ UniffiRustFutureContinuationCallback callback,
362
+ /*handle*/ uint64_t callback_data
363
+ );
364
+ void ffi_el_ffi_rust_future_cancel_void(
365
+ /*handle*/ uint64_t handle
366
+ );
367
+ void ffi_el_ffi_rust_future_free_void(
368
+ /*handle*/ uint64_t handle
369
+ );
370
+ void ffi_el_ffi_rust_future_complete_void(
371
+ /*handle*/ uint64_t handle,
372
+ RustCallStatus *uniffi_out_err
373
+ );
374
+ uint16_t uniffi_el_ffi_checksum_method_edgellm_ask(
375
+ );
376
+ uint16_t uniffi_el_ffi_checksum_method_edgellm_ask_stream_cb(
377
+ );
378
+ uint16_t uniffi_el_ffi_checksum_method_edgellm_reset(
379
+ );
380
+ uint16_t uniffi_el_ffi_checksum_constructor_edgellm_cloud(
381
+ );
382
+ uint16_t uniffi_el_ffi_checksum_constructor_edgellm_local(
383
+ );
384
+ uint16_t uniffi_el_ffi_checksum_method_streamhandler_on_token(
385
+ );
386
+ uint32_t ffi_el_ffi_uniffi_contract_version(
387
+ );
388
+ }
389
+
390
+
391
+ namespace uniffi::el_ffi {
392
+ template <typename T> struct Bridging;
393
+
394
+ using namespace facebook;
395
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
396
+
397
+ template <typename T> struct Bridging<ReferenceHolder<T>> {
398
+ static jsi::Value jsNew(jsi::Runtime &rt) {
399
+ auto holder = jsi::Object(rt);
400
+ return holder;
401
+ }
402
+ static T fromJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker,
403
+ const jsi::Value &value) {
404
+ auto obj = value.asObject(rt);
405
+ if (obj.hasProperty(rt, "pointee")) {
406
+ auto pointee = obj.getProperty(rt, "pointee");
407
+ return uniffi::el_ffi::Bridging<T>::fromJs(rt, callInvoker, pointee);
408
+ }
409
+ throw jsi::JSError(
410
+ rt,
411
+ "Expected ReferenceHolder to have a pointee property. This is likely a bug in uniffi-bindgen-react-native"
412
+ );
413
+ }
414
+ };
415
+ } // namespace uniffi::el_ffi
416
+ namespace uniffi::el_ffi {
417
+ using namespace facebook;
418
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
419
+
420
+ template <> struct Bridging<RustBuffer> {
421
+ static RustBuffer rustbuffer_alloc(int32_t size) {
422
+ RustCallStatus status = { UNIFFI_CALL_STATUS_OK };
423
+ return ffi_el_ffi_rustbuffer_alloc(
424
+ size,
425
+ &status
426
+ );
427
+ }
428
+
429
+ static void rustbuffer_free(RustBuffer buf) {
430
+ RustCallStatus status = { UNIFFI_CALL_STATUS_OK };
431
+ ffi_el_ffi_rustbuffer_free(
432
+ buf,
433
+ &status
434
+ );
435
+ }
436
+
437
+ static RustBuffer rustbuffer_from_bytes(ForeignBytes bytes) {
438
+ RustCallStatus status = { UNIFFI_CALL_STATUS_OK };
439
+ return ffi_el_ffi_rustbuffer_from_bytes(
440
+ bytes,
441
+ &status
442
+ );
443
+ }
444
+
445
+ static RustBuffer fromJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker>,
446
+ const jsi::Value &value) {
447
+ try {
448
+ auto buffer = uniffi_jsi::Bridging<jsi::ArrayBuffer>::value_to_arraybuffer(rt, value);
449
+ auto bytes = ForeignBytes{
450
+ .len = static_cast<int32_t>(buffer.length(rt)),
451
+ .data = buffer.data(rt),
452
+ };
453
+
454
+ // This buffer is constructed from foreign bytes. Rust scaffolding copies
455
+ // the bytes, to make the RustBuffer.
456
+ auto buf = rustbuffer_from_bytes(bytes);
457
+ // Once it leaves this function, the buffer is immediately passed back
458
+ // into Rust, where it's used to deserialize into the Rust versions of the
459
+ // arguments. At that point, the copy is destroyed.
460
+ return buf;
461
+ } catch (const std::logic_error &e) {
462
+ throw jsi::JSError(rt, e.what());
463
+ }
464
+ }
465
+
466
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker>,
467
+ RustBuffer buf) {
468
+ // View-handoff: hand JS a `Uint8Array` view aliasing the Rust-owned bytes
469
+ // (no boundary copy). The single mandatory copy now happens inside
470
+ // `converter.lift(view)` (string decode, byte-array `set`, field-by-field
471
+ // record reads). The codegen-emitted try/finally calls `rustbuffer_free`
472
+ // on the view after `lift` returns, releasing the Rust allocation.
473
+ //
474
+ // Capacity hint: Rust may return a buffer where `capacity > len`. The
475
+ // view's `byteLength` is `len` (so converters that decode the whole view
476
+ // see only the message bytes), but `rustbuffer_free` needs `capacity` to
477
+ // free correctly. We stash `capacity` on the view via a string-keyed
478
+ // property when it differs from `len`; the JSI `rustbufferFree` host
479
+ // function reads it back and falls back to `byteLength` for views from
480
+ // `rustbufferAlloc(n)` where `byteLength == capacity` already.
481
+ //
482
+ // CMutableBuffer is non-owning here: its destructor leaves `buf.data`
483
+ // alone. Only the codegen-emitted `rustbuffer_free` path frees it.
484
+ auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(
485
+ buf.data, static_cast<size_t>(buf.len));
486
+ auto view = uniffi_jsi::arraybufferToUint8Array(
487
+ rt, jsi::ArrayBuffer(rt, payload));
488
+ if (buf.capacity != static_cast<uint64_t>(buf.len)) {
489
+ view.setProperty(rt, uniffi_jsi::kUbrnRustCapacity,
490
+ jsi::Value(static_cast<double>(buf.capacity)));
491
+ }
492
+ return jsi::Value(rt, view);
493
+ }
494
+ };
495
+
496
+ } // namespace uniffi::el_ffi
497
+
498
+ namespace uniffi::el_ffi {
499
+ using namespace facebook;
500
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
501
+
502
+ template <> struct Bridging<RustCallStatus> {
503
+ static jsi::Value jsSuccess(jsi::Runtime &rt) {
504
+ auto statusObject = jsi::Object(rt);
505
+ statusObject.setProperty(rt, "code", jsi::Value(rt, UNIFFI_CALL_STATUS_OK));
506
+ return statusObject;
507
+ }
508
+ static RustCallStatus rustSuccess(jsi::Runtime &rt) {
509
+ return {UNIFFI_CALL_STATUS_OK};
510
+ }
511
+ static void copyIntoJs(jsi::Runtime &rt,
512
+ std::shared_ptr<CallInvoker> callInvoker,
513
+ const RustCallStatus status,
514
+ const jsi::Value &jsStatus) {
515
+ auto statusObject = jsStatus.asObject(rt);
516
+ if (status.error_buf.data != nullptr) {
517
+ // The error path is NOT wrapped in the codegen-emitted try/finally that
518
+ // covers normal returns: `errorBuf` is read by the runtime's call-status
519
+ // dispatcher (rust-call.ts) which throws straight to the user without
520
+ // ever calling `rustbuffer_free`. Switching this site to view-handoff
521
+ // would leak the Rust allocation, so we keep the copy semantics here:
522
+ // copy the bytes into a JS-owned ArrayBuffer and free the Rust buffer
523
+ // immediately. The errorBuf is small (a serialized error variant) and
524
+ // only allocated on the cold error path, so the boundary copy is cheap.
525
+ auto len = static_cast<size_t>(status.error_buf.len);
526
+ uint8_t *bytes = new uint8_t[len];
527
+ std::memcpy(bytes, status.error_buf.data, len);
528
+ auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(bytes, len);
529
+ auto view = uniffi_jsi::arraybufferToUint8Array(
530
+ rt, jsi::ArrayBuffer(rt, payload));
531
+ statusObject.setProperty(rt, "errorBuf", view);
532
+ Bridging<RustBuffer>::rustbuffer_free(status.error_buf);
533
+ }
534
+ if (status.code != UNIFFI_CALL_STATUS_OK) {
535
+ auto code =
536
+ uniffi_jsi::Bridging<uint8_t>::toJs(rt, callInvoker, status.code);
537
+ statusObject.setProperty(rt, "code", code);
538
+ }
539
+ }
540
+
541
+ static RustCallStatus fromJs(jsi::Runtime &rt,
542
+ std::shared_ptr<CallInvoker> invoker,
543
+ const jsi::Value &jsStatus) {
544
+ RustCallStatus status;
545
+ auto statusObject = jsStatus.asObject(rt);
546
+ if (statusObject.hasProperty(rt, "errorBuf")) {
547
+ auto rbuf = statusObject.getProperty(rt, "errorBuf");
548
+ status.error_buf =
549
+ Bridging<RustBuffer>::fromJs(rt, invoker, rbuf);
550
+ }
551
+ if (statusObject.hasProperty(rt, "code")) {
552
+ auto code = statusObject.getProperty(rt, "code");
553
+ status.code = uniffi_jsi::Bridging<uint8_t>::fromJs(rt, invoker, code);
554
+ }
555
+ return status;
556
+ }
557
+
558
+ static void copyFromJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> invoker,
559
+ const jsi::Value &jsStatus, RustCallStatus *status) {
560
+ auto statusObject = jsStatus.asObject(rt);
561
+ if (statusObject.hasProperty(rt, "errorBuf")) {
562
+ auto rbuf = statusObject.getProperty(rt, "errorBuf");
563
+ status->error_buf =
564
+ Bridging<RustBuffer>::fromJs(rt, invoker, rbuf);
565
+ }
566
+ if (statusObject.hasProperty(rt, "code")) {
567
+ auto code = statusObject.getProperty(rt, "code");
568
+ status->code = uniffi_jsi::Bridging<uint8_t>::fromJs(rt, invoker, code);
569
+ }
570
+ }
571
+ };
572
+
573
+ } // namespace uniffi::el_ffi
574
+ // In other uniffi bindings, it is assumed that the foreign language holds on
575
+ // to the vtable, which the Rust just gets a pointer to.
576
+ // Here, we need to hold on to them, but also be able to clear them at just the
577
+ // right time so we can support hot-reloading.
578
+ namespace uniffi::el_ffi::registry {
579
+ template <typename T>
580
+ class VTableHolder {
581
+ public:
582
+ T vtable;
583
+ VTableHolder(T v) : vtable(v) {}
584
+ };
585
+
586
+ // Mutex to bind the storage and setting of vtable together.
587
+ // We declare it here, but the lock is taken by callers of the putTable
588
+ // method who are also sending a pointer to Rust.
589
+ static std::mutex vtableMutex;
590
+
591
+ // Registry to hold all vtables so they persist even when JS objects are GC'd.
592
+ // The only reason this exists is to prevent a dangling pointer in the
593
+ // Rust machinery: i.e. we don't need to access or write to this registry
594
+ // after startup.
595
+ // Registry to hold all vtables so they persist even when JS objects are GC'd.
596
+ // Maps string identifiers to vtable holders using type erasure
597
+ static std::unordered_map<std::string, std::shared_ptr<void>> vtableRegistry;
598
+
599
+ // Add a vtable to the registry with an identifier
600
+ template <typename T>
601
+ static T* putTable(std::string_view identifier, T vtable) {
602
+ auto holder = std::make_shared<VTableHolder<T>>(vtable);
603
+ // Store the raw pointer to the vtable before type erasure
604
+ T* rawPtr = &(holder->vtable);
605
+ // Store the holder using type erasure with the string identifier
606
+ vtableRegistry[std::string(identifier)] = std::shared_ptr<void>(holder);
607
+ return rawPtr;
608
+ }
609
+
610
+ // Clear the registry.
611
+ //
612
+ // Conceptually, this is called after teardown of the module (i.e. after
613
+ // teardown of the jsi::Runtime). However, because Rust is dropping callbacks
614
+ // because the Runtime is being torn down, we must keep the registry intact
615
+ // until after the runtime goes away.
616
+ //
617
+ // Therefore, in practice we should call this when the next runtime is
618
+ // being stood up.
619
+ static void clearRegistry() {
620
+ std::lock_guard<std::mutex> lock(vtableMutex);
621
+ vtableRegistry.clear();
622
+ }
623
+ } // namespace uniffi::el_ffi::registry
624
+
625
+ // This calls into Rust.
626
+ // Implementation of callback function calling from Rust to JS RustFutureContinuationCallback
627
+
628
+ // Callback function: uniffi::el_ffi::cb::rustfuturecontinuationcallback::UniffiRustFutureContinuationCallback
629
+ //
630
+ // We have the following constraints:
631
+ // - we need to pass a function pointer to Rust.
632
+ // - we need a jsi::Runtime and jsi::Function to call into JS.
633
+ // - function pointers can't store state, so we can't use a lamda.
634
+ //
635
+ // For this, we store a lambda as a global, as `rsLambda`. The `callback` function calls
636
+ // the lambda, which itself calls the `body` which then calls into JS.
637
+ //
638
+ // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
639
+ // future.
640
+ namespace uniffi::el_ffi::cb::rustfuturecontinuationcallback {
641
+ using namespace facebook;
642
+
643
+ // We need to store a lambda in a global so we can call it from
644
+ // a function pointer. The function pointer is passed to Rust.
645
+ static std::function<void(uint64_t, int8_t)> rsLambda = nullptr;
646
+
647
+ // This is the main body of the callback. It's called from the lambda,
648
+ // which itself is called from the callback function which is passed to Rust.
649
+ static void body(jsi::Runtime &rt,
650
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
651
+ std::shared_ptr<jsi::Value> callbackValue
652
+ ,uint64_t rs_data
653
+ ,int8_t rs_pollResult) {
654
+
655
+ // Convert the arguments from Rust, into jsi::Values.
656
+ // We'll use the Bridging class to do this…
657
+ auto js_data = uniffi_jsi::Bridging<uint64_t>::toJs(rt, callInvoker, rs_data);
658
+ auto js_pollResult = uniffi_jsi::Bridging<int8_t>::toJs(rt, callInvoker, rs_pollResult);
659
+
660
+ // Now we are ready to call the callback.
661
+ // We are already on the JS thread, because this `body` function was
662
+ // invoked from the CallInvoker.
663
+ try {
664
+ // Getting the callback function
665
+ auto cb = callbackValue->asObject(rt).asFunction(rt);
666
+ auto uniffiResult = cb.call(rt, js_data, js_pollResult
667
+ );
668
+
669
+
670
+
671
+
672
+ } catch (const jsi::JSError &error) {
673
+ std::cout << "Error in callback UniffiRustFutureContinuationCallback: "
674
+ << error.what() << std::endl;
675
+ throw error;
676
+ }
677
+ }
678
+
679
+ static void callback(uint64_t rs_data, int8_t rs_pollResult) {
680
+ // If the runtime has shutdown, then there is no point in trying to
681
+ // call into Javascript. BUT how do we tell if the runtime has shutdown?
682
+ //
683
+ // Answer: the module destructor calls into callback `cleanup` method,
684
+ // which nulls out the rsLamda.
685
+ //
686
+ // If rsLamda is null, then there is no runtime to call into.
687
+ if (rsLambda == nullptr) {
688
+ // This only occurs when destructors are calling into Rust free/drop,
689
+ // which causes the JS callback to be dropped.
690
+ return;
691
+ }
692
+
693
+ // The runtime, the actual callback jsi::funtion, and the callInvoker
694
+ // are all in the lambda.
695
+ rsLambda(
696
+ rs_data,
697
+ rs_pollResult);
698
+ }
699
+
700
+ [[maybe_unused]] static UniffiRustFutureContinuationCallback
701
+ makeCallbackFunction( // uniffi::el_ffi::cb::rustfuturecontinuationcallback
702
+ jsi::Runtime &rt,
703
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
704
+ const jsi::Value &value) {
705
+ if (rsLambda != nullptr) {
706
+ // `makeCallbackFunction` is called in two circumstances:
707
+ //
708
+ // 1. at startup, when initializing callback interface vtables.
709
+ // 2. when polling futures. This happens at least once per future that is
710
+ // exposed to Javascript. We know that this is always the same function,
711
+ // `uniffiFutureContinuationCallback` in `async-rust-calls.ts`.
712
+ //
713
+ // We can therefore return the callback function without making anything
714
+ // new if we've been initialized already.
715
+ return callback;
716
+ }
717
+ auto callbackFunction = value.asObject(rt).asFunction(rt);
718
+ auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
719
+ rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_data, int8_t rs_pollResult) {
720
+ // We immediately make a lambda which will do the work of transforming the
721
+ // arguments into JSI values and calling the callback.
722
+ uniffi_runtime::UniffiCallFunc jsLambda = [
723
+ callInvoker,
724
+ callbackValue
725
+ , rs_data
726
+ , rs_pollResult](jsi::Runtime &rt) mutable {
727
+ body(rt, callInvoker, callbackValue
728
+ , rs_data
729
+ , rs_pollResult);
730
+ };
731
+ // We'll then call that lambda from the callInvoker which will
732
+ // look after calling it on the correct thread.
733
+
734
+ callInvoker->invokeNonBlocking(rt, jsLambda);
735
+ };
736
+ return callback;
737
+ }
738
+
739
+ // This method is called from the destructor of NativeElFfi, which only happens
740
+ // when the jsi::Runtime is being destroyed.
741
+ static void cleanup() {
742
+ // The lambda holds a reference to the the Runtime, so when this is nulled out,
743
+ // then the pointer will no longer be left dangling.
744
+ rsLambda = nullptr;
745
+ }
746
+ } // namespace uniffi::el_ffi::cb::rustfuturecontinuationcallback
747
+ // Implementation of callback function calling from Rust to JS ForeignFutureDroppedCallback
748
+
749
+ // Callback function: uniffi::el_ffi::cb::foreignfuturedroppedcallback::UniffiForeignFutureDroppedCallback
750
+ //
751
+ // We have the following constraints:
752
+ // - we need to pass a function pointer to Rust.
753
+ // - we need a jsi::Runtime and jsi::Function to call into JS.
754
+ // - function pointers can't store state, so we can't use a lamda.
755
+ //
756
+ // For this, we store a lambda as a global, as `rsLambda`. The `callback` function calls
757
+ // the lambda, which itself calls the `body` which then calls into JS.
758
+ //
759
+ // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
760
+ // future.
761
+ namespace uniffi::el_ffi::cb::foreignfuturedroppedcallback {
762
+ using namespace facebook;
763
+
764
+ // We need to store a lambda in a global so we can call it from
765
+ // a function pointer. The function pointer is passed to Rust.
766
+ static std::function<void(uint64_t)> rsLambda = nullptr;
767
+
768
+ // This is the main body of the callback. It's called from the lambda,
769
+ // which itself is called from the callback function which is passed to Rust.
770
+ static void body(jsi::Runtime &rt,
771
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
772
+ std::shared_ptr<jsi::Value> callbackValue
773
+ ,uint64_t rs_handle) {
774
+
775
+ // Convert the arguments from Rust, into jsi::Values.
776
+ // We'll use the Bridging class to do this…
777
+ auto js_handle = uniffi_jsi::Bridging<uint64_t>::toJs(rt, callInvoker, rs_handle);
778
+
779
+ // Now we are ready to call the callback.
780
+ // We are already on the JS thread, because this `body` function was
781
+ // invoked from the CallInvoker.
782
+ try {
783
+ // Getting the callback function
784
+ auto cb = callbackValue->asObject(rt).asFunction(rt);
785
+ auto uniffiResult = cb.call(rt, js_handle
786
+ );
787
+
788
+
789
+
790
+
791
+ } catch (const jsi::JSError &error) {
792
+ std::cout << "Error in callback UniffiForeignFutureDroppedCallback: "
793
+ << error.what() << std::endl;
794
+ throw error;
795
+ }
796
+ }
797
+
798
+ static void callback(uint64_t rs_handle) {
799
+ // If the runtime has shutdown, then there is no point in trying to
800
+ // call into Javascript. BUT how do we tell if the runtime has shutdown?
801
+ //
802
+ // Answer: the module destructor calls into callback `cleanup` method,
803
+ // which nulls out the rsLamda.
804
+ //
805
+ // If rsLamda is null, then there is no runtime to call into.
806
+ if (rsLambda == nullptr) {
807
+ // This only occurs when destructors are calling into Rust free/drop,
808
+ // which causes the JS callback to be dropped.
809
+ return;
810
+ }
811
+
812
+ // The runtime, the actual callback jsi::funtion, and the callInvoker
813
+ // are all in the lambda.
814
+ rsLambda(
815
+ rs_handle);
816
+ }
817
+
818
+ [[maybe_unused]] static UniffiForeignFutureDroppedCallback
819
+ makeCallbackFunction( // uniffi::el_ffi::cb::foreignfuturedroppedcallback
820
+ jsi::Runtime &rt,
821
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
822
+ const jsi::Value &value) {
823
+ if (rsLambda != nullptr) {
824
+ // `makeCallbackFunction` is called in two circumstances:
825
+ //
826
+ // 1. at startup, when initializing callback interface vtables.
827
+ // 2. when polling futures. This happens at least once per future that is
828
+ // exposed to Javascript. We know that this is always the same function,
829
+ // `uniffiFutureContinuationCallback` in `async-rust-calls.ts`.
830
+ //
831
+ // We can therefore return the callback function without making anything
832
+ // new if we've been initialized already.
833
+ return callback;
834
+ }
835
+ auto callbackFunction = value.asObject(rt).asFunction(rt);
836
+ auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
837
+ rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_handle) {
838
+ // We immediately make a lambda which will do the work of transforming the
839
+ // arguments into JSI values and calling the callback.
840
+ uniffi_runtime::UniffiCallFunc jsLambda = [
841
+ callInvoker,
842
+ callbackValue
843
+ , rs_handle](jsi::Runtime &rt) mutable {
844
+ body(rt, callInvoker, callbackValue
845
+ , rs_handle);
846
+ };
847
+ // We'll then call that lambda from the callInvoker which will
848
+ // look after calling it on the correct thread.
849
+
850
+ callInvoker->invokeNonBlocking(rt, jsLambda);
851
+ };
852
+ return callback;
853
+ }
854
+
855
+ // This method is called from the destructor of NativeElFfi, which only happens
856
+ // when the jsi::Runtime is being destroyed.
857
+ static void cleanup() {
858
+ // The lambda holds a reference to the the Runtime, so when this is nulled out,
859
+ // then the pointer will no longer be left dangling.
860
+ rsLambda = nullptr;
861
+ }
862
+ } // namespace uniffi::el_ffi::cb::foreignfuturedroppedcallback
863
+ // Implementation of free callback function CallbackInterfaceFree
864
+
865
+
866
+ // Callback function: uniffi::el_ffi::st::vtablecallbackinterfacestreamhandler::vtablecallbackinterfacestreamhandler::free::UniffiCallbackInterfaceFree
867
+ //
868
+ // We have the following constraints:
869
+ // - we need to pass a function pointer to Rust.
870
+ // - we need a jsi::Runtime and jsi::Function to call into JS.
871
+ // - function pointers can't store state, so we can't use a lamda.
872
+ //
873
+ // For this, we store a lambda as a global, as `rsLambda`. The `callback` function calls
874
+ // the lambda, which itself calls the `body` which then calls into JS.
875
+ //
876
+ // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
877
+ // future.
878
+ namespace uniffi::el_ffi::st::vtablecallbackinterfacestreamhandler::vtablecallbackinterfacestreamhandler::free {
879
+ using namespace facebook;
880
+
881
+ // We need to store a lambda in a global so we can call it from
882
+ // a function pointer. The function pointer is passed to Rust.
883
+ static std::function<void(uint64_t)> rsLambda = nullptr;
884
+
885
+ // This is the main body of the callback. It's called from the lambda,
886
+ // which itself is called from the callback function which is passed to Rust.
887
+ static void body(jsi::Runtime &rt,
888
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
889
+ std::shared_ptr<jsi::Value> callbackValue
890
+ ,uint64_t rs_handle) {
891
+
892
+ // Convert the arguments from Rust, into jsi::Values.
893
+ // We'll use the Bridging class to do this…
894
+ auto js_handle = uniffi_jsi::Bridging<uint64_t>::toJs(rt, callInvoker, rs_handle);
895
+
896
+ // Now we are ready to call the callback.
897
+ // We are already on the JS thread, because this `body` function was
898
+ // invoked from the CallInvoker.
899
+ try {
900
+ // Getting the callback function
901
+ auto cb = callbackValue->asObject(rt).asFunction(rt);
902
+ auto uniffiResult = cb.call(rt, js_handle
903
+ );
904
+
905
+
906
+
907
+
908
+ } catch (const jsi::JSError &error) {
909
+ std::cout << "Error in callback UniffiCallbackInterfaceFree: "
910
+ << error.what() << std::endl;
911
+ throw error;
912
+ }
913
+ }
914
+
915
+ static void callback(uint64_t rs_handle) {
916
+ // If the runtime has shutdown, then there is no point in trying to
917
+ // call into Javascript. BUT how do we tell if the runtime has shutdown?
918
+ //
919
+ // Answer: the module destructor calls into callback `cleanup` method,
920
+ // which nulls out the rsLamda.
921
+ //
922
+ // If rsLamda is null, then there is no runtime to call into.
923
+ if (rsLambda == nullptr) {
924
+ // This only occurs when destructors are calling into Rust free/drop,
925
+ // which causes the JS callback to be dropped.
926
+ return;
927
+ }
928
+
929
+ // The runtime, the actual callback jsi::funtion, and the callInvoker
930
+ // are all in the lambda.
931
+ rsLambda(
932
+ rs_handle);
933
+ }
934
+
935
+ [[maybe_unused]] static UniffiCallbackInterfaceFree
936
+ makeCallbackFunction( // uniffi::el_ffi::st::vtablecallbackinterfacestreamhandler::vtablecallbackinterfacestreamhandler::free
937
+ jsi::Runtime &rt,
938
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
939
+ const jsi::Value &value) {
940
+ if (rsLambda != nullptr) {
941
+ // `makeCallbackFunction` is called in two circumstances:
942
+ //
943
+ // 1. at startup, when initializing callback interface vtables.
944
+ // 2. when polling futures. This happens at least once per future that is
945
+ // exposed to Javascript. We know that this is always the same function,
946
+ // `uniffiFutureContinuationCallback` in `async-rust-calls.ts`.
947
+ //
948
+ // We can therefore return the callback function without making anything
949
+ // new if we've been initialized already.
950
+ return callback;
951
+ }
952
+ auto callbackFunction = value.asObject(rt).asFunction(rt);
953
+ auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
954
+ rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_handle) {
955
+ // We immediately make a lambda which will do the work of transforming the
956
+ // arguments into JSI values and calling the callback.
957
+ uniffi_runtime::UniffiCallFunc jsLambda = [
958
+ callInvoker,
959
+ callbackValue
960
+ , rs_handle](jsi::Runtime &rt) mutable {
961
+ body(rt, callInvoker, callbackValue
962
+ , rs_handle);
963
+ };
964
+ // We'll then call that lambda from the callInvoker which will
965
+ // look after calling it on the correct thread.
966
+
967
+ callInvoker->invokeNonBlocking(rt, jsLambda);
968
+ };
969
+ return callback;
970
+ }
971
+
972
+ // This method is called from the destructor of NativeElFfi, which only happens
973
+ // when the jsi::Runtime is being destroyed.
974
+ static void cleanup() {
975
+ // The lambda holds a reference to the the Runtime, so when this is nulled out,
976
+ // then the pointer will no longer be left dangling.
977
+ rsLambda = nullptr;
978
+ }
979
+ } // namespace uniffi::el_ffi::st::vtablecallbackinterfacestreamhandler::vtablecallbackinterfacestreamhandler::free
980
+ namespace uniffi::el_ffi {
981
+ using namespace facebook;
982
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
983
+
984
+ template <> struct Bridging<UniffiForeignFutureDroppedCallbackStruct> {
985
+ static UniffiForeignFutureDroppedCallbackStruct fromJs(jsi::Runtime &rt,
986
+ std::shared_ptr<CallInvoker> callInvoker,
987
+ const jsi::Value &jsValue
988
+ ) {
989
+ // Check if the input is an object
990
+ if (!jsValue.isObject()) {
991
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureDroppedCallbackStruct");
992
+ }
993
+
994
+ // Get the object from the jsi::Value
995
+ auto jsObject = jsValue.getObject(rt);
996
+
997
+ // Create the vtable struct
998
+ UniffiForeignFutureDroppedCallbackStruct rsObject;
999
+
1000
+ // Create the vtable from the js callbacks.
1001
+ rsObject.handle = uniffi_jsi::Bridging<uint64_t>::fromJs(
1002
+ rt, callInvoker,
1003
+ jsObject.getProperty(rt, "handle")
1004
+ );
1005
+ rsObject.free = uniffi::el_ffi::cb::foreignfuturedroppedcallback::makeCallbackFunction(
1006
+ rt, callInvoker, jsObject.getProperty(rt, "free")
1007
+ );
1008
+
1009
+ return rsObject;
1010
+ }
1011
+ };
1012
+
1013
+ } // namespace uniffi::el_ffi
1014
+ namespace uniffi::el_ffi {
1015
+ using namespace facebook;
1016
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1017
+
1018
+ template <> struct Bridging<UniffiForeignFutureResultU8> {
1019
+ static UniffiForeignFutureResultU8 fromJs(jsi::Runtime &rt,
1020
+ std::shared_ptr<CallInvoker> callInvoker,
1021
+ const jsi::Value &jsValue
1022
+ ) {
1023
+ // Check if the input is an object
1024
+ if (!jsValue.isObject()) {
1025
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultU8");
1026
+ }
1027
+
1028
+ // Get the object from the jsi::Value
1029
+ auto jsObject = jsValue.getObject(rt);
1030
+
1031
+ // Create the vtable struct
1032
+ UniffiForeignFutureResultU8 rsObject;
1033
+
1034
+ // Create the vtable from the js callbacks.
1035
+ rsObject.return_value = uniffi_jsi::Bridging<uint8_t>::fromJs(
1036
+ rt, callInvoker,
1037
+ jsObject.getProperty(rt, "return_value")
1038
+ );
1039
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1040
+ rt, callInvoker,
1041
+ jsObject.getProperty(rt, "call_status")
1042
+ );
1043
+
1044
+ return rsObject;
1045
+ }
1046
+ };
1047
+
1048
+ } // namespace uniffi::el_ffi
1049
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteU8,
1050
+ // passed from Rust to JS as part of async callbacks.
1051
+ namespace uniffi::el_ffi {
1052
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1053
+
1054
+ template <> struct Bridging<UniffiForeignFutureCompleteU8> {
1055
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteU8 rsCallback) {
1056
+ return jsi::Function::createFromHostFunction(
1057
+ rt,
1058
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteU8"),
1059
+ 2,
1060
+ [rsCallback, callInvoker](
1061
+ jsi::Runtime &rt,
1062
+ const jsi::Value &thisValue,
1063
+ const jsi::Value *arguments,
1064
+ size_t count) -> jsi::Value
1065
+ {
1066
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1067
+ }
1068
+ );
1069
+ }
1070
+
1071
+ static jsi::Value intoRust(
1072
+ jsi::Runtime &rt,
1073
+ std::shared_ptr<CallInvoker> callInvoker,
1074
+ const jsi::Value &thisValue,
1075
+ const jsi::Value *args,
1076
+ size_t count,
1077
+ UniffiForeignFutureCompleteU8 func) {
1078
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1079
+ // then call the rs_callback with those arguments.
1080
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultU8>::fromJs(rt, callInvoker, args[1])
1081
+ );
1082
+
1083
+
1084
+ return jsi::Value::undefined();
1085
+ }
1086
+ };
1087
+ } // namespace uniffi::el_ffi
1088
+ namespace uniffi::el_ffi {
1089
+ using namespace facebook;
1090
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1091
+
1092
+ template <> struct Bridging<UniffiForeignFutureResultI8> {
1093
+ static UniffiForeignFutureResultI8 fromJs(jsi::Runtime &rt,
1094
+ std::shared_ptr<CallInvoker> callInvoker,
1095
+ const jsi::Value &jsValue
1096
+ ) {
1097
+ // Check if the input is an object
1098
+ if (!jsValue.isObject()) {
1099
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultI8");
1100
+ }
1101
+
1102
+ // Get the object from the jsi::Value
1103
+ auto jsObject = jsValue.getObject(rt);
1104
+
1105
+ // Create the vtable struct
1106
+ UniffiForeignFutureResultI8 rsObject;
1107
+
1108
+ // Create the vtable from the js callbacks.
1109
+ rsObject.return_value = uniffi_jsi::Bridging<int8_t>::fromJs(
1110
+ rt, callInvoker,
1111
+ jsObject.getProperty(rt, "return_value")
1112
+ );
1113
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1114
+ rt, callInvoker,
1115
+ jsObject.getProperty(rt, "call_status")
1116
+ );
1117
+
1118
+ return rsObject;
1119
+ }
1120
+ };
1121
+
1122
+ } // namespace uniffi::el_ffi
1123
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteI8,
1124
+ // passed from Rust to JS as part of async callbacks.
1125
+ namespace uniffi::el_ffi {
1126
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1127
+
1128
+ template <> struct Bridging<UniffiForeignFutureCompleteI8> {
1129
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteI8 rsCallback) {
1130
+ return jsi::Function::createFromHostFunction(
1131
+ rt,
1132
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteI8"),
1133
+ 2,
1134
+ [rsCallback, callInvoker](
1135
+ jsi::Runtime &rt,
1136
+ const jsi::Value &thisValue,
1137
+ const jsi::Value *arguments,
1138
+ size_t count) -> jsi::Value
1139
+ {
1140
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1141
+ }
1142
+ );
1143
+ }
1144
+
1145
+ static jsi::Value intoRust(
1146
+ jsi::Runtime &rt,
1147
+ std::shared_ptr<CallInvoker> callInvoker,
1148
+ const jsi::Value &thisValue,
1149
+ const jsi::Value *args,
1150
+ size_t count,
1151
+ UniffiForeignFutureCompleteI8 func) {
1152
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1153
+ // then call the rs_callback with those arguments.
1154
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultI8>::fromJs(rt, callInvoker, args[1])
1155
+ );
1156
+
1157
+
1158
+ return jsi::Value::undefined();
1159
+ }
1160
+ };
1161
+ } // namespace uniffi::el_ffi
1162
+ namespace uniffi::el_ffi {
1163
+ using namespace facebook;
1164
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1165
+
1166
+ template <> struct Bridging<UniffiForeignFutureResultU16> {
1167
+ static UniffiForeignFutureResultU16 fromJs(jsi::Runtime &rt,
1168
+ std::shared_ptr<CallInvoker> callInvoker,
1169
+ const jsi::Value &jsValue
1170
+ ) {
1171
+ // Check if the input is an object
1172
+ if (!jsValue.isObject()) {
1173
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultU16");
1174
+ }
1175
+
1176
+ // Get the object from the jsi::Value
1177
+ auto jsObject = jsValue.getObject(rt);
1178
+
1179
+ // Create the vtable struct
1180
+ UniffiForeignFutureResultU16 rsObject;
1181
+
1182
+ // Create the vtable from the js callbacks.
1183
+ rsObject.return_value = uniffi_jsi::Bridging<uint16_t>::fromJs(
1184
+ rt, callInvoker,
1185
+ jsObject.getProperty(rt, "return_value")
1186
+ );
1187
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1188
+ rt, callInvoker,
1189
+ jsObject.getProperty(rt, "call_status")
1190
+ );
1191
+
1192
+ return rsObject;
1193
+ }
1194
+ };
1195
+
1196
+ } // namespace uniffi::el_ffi
1197
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteU16,
1198
+ // passed from Rust to JS as part of async callbacks.
1199
+ namespace uniffi::el_ffi {
1200
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1201
+
1202
+ template <> struct Bridging<UniffiForeignFutureCompleteU16> {
1203
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteU16 rsCallback) {
1204
+ return jsi::Function::createFromHostFunction(
1205
+ rt,
1206
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteU16"),
1207
+ 2,
1208
+ [rsCallback, callInvoker](
1209
+ jsi::Runtime &rt,
1210
+ const jsi::Value &thisValue,
1211
+ const jsi::Value *arguments,
1212
+ size_t count) -> jsi::Value
1213
+ {
1214
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1215
+ }
1216
+ );
1217
+ }
1218
+
1219
+ static jsi::Value intoRust(
1220
+ jsi::Runtime &rt,
1221
+ std::shared_ptr<CallInvoker> callInvoker,
1222
+ const jsi::Value &thisValue,
1223
+ const jsi::Value *args,
1224
+ size_t count,
1225
+ UniffiForeignFutureCompleteU16 func) {
1226
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1227
+ // then call the rs_callback with those arguments.
1228
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultU16>::fromJs(rt, callInvoker, args[1])
1229
+ );
1230
+
1231
+
1232
+ return jsi::Value::undefined();
1233
+ }
1234
+ };
1235
+ } // namespace uniffi::el_ffi
1236
+ namespace uniffi::el_ffi {
1237
+ using namespace facebook;
1238
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1239
+
1240
+ template <> struct Bridging<UniffiForeignFutureResultI16> {
1241
+ static UniffiForeignFutureResultI16 fromJs(jsi::Runtime &rt,
1242
+ std::shared_ptr<CallInvoker> callInvoker,
1243
+ const jsi::Value &jsValue
1244
+ ) {
1245
+ // Check if the input is an object
1246
+ if (!jsValue.isObject()) {
1247
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultI16");
1248
+ }
1249
+
1250
+ // Get the object from the jsi::Value
1251
+ auto jsObject = jsValue.getObject(rt);
1252
+
1253
+ // Create the vtable struct
1254
+ UniffiForeignFutureResultI16 rsObject;
1255
+
1256
+ // Create the vtable from the js callbacks.
1257
+ rsObject.return_value = uniffi_jsi::Bridging<int16_t>::fromJs(
1258
+ rt, callInvoker,
1259
+ jsObject.getProperty(rt, "return_value")
1260
+ );
1261
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1262
+ rt, callInvoker,
1263
+ jsObject.getProperty(rt, "call_status")
1264
+ );
1265
+
1266
+ return rsObject;
1267
+ }
1268
+ };
1269
+
1270
+ } // namespace uniffi::el_ffi
1271
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteI16,
1272
+ // passed from Rust to JS as part of async callbacks.
1273
+ namespace uniffi::el_ffi {
1274
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1275
+
1276
+ template <> struct Bridging<UniffiForeignFutureCompleteI16> {
1277
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteI16 rsCallback) {
1278
+ return jsi::Function::createFromHostFunction(
1279
+ rt,
1280
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteI16"),
1281
+ 2,
1282
+ [rsCallback, callInvoker](
1283
+ jsi::Runtime &rt,
1284
+ const jsi::Value &thisValue,
1285
+ const jsi::Value *arguments,
1286
+ size_t count) -> jsi::Value
1287
+ {
1288
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1289
+ }
1290
+ );
1291
+ }
1292
+
1293
+ static jsi::Value intoRust(
1294
+ jsi::Runtime &rt,
1295
+ std::shared_ptr<CallInvoker> callInvoker,
1296
+ const jsi::Value &thisValue,
1297
+ const jsi::Value *args,
1298
+ size_t count,
1299
+ UniffiForeignFutureCompleteI16 func) {
1300
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1301
+ // then call the rs_callback with those arguments.
1302
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultI16>::fromJs(rt, callInvoker, args[1])
1303
+ );
1304
+
1305
+
1306
+ return jsi::Value::undefined();
1307
+ }
1308
+ };
1309
+ } // namespace uniffi::el_ffi
1310
+ namespace uniffi::el_ffi {
1311
+ using namespace facebook;
1312
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1313
+
1314
+ template <> struct Bridging<UniffiForeignFutureResultU32> {
1315
+ static UniffiForeignFutureResultU32 fromJs(jsi::Runtime &rt,
1316
+ std::shared_ptr<CallInvoker> callInvoker,
1317
+ const jsi::Value &jsValue
1318
+ ) {
1319
+ // Check if the input is an object
1320
+ if (!jsValue.isObject()) {
1321
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultU32");
1322
+ }
1323
+
1324
+ // Get the object from the jsi::Value
1325
+ auto jsObject = jsValue.getObject(rt);
1326
+
1327
+ // Create the vtable struct
1328
+ UniffiForeignFutureResultU32 rsObject;
1329
+
1330
+ // Create the vtable from the js callbacks.
1331
+ rsObject.return_value = uniffi_jsi::Bridging<uint32_t>::fromJs(
1332
+ rt, callInvoker,
1333
+ jsObject.getProperty(rt, "return_value")
1334
+ );
1335
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1336
+ rt, callInvoker,
1337
+ jsObject.getProperty(rt, "call_status")
1338
+ );
1339
+
1340
+ return rsObject;
1341
+ }
1342
+ };
1343
+
1344
+ } // namespace uniffi::el_ffi
1345
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteU32,
1346
+ // passed from Rust to JS as part of async callbacks.
1347
+ namespace uniffi::el_ffi {
1348
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1349
+
1350
+ template <> struct Bridging<UniffiForeignFutureCompleteU32> {
1351
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteU32 rsCallback) {
1352
+ return jsi::Function::createFromHostFunction(
1353
+ rt,
1354
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteU32"),
1355
+ 2,
1356
+ [rsCallback, callInvoker](
1357
+ jsi::Runtime &rt,
1358
+ const jsi::Value &thisValue,
1359
+ const jsi::Value *arguments,
1360
+ size_t count) -> jsi::Value
1361
+ {
1362
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1363
+ }
1364
+ );
1365
+ }
1366
+
1367
+ static jsi::Value intoRust(
1368
+ jsi::Runtime &rt,
1369
+ std::shared_ptr<CallInvoker> callInvoker,
1370
+ const jsi::Value &thisValue,
1371
+ const jsi::Value *args,
1372
+ size_t count,
1373
+ UniffiForeignFutureCompleteU32 func) {
1374
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1375
+ // then call the rs_callback with those arguments.
1376
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultU32>::fromJs(rt, callInvoker, args[1])
1377
+ );
1378
+
1379
+
1380
+ return jsi::Value::undefined();
1381
+ }
1382
+ };
1383
+ } // namespace uniffi::el_ffi
1384
+ namespace uniffi::el_ffi {
1385
+ using namespace facebook;
1386
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1387
+
1388
+ template <> struct Bridging<UniffiForeignFutureResultI32> {
1389
+ static UniffiForeignFutureResultI32 fromJs(jsi::Runtime &rt,
1390
+ std::shared_ptr<CallInvoker> callInvoker,
1391
+ const jsi::Value &jsValue
1392
+ ) {
1393
+ // Check if the input is an object
1394
+ if (!jsValue.isObject()) {
1395
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultI32");
1396
+ }
1397
+
1398
+ // Get the object from the jsi::Value
1399
+ auto jsObject = jsValue.getObject(rt);
1400
+
1401
+ // Create the vtable struct
1402
+ UniffiForeignFutureResultI32 rsObject;
1403
+
1404
+ // Create the vtable from the js callbacks.
1405
+ rsObject.return_value = uniffi_jsi::Bridging<int32_t>::fromJs(
1406
+ rt, callInvoker,
1407
+ jsObject.getProperty(rt, "return_value")
1408
+ );
1409
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1410
+ rt, callInvoker,
1411
+ jsObject.getProperty(rt, "call_status")
1412
+ );
1413
+
1414
+ return rsObject;
1415
+ }
1416
+ };
1417
+
1418
+ } // namespace uniffi::el_ffi
1419
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteI32,
1420
+ // passed from Rust to JS as part of async callbacks.
1421
+ namespace uniffi::el_ffi {
1422
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1423
+
1424
+ template <> struct Bridging<UniffiForeignFutureCompleteI32> {
1425
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteI32 rsCallback) {
1426
+ return jsi::Function::createFromHostFunction(
1427
+ rt,
1428
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteI32"),
1429
+ 2,
1430
+ [rsCallback, callInvoker](
1431
+ jsi::Runtime &rt,
1432
+ const jsi::Value &thisValue,
1433
+ const jsi::Value *arguments,
1434
+ size_t count) -> jsi::Value
1435
+ {
1436
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1437
+ }
1438
+ );
1439
+ }
1440
+
1441
+ static jsi::Value intoRust(
1442
+ jsi::Runtime &rt,
1443
+ std::shared_ptr<CallInvoker> callInvoker,
1444
+ const jsi::Value &thisValue,
1445
+ const jsi::Value *args,
1446
+ size_t count,
1447
+ UniffiForeignFutureCompleteI32 func) {
1448
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1449
+ // then call the rs_callback with those arguments.
1450
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultI32>::fromJs(rt, callInvoker, args[1])
1451
+ );
1452
+
1453
+
1454
+ return jsi::Value::undefined();
1455
+ }
1456
+ };
1457
+ } // namespace uniffi::el_ffi
1458
+ namespace uniffi::el_ffi {
1459
+ using namespace facebook;
1460
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1461
+
1462
+ template <> struct Bridging<UniffiForeignFutureResultU64> {
1463
+ static UniffiForeignFutureResultU64 fromJs(jsi::Runtime &rt,
1464
+ std::shared_ptr<CallInvoker> callInvoker,
1465
+ const jsi::Value &jsValue
1466
+ ) {
1467
+ // Check if the input is an object
1468
+ if (!jsValue.isObject()) {
1469
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultU64");
1470
+ }
1471
+
1472
+ // Get the object from the jsi::Value
1473
+ auto jsObject = jsValue.getObject(rt);
1474
+
1475
+ // Create the vtable struct
1476
+ UniffiForeignFutureResultU64 rsObject;
1477
+
1478
+ // Create the vtable from the js callbacks.
1479
+ rsObject.return_value = uniffi_jsi::Bridging<uint64_t>::fromJs(
1480
+ rt, callInvoker,
1481
+ jsObject.getProperty(rt, "return_value")
1482
+ );
1483
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1484
+ rt, callInvoker,
1485
+ jsObject.getProperty(rt, "call_status")
1486
+ );
1487
+
1488
+ return rsObject;
1489
+ }
1490
+ };
1491
+
1492
+ } // namespace uniffi::el_ffi
1493
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteU64,
1494
+ // passed from Rust to JS as part of async callbacks.
1495
+ namespace uniffi::el_ffi {
1496
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1497
+
1498
+ template <> struct Bridging<UniffiForeignFutureCompleteU64> {
1499
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteU64 rsCallback) {
1500
+ return jsi::Function::createFromHostFunction(
1501
+ rt,
1502
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteU64"),
1503
+ 2,
1504
+ [rsCallback, callInvoker](
1505
+ jsi::Runtime &rt,
1506
+ const jsi::Value &thisValue,
1507
+ const jsi::Value *arguments,
1508
+ size_t count) -> jsi::Value
1509
+ {
1510
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1511
+ }
1512
+ );
1513
+ }
1514
+
1515
+ static jsi::Value intoRust(
1516
+ jsi::Runtime &rt,
1517
+ std::shared_ptr<CallInvoker> callInvoker,
1518
+ const jsi::Value &thisValue,
1519
+ const jsi::Value *args,
1520
+ size_t count,
1521
+ UniffiForeignFutureCompleteU64 func) {
1522
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1523
+ // then call the rs_callback with those arguments.
1524
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultU64>::fromJs(rt, callInvoker, args[1])
1525
+ );
1526
+
1527
+
1528
+ return jsi::Value::undefined();
1529
+ }
1530
+ };
1531
+ } // namespace uniffi::el_ffi
1532
+ namespace uniffi::el_ffi {
1533
+ using namespace facebook;
1534
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1535
+
1536
+ template <> struct Bridging<UniffiForeignFutureResultI64> {
1537
+ static UniffiForeignFutureResultI64 fromJs(jsi::Runtime &rt,
1538
+ std::shared_ptr<CallInvoker> callInvoker,
1539
+ const jsi::Value &jsValue
1540
+ ) {
1541
+ // Check if the input is an object
1542
+ if (!jsValue.isObject()) {
1543
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultI64");
1544
+ }
1545
+
1546
+ // Get the object from the jsi::Value
1547
+ auto jsObject = jsValue.getObject(rt);
1548
+
1549
+ // Create the vtable struct
1550
+ UniffiForeignFutureResultI64 rsObject;
1551
+
1552
+ // Create the vtable from the js callbacks.
1553
+ rsObject.return_value = uniffi_jsi::Bridging<int64_t>::fromJs(
1554
+ rt, callInvoker,
1555
+ jsObject.getProperty(rt, "return_value")
1556
+ );
1557
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1558
+ rt, callInvoker,
1559
+ jsObject.getProperty(rt, "call_status")
1560
+ );
1561
+
1562
+ return rsObject;
1563
+ }
1564
+ };
1565
+
1566
+ } // namespace uniffi::el_ffi
1567
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteI64,
1568
+ // passed from Rust to JS as part of async callbacks.
1569
+ namespace uniffi::el_ffi {
1570
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1571
+
1572
+ template <> struct Bridging<UniffiForeignFutureCompleteI64> {
1573
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteI64 rsCallback) {
1574
+ return jsi::Function::createFromHostFunction(
1575
+ rt,
1576
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteI64"),
1577
+ 2,
1578
+ [rsCallback, callInvoker](
1579
+ jsi::Runtime &rt,
1580
+ const jsi::Value &thisValue,
1581
+ const jsi::Value *arguments,
1582
+ size_t count) -> jsi::Value
1583
+ {
1584
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1585
+ }
1586
+ );
1587
+ }
1588
+
1589
+ static jsi::Value intoRust(
1590
+ jsi::Runtime &rt,
1591
+ std::shared_ptr<CallInvoker> callInvoker,
1592
+ const jsi::Value &thisValue,
1593
+ const jsi::Value *args,
1594
+ size_t count,
1595
+ UniffiForeignFutureCompleteI64 func) {
1596
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1597
+ // then call the rs_callback with those arguments.
1598
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultI64>::fromJs(rt, callInvoker, args[1])
1599
+ );
1600
+
1601
+
1602
+ return jsi::Value::undefined();
1603
+ }
1604
+ };
1605
+ } // namespace uniffi::el_ffi
1606
+ namespace uniffi::el_ffi {
1607
+ using namespace facebook;
1608
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1609
+
1610
+ template <> struct Bridging<UniffiForeignFutureResultF32> {
1611
+ static UniffiForeignFutureResultF32 fromJs(jsi::Runtime &rt,
1612
+ std::shared_ptr<CallInvoker> callInvoker,
1613
+ const jsi::Value &jsValue
1614
+ ) {
1615
+ // Check if the input is an object
1616
+ if (!jsValue.isObject()) {
1617
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultF32");
1618
+ }
1619
+
1620
+ // Get the object from the jsi::Value
1621
+ auto jsObject = jsValue.getObject(rt);
1622
+
1623
+ // Create the vtable struct
1624
+ UniffiForeignFutureResultF32 rsObject;
1625
+
1626
+ // Create the vtable from the js callbacks.
1627
+ rsObject.return_value = uniffi_jsi::Bridging<float>::fromJs(
1628
+ rt, callInvoker,
1629
+ jsObject.getProperty(rt, "return_value")
1630
+ );
1631
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1632
+ rt, callInvoker,
1633
+ jsObject.getProperty(rt, "call_status")
1634
+ );
1635
+
1636
+ return rsObject;
1637
+ }
1638
+ };
1639
+
1640
+ } // namespace uniffi::el_ffi
1641
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteF32,
1642
+ // passed from Rust to JS as part of async callbacks.
1643
+ namespace uniffi::el_ffi {
1644
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1645
+
1646
+ template <> struct Bridging<UniffiForeignFutureCompleteF32> {
1647
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteF32 rsCallback) {
1648
+ return jsi::Function::createFromHostFunction(
1649
+ rt,
1650
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteF32"),
1651
+ 2,
1652
+ [rsCallback, callInvoker](
1653
+ jsi::Runtime &rt,
1654
+ const jsi::Value &thisValue,
1655
+ const jsi::Value *arguments,
1656
+ size_t count) -> jsi::Value
1657
+ {
1658
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1659
+ }
1660
+ );
1661
+ }
1662
+
1663
+ static jsi::Value intoRust(
1664
+ jsi::Runtime &rt,
1665
+ std::shared_ptr<CallInvoker> callInvoker,
1666
+ const jsi::Value &thisValue,
1667
+ const jsi::Value *args,
1668
+ size_t count,
1669
+ UniffiForeignFutureCompleteF32 func) {
1670
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1671
+ // then call the rs_callback with those arguments.
1672
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultF32>::fromJs(rt, callInvoker, args[1])
1673
+ );
1674
+
1675
+
1676
+ return jsi::Value::undefined();
1677
+ }
1678
+ };
1679
+ } // namespace uniffi::el_ffi
1680
+ namespace uniffi::el_ffi {
1681
+ using namespace facebook;
1682
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1683
+
1684
+ template <> struct Bridging<UniffiForeignFutureResultF64> {
1685
+ static UniffiForeignFutureResultF64 fromJs(jsi::Runtime &rt,
1686
+ std::shared_ptr<CallInvoker> callInvoker,
1687
+ const jsi::Value &jsValue
1688
+ ) {
1689
+ // Check if the input is an object
1690
+ if (!jsValue.isObject()) {
1691
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultF64");
1692
+ }
1693
+
1694
+ // Get the object from the jsi::Value
1695
+ auto jsObject = jsValue.getObject(rt);
1696
+
1697
+ // Create the vtable struct
1698
+ UniffiForeignFutureResultF64 rsObject;
1699
+
1700
+ // Create the vtable from the js callbacks.
1701
+ rsObject.return_value = uniffi_jsi::Bridging<double>::fromJs(
1702
+ rt, callInvoker,
1703
+ jsObject.getProperty(rt, "return_value")
1704
+ );
1705
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1706
+ rt, callInvoker,
1707
+ jsObject.getProperty(rt, "call_status")
1708
+ );
1709
+
1710
+ return rsObject;
1711
+ }
1712
+ };
1713
+
1714
+ } // namespace uniffi::el_ffi
1715
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteF64,
1716
+ // passed from Rust to JS as part of async callbacks.
1717
+ namespace uniffi::el_ffi {
1718
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1719
+
1720
+ template <> struct Bridging<UniffiForeignFutureCompleteF64> {
1721
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteF64 rsCallback) {
1722
+ return jsi::Function::createFromHostFunction(
1723
+ rt,
1724
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteF64"),
1725
+ 2,
1726
+ [rsCallback, callInvoker](
1727
+ jsi::Runtime &rt,
1728
+ const jsi::Value &thisValue,
1729
+ const jsi::Value *arguments,
1730
+ size_t count) -> jsi::Value
1731
+ {
1732
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1733
+ }
1734
+ );
1735
+ }
1736
+
1737
+ static jsi::Value intoRust(
1738
+ jsi::Runtime &rt,
1739
+ std::shared_ptr<CallInvoker> callInvoker,
1740
+ const jsi::Value &thisValue,
1741
+ const jsi::Value *args,
1742
+ size_t count,
1743
+ UniffiForeignFutureCompleteF64 func) {
1744
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1745
+ // then call the rs_callback with those arguments.
1746
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultF64>::fromJs(rt, callInvoker, args[1])
1747
+ );
1748
+
1749
+
1750
+ return jsi::Value::undefined();
1751
+ }
1752
+ };
1753
+ } // namespace uniffi::el_ffi
1754
+ namespace uniffi::el_ffi {
1755
+ using namespace facebook;
1756
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1757
+
1758
+ template <> struct Bridging<UniffiForeignFutureResultRustBuffer> {
1759
+ static UniffiForeignFutureResultRustBuffer fromJs(jsi::Runtime &rt,
1760
+ std::shared_ptr<CallInvoker> callInvoker,
1761
+ const jsi::Value &jsValue
1762
+ ) {
1763
+ // Check if the input is an object
1764
+ if (!jsValue.isObject()) {
1765
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultRustBuffer");
1766
+ }
1767
+
1768
+ // Get the object from the jsi::Value
1769
+ auto jsObject = jsValue.getObject(rt);
1770
+
1771
+ // Create the vtable struct
1772
+ UniffiForeignFutureResultRustBuffer rsObject;
1773
+
1774
+ // Create the vtable from the js callbacks.
1775
+ rsObject.return_value = uniffi::el_ffi::Bridging<RustBuffer>::fromJs(
1776
+ rt, callInvoker,
1777
+ jsObject.getProperty(rt, "return_value")
1778
+ );
1779
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1780
+ rt, callInvoker,
1781
+ jsObject.getProperty(rt, "call_status")
1782
+ );
1783
+
1784
+ return rsObject;
1785
+ }
1786
+ };
1787
+
1788
+ } // namespace uniffi::el_ffi
1789
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteRustBuffer,
1790
+ // passed from Rust to JS as part of async callbacks.
1791
+ namespace uniffi::el_ffi {
1792
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1793
+
1794
+ template <> struct Bridging<UniffiForeignFutureCompleteRustBuffer> {
1795
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteRustBuffer rsCallback) {
1796
+ return jsi::Function::createFromHostFunction(
1797
+ rt,
1798
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteRustBuffer"),
1799
+ 2,
1800
+ [rsCallback, callInvoker](
1801
+ jsi::Runtime &rt,
1802
+ const jsi::Value &thisValue,
1803
+ const jsi::Value *arguments,
1804
+ size_t count) -> jsi::Value
1805
+ {
1806
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1807
+ }
1808
+ );
1809
+ }
1810
+
1811
+ static jsi::Value intoRust(
1812
+ jsi::Runtime &rt,
1813
+ std::shared_ptr<CallInvoker> callInvoker,
1814
+ const jsi::Value &thisValue,
1815
+ const jsi::Value *args,
1816
+ size_t count,
1817
+ UniffiForeignFutureCompleteRustBuffer func) {
1818
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1819
+ // then call the rs_callback with those arguments.
1820
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultRustBuffer>::fromJs(rt, callInvoker, args[1])
1821
+ );
1822
+
1823
+
1824
+ return jsi::Value::undefined();
1825
+ }
1826
+ };
1827
+ } // namespace uniffi::el_ffi
1828
+ namespace uniffi::el_ffi {
1829
+ using namespace facebook;
1830
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1831
+
1832
+ template <> struct Bridging<UniffiForeignFutureResultVoid> {
1833
+ static UniffiForeignFutureResultVoid fromJs(jsi::Runtime &rt,
1834
+ std::shared_ptr<CallInvoker> callInvoker,
1835
+ const jsi::Value &jsValue
1836
+ ) {
1837
+ // Check if the input is an object
1838
+ if (!jsValue.isObject()) {
1839
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultVoid");
1840
+ }
1841
+
1842
+ // Get the object from the jsi::Value
1843
+ auto jsObject = jsValue.getObject(rt);
1844
+
1845
+ // Create the vtable struct
1846
+ UniffiForeignFutureResultVoid rsObject;
1847
+
1848
+ // Create the vtable from the js callbacks.
1849
+ rsObject.call_status = uniffi::el_ffi::Bridging<RustCallStatus>::fromJs(
1850
+ rt, callInvoker,
1851
+ jsObject.getProperty(rt, "call_status")
1852
+ );
1853
+
1854
+ return rsObject;
1855
+ }
1856
+ };
1857
+
1858
+ } // namespace uniffi::el_ffi
1859
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteVoid,
1860
+ // passed from Rust to JS as part of async callbacks.
1861
+ namespace uniffi::el_ffi {
1862
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1863
+
1864
+ template <> struct Bridging<UniffiForeignFutureCompleteVoid> {
1865
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteVoid rsCallback) {
1866
+ return jsi::Function::createFromHostFunction(
1867
+ rt,
1868
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteVoid"),
1869
+ 2,
1870
+ [rsCallback, callInvoker](
1871
+ jsi::Runtime &rt,
1872
+ const jsi::Value &thisValue,
1873
+ const jsi::Value *arguments,
1874
+ size_t count) -> jsi::Value
1875
+ {
1876
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1877
+ }
1878
+ );
1879
+ }
1880
+
1881
+ static jsi::Value intoRust(
1882
+ jsi::Runtime &rt,
1883
+ std::shared_ptr<CallInvoker> callInvoker,
1884
+ const jsi::Value &thisValue,
1885
+ const jsi::Value *args,
1886
+ size_t count,
1887
+ UniffiForeignFutureCompleteVoid func) {
1888
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1889
+ // then call the rs_callback with those arguments.
1890
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<UniffiForeignFutureResultVoid>::fromJs(rt, callInvoker, args[1])
1891
+ );
1892
+
1893
+
1894
+ return jsi::Value::undefined();
1895
+ }
1896
+ };
1897
+ } // namespace uniffi::el_ffi
1898
+ // Implementation of CallbackInterfaceClone for vtable field uniffi_clone in VTableCallbackInterfaceStreamHandler
1899
+
1900
+
1901
+ // Callback function: uniffi::el_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacestreamhandler::UniffiCallbackInterfaceClone
1902
+ //
1903
+ // We have the following constraints:
1904
+ // - we need to pass a function pointer to Rust.
1905
+ // - we need a jsi::Runtime and jsi::Function to call into JS.
1906
+ // - function pointers can't store state, so we can't use a lamda.
1907
+ //
1908
+ // For this, we store a lambda as a global, as `rsLambda`. The `callback` function calls
1909
+ // the lambda, which itself calls the `body` which then calls into JS.
1910
+ //
1911
+ // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
1912
+ // future.
1913
+ namespace uniffi::el_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacestreamhandler {
1914
+ using namespace facebook;
1915
+
1916
+ // We need to store a lambda in a global so we can call it from
1917
+ // a function pointer. The function pointer is passed to Rust.
1918
+ static std::function<void(uint64_t, uint64_t*)> rsLambda = nullptr;
1919
+
1920
+ // This is the main body of the callback. It's called from the lambda,
1921
+ // which itself is called from the callback function which is passed to Rust.
1922
+ static void body(jsi::Runtime &rt,
1923
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
1924
+ std::shared_ptr<jsi::Value> callbackValue
1925
+ ,uint64_t rs_handle
1926
+ , uint64_t* uniffi_direct_return) {
1927
+
1928
+ // Convert the arguments from Rust, into jsi::Values.
1929
+ // We'll use the Bridging class to do this…
1930
+ auto js_handle = uniffi_jsi::Bridging<uint64_t>::toJs(rt, callInvoker, rs_handle);
1931
+
1932
+ // Now we are ready to call the callback.
1933
+ // We are already on the JS thread, because this `body` function was
1934
+ // invoked from the CallInvoker.
1935
+ try {
1936
+ // Getting the callback function
1937
+ auto cb = callbackValue->asObject(rt).asFunction(rt);
1938
+ auto uniffiResult = cb.call(rt, js_handle
1939
+ );
1940
+
1941
+
1942
+
1943
+
1944
+ // Write the direct return value back to the caller.
1945
+ if (uniffi_direct_return != nullptr) {
1946
+ *uniffi_direct_return = uniffi_jsi::Bridging<uint64_t>::fromJs(
1947
+ rt, callInvoker, uniffiResult
1948
+ );
1949
+ }
1950
+ } catch (const jsi::JSError &error) {
1951
+ std::cout << "Error in callback UniffiCallbackInterfaceClone: "
1952
+ << error.what() << std::endl;
1953
+ throw error;
1954
+ }
1955
+ }
1956
+
1957
+ static uint64_t callback(uint64_t rs_handle) {
1958
+ // If the runtime has shutdown, then there is no point in trying to
1959
+ // call into Javascript. BUT how do we tell if the runtime has shutdown?
1960
+ //
1961
+ // Answer: the module destructor calls into callback `cleanup` method,
1962
+ // which nulls out the rsLamda.
1963
+ //
1964
+ // If rsLamda is null, then there is no runtime to call into.
1965
+ if (rsLambda == nullptr) {
1966
+ // This only occurs when destructors are calling into Rust free/drop,
1967
+ // which causes the JS callback to be dropped.
1968
+ return 0;
1969
+ }
1970
+ uint64_t uniffi_result = 0;
1971
+
1972
+ // The runtime, the actual callback jsi::funtion, and the callInvoker
1973
+ // are all in the lambda.
1974
+ rsLambda(
1975
+ rs_handle,
1976
+ &uniffi_result);
1977
+ return uniffi_result;
1978
+ }
1979
+
1980
+ [[maybe_unused]] static UniffiCallbackInterfaceClone
1981
+ makeCallbackFunction( // uniffi::el_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacestreamhandler
1982
+ jsi::Runtime &rt,
1983
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
1984
+ const jsi::Value &value) {
1985
+ if (rsLambda != nullptr) {
1986
+ // `makeCallbackFunction` is called in two circumstances:
1987
+ //
1988
+ // 1. at startup, when initializing callback interface vtables.
1989
+ // 2. when polling futures. This happens at least once per future that is
1990
+ // exposed to Javascript. We know that this is always the same function,
1991
+ // `uniffiFutureContinuationCallback` in `async-rust-calls.ts`.
1992
+ //
1993
+ // We can therefore return the callback function without making anything
1994
+ // new if we've been initialized already.
1995
+ return callback;
1996
+ }
1997
+ auto callbackFunction = value.asObject(rt).asFunction(rt);
1998
+ auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
1999
+ rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_handle, uint64_t* uniffi_direct_return) {
2000
+ // We immediately make a lambda which will do the work of transforming the
2001
+ // arguments into JSI values and calling the callback.
2002
+ uniffi_runtime::UniffiCallFunc jsLambda = [
2003
+ callInvoker,
2004
+ callbackValue
2005
+ , rs_handle, uniffi_direct_return](jsi::Runtime &rt) mutable {
2006
+ body(rt, callInvoker, callbackValue
2007
+ , rs_handle, uniffi_direct_return);
2008
+ };
2009
+ // We'll then call that lambda from the callInvoker which will
2010
+ // look after calling it on the correct thread.
2011
+ callInvoker->invokeBlocking(rt, jsLambda);
2012
+ };
2013
+ return callback;
2014
+ }
2015
+
2016
+ // This method is called from the destructor of NativeElFfi, which only happens
2017
+ // when the jsi::Runtime is being destroyed.
2018
+ static void cleanup() {
2019
+ // The lambda holds a reference to the the Runtime, so when this is nulled out,
2020
+ // then the pointer will no longer be left dangling.
2021
+ rsLambda = nullptr;
2022
+ }
2023
+ } // namespace uniffi::el_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacestreamhandler
2024
+ // Implementation of CallbackInterfaceStreamHandlerMethod0 for vtable field on_token in VTableCallbackInterfaceStreamHandler
2025
+
2026
+
2027
+ // Callback function: uniffi::el_ffi::cb::callbackinterfacestreamhandlermethod0::vtablecallbackinterfacestreamhandler::UniffiCallbackInterfaceStreamHandlerMethod0
2028
+ //
2029
+ // We have the following constraints:
2030
+ // - we need to pass a function pointer to Rust.
2031
+ // - we need a jsi::Runtime and jsi::Function to call into JS.
2032
+ // - function pointers can't store state, so we can't use a lamda.
2033
+ //
2034
+ // For this, we store a lambda as a global, as `rsLambda`. The `callback` function calls
2035
+ // the lambda, which itself calls the `body` which then calls into JS.
2036
+ //
2037
+ // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
2038
+ // future.
2039
+ namespace uniffi::el_ffi::cb::callbackinterfacestreamhandlermethod0::vtablecallbackinterfacestreamhandler {
2040
+ using namespace facebook;
2041
+
2042
+ // We need to store a lambda in a global so we can call it from
2043
+ // a function pointer. The function pointer is passed to Rust.
2044
+ static std::function<void(uint64_t, RustBuffer, void *, RustCallStatus*)> rsLambda = nullptr;
2045
+
2046
+ // This is the main body of the callback. It's called from the lambda,
2047
+ // which itself is called from the callback function which is passed to Rust.
2048
+ static void body(jsi::Runtime &rt,
2049
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
2050
+ std::shared_ptr<jsi::Value> callbackValue
2051
+ ,uint64_t rs_uniffiHandle
2052
+ ,RustBuffer rs_token
2053
+ ,void * rs_uniffiOutReturn, RustCallStatus* uniffi_call_status) {
2054
+
2055
+ // Convert the arguments from Rust, into jsi::Values.
2056
+ // We'll use the Bridging class to do this…
2057
+ auto js_uniffiHandle = uniffi_jsi::Bridging<uint64_t>::toJs(rt, callInvoker, rs_uniffiHandle);
2058
+ auto js_token = uniffi::el_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, rs_token);
2059
+
2060
+ // Now we are ready to call the callback.
2061
+ // We are already on the JS thread, because this `body` function was
2062
+ // invoked from the CallInvoker.
2063
+ try {
2064
+ // Getting the callback function
2065
+ auto cb = callbackValue->asObject(rt).asFunction(rt);
2066
+ auto uniffiResult = cb.call(rt, js_uniffiHandle, js_token
2067
+ );
2068
+
2069
+ // Now copy the result back from JS into the RustCallStatus object.
2070
+ uniffi::el_ffi::Bridging<RustCallStatus>::copyFromJs(rt, callInvoker, uniffiResult, uniffi_call_status);
2071
+
2072
+ if (uniffi_call_status->code != UNIFFI_CALL_STATUS_OK) {
2073
+ // The JS callback finished abnormally, so we cannot retrieve the return value.
2074
+ return;
2075
+ }
2076
+
2077
+
2078
+ } catch (const jsi::JSError &error) {
2079
+ std::cout << "Error in callback UniffiCallbackInterfaceStreamHandlerMethod0: "
2080
+ << error.what() << std::endl;
2081
+ throw error;
2082
+ }
2083
+ }
2084
+
2085
+ static void callback(uint64_t rs_uniffiHandle, RustBuffer rs_token, void * rs_uniffiOutReturn, RustCallStatus* uniffi_call_status) {
2086
+ // If the runtime has shutdown, then there is no point in trying to
2087
+ // call into Javascript. BUT how do we tell if the runtime has shutdown?
2088
+ //
2089
+ // Answer: the module destructor calls into callback `cleanup` method,
2090
+ // which nulls out the rsLamda.
2091
+ //
2092
+ // If rsLamda is null, then there is no runtime to call into.
2093
+ if (rsLambda == nullptr) {
2094
+ // This only occurs when destructors are calling into Rust free/drop,
2095
+ // which causes the JS callback to be dropped.
2096
+ return;
2097
+ }
2098
+
2099
+ // The runtime, the actual callback jsi::funtion, and the callInvoker
2100
+ // are all in the lambda.
2101
+ rsLambda(
2102
+ rs_uniffiHandle,
2103
+ rs_token,
2104
+ rs_uniffiOutReturn, uniffi_call_status);
2105
+ }
2106
+
2107
+ [[maybe_unused]] static UniffiCallbackInterfaceStreamHandlerMethod0
2108
+ makeCallbackFunction( // uniffi::el_ffi::cb::callbackinterfacestreamhandlermethod0::vtablecallbackinterfacestreamhandler
2109
+ jsi::Runtime &rt,
2110
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
2111
+ const jsi::Value &value) {
2112
+ if (rsLambda != nullptr) {
2113
+ // `makeCallbackFunction` is called in two circumstances:
2114
+ //
2115
+ // 1. at startup, when initializing callback interface vtables.
2116
+ // 2. when polling futures. This happens at least once per future that is
2117
+ // exposed to Javascript. We know that this is always the same function,
2118
+ // `uniffiFutureContinuationCallback` in `async-rust-calls.ts`.
2119
+ //
2120
+ // We can therefore return the callback function without making anything
2121
+ // new if we've been initialized already.
2122
+ return callback;
2123
+ }
2124
+ auto callbackFunction = value.asObject(rt).asFunction(rt);
2125
+ auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
2126
+ rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_uniffiHandle, RustBuffer rs_token, void * rs_uniffiOutReturn, RustCallStatus* uniffi_call_status) {
2127
+ // We immediately make a lambda which will do the work of transforming the
2128
+ // arguments into JSI values and calling the callback.
2129
+ uniffi_runtime::UniffiCallFunc jsLambda = [
2130
+ callInvoker,
2131
+ callbackValue
2132
+ , rs_uniffiHandle
2133
+ , rs_token
2134
+ , rs_uniffiOutReturn, uniffi_call_status](jsi::Runtime &rt) mutable {
2135
+ body(rt, callInvoker, callbackValue
2136
+ , rs_uniffiHandle
2137
+ , rs_token
2138
+ , rs_uniffiOutReturn, uniffi_call_status);
2139
+ };
2140
+ // We'll then call that lambda from the callInvoker which will
2141
+ // look after calling it on the correct thread.
2142
+ callInvoker->invokeBlocking(rt, jsLambda);
2143
+ };
2144
+ return callback;
2145
+ }
2146
+
2147
+ // This method is called from the destructor of NativeElFfi, which only happens
2148
+ // when the jsi::Runtime is being destroyed.
2149
+ static void cleanup() {
2150
+ // The lambda holds a reference to the the Runtime, so when this is nulled out,
2151
+ // then the pointer will no longer be left dangling.
2152
+ rsLambda = nullptr;
2153
+ }
2154
+ } // namespace uniffi::el_ffi::cb::callbackinterfacestreamhandlermethod0::vtablecallbackinterfacestreamhandler
2155
+ namespace uniffi::el_ffi {
2156
+ using namespace facebook;
2157
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
2158
+
2159
+ template <> struct Bridging<UniffiVTableCallbackInterfaceStreamHandler> {
2160
+ static UniffiVTableCallbackInterfaceStreamHandler fromJs(jsi::Runtime &rt,
2161
+ std::shared_ptr<CallInvoker> callInvoker,
2162
+ const jsi::Value &jsValue
2163
+ ) {
2164
+ // Check if the input is an object
2165
+ if (!jsValue.isObject()) {
2166
+ throw jsi::JSError(rt, "Expected an object for UniffiVTableCallbackInterfaceStreamHandler");
2167
+ }
2168
+
2169
+ // Get the object from the jsi::Value
2170
+ auto jsObject = jsValue.getObject(rt);
2171
+
2172
+ // Create the vtable struct
2173
+ UniffiVTableCallbackInterfaceStreamHandler rsObject;
2174
+
2175
+ // Create the vtable from the js callbacks.
2176
+ rsObject.uniffi_free = uniffi::el_ffi::st::vtablecallbackinterfacestreamhandler::vtablecallbackinterfacestreamhandler::free::makeCallbackFunction(
2177
+ rt, callInvoker, jsObject.getProperty(rt, "uniffi_free")
2178
+ );
2179
+ rsObject.uniffi_clone = uniffi::el_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacestreamhandler::makeCallbackFunction(
2180
+ rt, callInvoker, jsObject.getProperty(rt, "uniffi_clone")
2181
+ );
2182
+ rsObject.on_token = uniffi::el_ffi::cb::callbackinterfacestreamhandlermethod0::vtablecallbackinterfacestreamhandler::makeCallbackFunction(
2183
+ rt, callInvoker, jsObject.getProperty(rt, "on_token")
2184
+ );
2185
+
2186
+ return rsObject;
2187
+ }
2188
+ };
2189
+
2190
+ } // namespace uniffi::el_ffi
2191
+
2192
+
2193
+ namespace uniffi::el_ffi {
2194
+ using namespace facebook;
2195
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
2196
+
2197
+ template <> struct Bridging<UniffiRustFutureContinuationCallback> {
2198
+ static UniffiRustFutureContinuationCallback fromJs(
2199
+ jsi::Runtime &rt,
2200
+ std::shared_ptr<CallInvoker> callInvoker,
2201
+ const jsi::Value &value
2202
+ ) {
2203
+ try {
2204
+ return uniffi::el_ffi::cb::rustfuturecontinuationcallback::makeCallbackFunction(
2205
+ rt,
2206
+ callInvoker,
2207
+ value
2208
+ );
2209
+ } catch (const std::logic_error &e) {
2210
+ throw jsi::JSError(rt, e.what());
2211
+ }
2212
+ }
2213
+ };
2214
+
2215
+ } // namespace uniffi::el_ffi
2216
+
2217
+ NativeElFfi::NativeElFfi(
2218
+ jsi::Runtime &rt,
2219
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> invoker
2220
+ ) : callInvoker(invoker), props() {
2221
+ // Map from Javascript names to the cpp names
2222
+ props["ubrn_uniffi_internal_fn_func_ffi__string_to_byte_length"] = jsi::Function::createFromHostFunction(
2223
+ rt,
2224
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_to_byte_length"),
2225
+ 1,
2226
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2227
+ return this->cpp_uniffi_internal_fn_func_ffi__string_to_byte_length(rt, thisVal, args, count);
2228
+ }
2229
+ );
2230
+ props["ubrn_uniffi_internal_fn_func_ffi__string_to_buffer"] = jsi::Function::createFromHostFunction(
2231
+ rt,
2232
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_to_buffer"),
2233
+ 1,
2234
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2235
+ return this->cpp_uniffi_internal_fn_func_ffi__string_to_buffer(rt, thisVal, args, count);
2236
+ }
2237
+ );
2238
+ props["ubrn_uniffi_internal_fn_func_ffi__string_from_buffer"] = jsi::Function::createFromHostFunction(
2239
+ rt,
2240
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_from_buffer"),
2241
+ 1,
2242
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2243
+ return this->cpp_uniffi_internal_fn_func_ffi__string_from_buffer(rt, thisVal, args, count);
2244
+ }
2245
+ );
2246
+ props["ubrn_uniffi_internal_fn_func_ffi__read_string_from_buffer"] = jsi::Function::createFromHostFunction(
2247
+ rt,
2248
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__read_string_from_buffer"),
2249
+ 3,
2250
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2251
+ return this->cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(rt, thisVal, args, count);
2252
+ }
2253
+ );
2254
+ props["ubrn_uniffi_el_ffi_fn_clone_edgellm"] = jsi::Function::createFromHostFunction(
2255
+ rt,
2256
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_fn_clone_edgellm"),
2257
+ 1,
2258
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2259
+ return this->cpp_uniffi_el_ffi_fn_clone_edgellm(rt, thisVal, args, count);
2260
+ }
2261
+ );
2262
+ props["ubrn_uniffi_el_ffi_fn_free_edgellm"] = jsi::Function::createFromHostFunction(
2263
+ rt,
2264
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_fn_free_edgellm"),
2265
+ 1,
2266
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2267
+ return this->cpp_uniffi_el_ffi_fn_free_edgellm(rt, thisVal, args, count);
2268
+ }
2269
+ );
2270
+ props["ubrn_uniffi_el_ffi_fn_constructor_edgellm_cloud"] = jsi::Function::createFromHostFunction(
2271
+ rt,
2272
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_fn_constructor_edgellm_cloud"),
2273
+ 2,
2274
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2275
+ return this->cpp_uniffi_el_ffi_fn_constructor_edgellm_cloud(rt, thisVal, args, count);
2276
+ }
2277
+ );
2278
+ props["ubrn_uniffi_el_ffi_fn_constructor_edgellm_local"] = jsi::Function::createFromHostFunction(
2279
+ rt,
2280
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_fn_constructor_edgellm_local"),
2281
+ 1,
2282
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2283
+ return this->cpp_uniffi_el_ffi_fn_constructor_edgellm_local(rt, thisVal, args, count);
2284
+ }
2285
+ );
2286
+ props["ubrn_uniffi_el_ffi_fn_method_edgellm_ask"] = jsi::Function::createFromHostFunction(
2287
+ rt,
2288
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_fn_method_edgellm_ask"),
2289
+ 2,
2290
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2291
+ return this->cpp_uniffi_el_ffi_fn_method_edgellm_ask(rt, thisVal, args, count);
2292
+ }
2293
+ );
2294
+ props["ubrn_uniffi_el_ffi_fn_method_edgellm_ask_stream_cb"] = jsi::Function::createFromHostFunction(
2295
+ rt,
2296
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_fn_method_edgellm_ask_stream_cb"),
2297
+ 3,
2298
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2299
+ return this->cpp_uniffi_el_ffi_fn_method_edgellm_ask_stream_cb(rt, thisVal, args, count);
2300
+ }
2301
+ );
2302
+ props["ubrn_uniffi_el_ffi_fn_method_edgellm_reset"] = jsi::Function::createFromHostFunction(
2303
+ rt,
2304
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_fn_method_edgellm_reset"),
2305
+ 1,
2306
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2307
+ return this->cpp_uniffi_el_ffi_fn_method_edgellm_reset(rt, thisVal, args, count);
2308
+ }
2309
+ );
2310
+ props["ubrn_uniffi_el_ffi_fn_init_callback_vtable_streamhandler"] = jsi::Function::createFromHostFunction(
2311
+ rt,
2312
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_fn_init_callback_vtable_streamhandler"),
2313
+ 1,
2314
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2315
+ return this->cpp_uniffi_el_ffi_fn_init_callback_vtable_streamhandler(rt, thisVal, args, count);
2316
+ }
2317
+ );
2318
+ props["ubrn_uniffi_el_ffi_checksum_method_edgellm_ask"] = jsi::Function::createFromHostFunction(
2319
+ rt,
2320
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_checksum_method_edgellm_ask"),
2321
+ 0,
2322
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2323
+ return this->cpp_uniffi_el_ffi_checksum_method_edgellm_ask(rt, thisVal, args, count);
2324
+ }
2325
+ );
2326
+ props["ubrn_uniffi_el_ffi_checksum_method_edgellm_ask_stream_cb"] = jsi::Function::createFromHostFunction(
2327
+ rt,
2328
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_checksum_method_edgellm_ask_stream_cb"),
2329
+ 0,
2330
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2331
+ return this->cpp_uniffi_el_ffi_checksum_method_edgellm_ask_stream_cb(rt, thisVal, args, count);
2332
+ }
2333
+ );
2334
+ props["ubrn_uniffi_el_ffi_checksum_method_edgellm_reset"] = jsi::Function::createFromHostFunction(
2335
+ rt,
2336
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_checksum_method_edgellm_reset"),
2337
+ 0,
2338
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2339
+ return this->cpp_uniffi_el_ffi_checksum_method_edgellm_reset(rt, thisVal, args, count);
2340
+ }
2341
+ );
2342
+ props["ubrn_uniffi_el_ffi_checksum_constructor_edgellm_cloud"] = jsi::Function::createFromHostFunction(
2343
+ rt,
2344
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_checksum_constructor_edgellm_cloud"),
2345
+ 0,
2346
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2347
+ return this->cpp_uniffi_el_ffi_checksum_constructor_edgellm_cloud(rt, thisVal, args, count);
2348
+ }
2349
+ );
2350
+ props["ubrn_uniffi_el_ffi_checksum_constructor_edgellm_local"] = jsi::Function::createFromHostFunction(
2351
+ rt,
2352
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_checksum_constructor_edgellm_local"),
2353
+ 0,
2354
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2355
+ return this->cpp_uniffi_el_ffi_checksum_constructor_edgellm_local(rt, thisVal, args, count);
2356
+ }
2357
+ );
2358
+ props["ubrn_uniffi_el_ffi_checksum_method_streamhandler_on_token"] = jsi::Function::createFromHostFunction(
2359
+ rt,
2360
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_el_ffi_checksum_method_streamhandler_on_token"),
2361
+ 0,
2362
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2363
+ return this->cpp_uniffi_el_ffi_checksum_method_streamhandler_on_token(rt, thisVal, args, count);
2364
+ }
2365
+ );
2366
+ props["ubrn_ffi_el_ffi_uniffi_contract_version"] = jsi::Function::createFromHostFunction(
2367
+ rt,
2368
+ jsi::PropNameID::forAscii(rt, "ubrn_ffi_el_ffi_uniffi_contract_version"),
2369
+ 0,
2370
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2371
+ return this->cpp_ffi_el_ffi_uniffi_contract_version(rt, thisVal, args, count);
2372
+ }
2373
+ );
2374
+ props["ubrn_uniffi_internal_fn_method_edgellm_ffi__bless_pointer"] = jsi::Function::createFromHostFunction(
2375
+ rt,
2376
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_method_edgellm_ffi__bless_pointer"),
2377
+ 1,
2378
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2379
+ return this->cpp_uniffi_internal_fn_method_edgellm_ffi__bless_pointer(rt, thisVal, args, count);
2380
+ }
2381
+ );
2382
+
2383
+ // `rustbuffer_alloc(n)` -> Uint8Array view over Rust-owned memory of capacity `n`.
2384
+ // `rustbuffer_free(view)` -> hands the underlying (ptr, capacity) back to the
2385
+ // crate's `rustbuffer_free`. Together they let JS allocate buffers that the
2386
+ // codegen-emitted lowering path can fill in place and ship to Rust without copying.
2387
+ props["rustbuffer_alloc"] = jsi::Function::createFromHostFunction(
2388
+ rt,
2389
+ jsi::PropNameID::forAscii(rt, "rustbuffer_alloc"),
2390
+ 1,
2391
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2392
+ if (count < 1 || !args[0].isNumber()) {
2393
+ throw jsi::JSError(rt, "rustbuffer_alloc expected a number argument");
2394
+ }
2395
+ double size = args[0].asNumber();
2396
+ if (size < 0) {
2397
+ throw jsi::JSError(rt, "rustbuffer_alloc: size must be non-negative");
2398
+ }
2399
+ if (size > INT32_MAX) {
2400
+ throw jsi::JSError(rt, "rustbuffer_alloc: size exceeds INT32_MAX");
2401
+ }
2402
+ auto rb = uniffi::el_ffi::Bridging<RustBuffer>::rustbuffer_alloc(static_cast<int32_t>(size));
2403
+ if (rb.data == nullptr) {
2404
+ throw jsi::JSError(rt, "rustbuffer_alloc failed: alloc returned null");
2405
+ }
2406
+ // Non-owning view over Rust-allocated memory; CMutableBuffer's destructor
2407
+ // is the default and does not free `rb.data`. JS must call rustbuffer_free
2408
+ // explicitly before dropping the reference.
2409
+ auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(
2410
+ rb.data, static_cast<size_t>(rb.capacity));
2411
+ // Wrap as Uint8Array so JS can index/assign bytes directly.
2412
+ return jsi::Value(
2413
+ rt, uniffi_jsi::arraybufferToUint8Array(
2414
+ rt, jsi::ArrayBuffer(rt, payload)));
2415
+ }
2416
+ );
2417
+
2418
+ props["rustbuffer_free"] = jsi::Function::createFromHostFunction(
2419
+ rt,
2420
+ jsi::PropNameID::forAscii(rt, "rustbuffer_free"),
2421
+ 1,
2422
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2423
+ if (count < 1 || !args[0].isObject()) {
2424
+ throw jsi::JSError(rt, "rustbuffer_free expected a Uint8Array argument");
2425
+ }
2426
+ auto view = args[0].asObject(rt);
2427
+ auto byteLength =
2428
+ static_cast<size_t>(view.getProperty(rt, "byteLength").asNumber());
2429
+ // Empty views were never allocated by `rustbuffer_alloc`; nothing
2430
+ // to free. Bail out before reading buffer/byteOffset/capacity to
2431
+ // skip three JSI property traversals on the empty path.
2432
+ if (byteLength == 0) {
2433
+ return jsi::Value::undefined();
2434
+ }
2435
+ // Capacity resolution:
2436
+ // * For a view from `rustbuffer_alloc(n)`, `byteLength == n == capacity`,
2437
+ // and no `__ubrnRustCapacity` hint was set.
2438
+ // * For a view from a lift-handoff, the codegen-emitted
2439
+ // `Bridging<RustBuffer>::toJs` set `byteLength = len` and stashed
2440
+ // the original `capacity` on `__ubrnRustCapacity` whenever
2441
+ // `capacity != len`.
2442
+ // So: prefer the hint, fall back to byteLength.
2443
+ size_t capacity = byteLength;
2444
+ if (view.hasProperty(rt, uniffi_jsi::kUbrnRustCapacity)) {
2445
+ capacity = static_cast<size_t>(
2446
+ view.getProperty(rt, uniffi_jsi::kUbrnRustCapacity).asNumber());
2447
+ }
2448
+ auto buffer = view.getPropertyAsObject(rt, "buffer").getArrayBuffer(rt);
2449
+ auto byteOffset =
2450
+ static_cast<size_t>(view.getProperty(rt, "byteOffset").asNumber());
2451
+ // Honour byteOffset for safety (defensive; currently always 0).
2452
+ RustBuffer rb {
2453
+ .capacity = static_cast<uint64_t>(capacity),
2454
+ .len = 0,
2455
+ .data = buffer.data(rt) + byteOffset,
2456
+ };
2457
+ uniffi::el_ffi::Bridging<RustBuffer>::rustbuffer_free(rb);
2458
+ return jsi::Value::undefined();
2459
+ }
2460
+ );
2461
+ }
2462
+
2463
+ void NativeElFfi::registerModule(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> callInvoker) {
2464
+ auto invoker = std::make_shared<uniffi_runtime::UniffiCallInvoker>(callInvoker);
2465
+ auto tm = std::make_shared<NativeElFfi>(rt, invoker);
2466
+ auto obj = rt.global().createFromHostObject(rt, tm);
2467
+ rt.global().setProperty(rt, "NativeElFfi", obj);
2468
+ }
2469
+
2470
+ void NativeElFfi::unregisterModule(jsi::Runtime &rt) {
2471
+ uniffi::el_ffi::registry::clearRegistry();
2472
+ }
2473
+
2474
+ jsi::Value NativeElFfi::get(jsi::Runtime& rt, const jsi::PropNameID& name) {
2475
+ try {
2476
+ return jsi::Value(rt, props.at(name.utf8(rt)));
2477
+ }
2478
+ catch (std::out_of_range &) {
2479
+ return jsi::Value::undefined();
2480
+ }
2481
+ }
2482
+
2483
+ std::vector<jsi::PropNameID> NativeElFfi::getPropertyNames(jsi::Runtime& rt) {
2484
+ std::vector<jsi::PropNameID> rval;
2485
+ for (auto& [key, value] : props) {
2486
+ rval.push_back(jsi::PropNameID::forUtf8(rt, key));
2487
+ }
2488
+ return rval;
2489
+ }
2490
+
2491
+ void NativeElFfi::set(jsi::Runtime& rt, const jsi::PropNameID& name, const jsi::Value& value) {
2492
+ props.insert_or_assign(name.utf8(rt), &value);
2493
+ }
2494
+
2495
+ NativeElFfi::~NativeElFfi() {
2496
+ // Cleanup for callback function RustFutureContinuationCallback
2497
+ uniffi::el_ffi::cb::rustfuturecontinuationcallback::cleanup();
2498
+ // Cleanup for callback function ForeignFutureDroppedCallback
2499
+ uniffi::el_ffi::cb::foreignfuturedroppedcallback::cleanup();
2500
+ // Cleanup for "free" callback function CallbackInterfaceFree
2501
+ uniffi::el_ffi::st::vtablecallbackinterfacestreamhandler::vtablecallbackinterfacestreamhandler::free::cleanup();
2502
+ uniffi::el_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacestreamhandler::cleanup();
2503
+ uniffi::el_ffi::cb::callbackinterfacestreamhandlermethod0::vtablecallbackinterfacestreamhandler::cleanup();
2504
+ }
2505
+
2506
+ // Utility functions for serialization/deserialization of strings.
2507
+ jsi::Value NativeElFfi::cpp_uniffi_internal_fn_func_ffi__string_to_byte_length(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2508
+ return uniffi_jsi::Bridging<std::string>::string_to_bytelength(rt, args[0]);
2509
+ }
2510
+
2511
+ jsi::Value NativeElFfi::cpp_uniffi_internal_fn_func_ffi__string_to_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2512
+ return uniffi_jsi::Bridging<std::string>::string_to_buffer(rt, args[0]);
2513
+ }
2514
+
2515
+ jsi::Value NativeElFfi::cpp_uniffi_internal_fn_func_ffi__string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2516
+ return uniffi_jsi::Bridging<std::string>::string_from_buffer(rt, args[0]);
2517
+ }
2518
+
2519
+ jsi::Value NativeElFfi::cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2520
+ return uniffi_jsi::Bridging<std::string>::read_string_from_buffer(rt, args[0], args[1], args[2]);
2521
+ }jsi::Value NativeElFfi::cpp_uniffi_internal_fn_method_edgellm_ffi__bless_pointer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2522
+ auto pointer = uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]);
2523
+ auto static destructor = [](uint64_t p) {
2524
+ RustCallStatus status = {0};
2525
+ uniffi_el_ffi_fn_free_edgellm(p, &status);
2526
+ };
2527
+ auto ptrObj = std::make_shared<uniffi_jsi::DestructibleObject>(pointer, destructor);
2528
+ auto obj = jsi::Object::createFromHostObject(rt, ptrObj);
2529
+ return jsi::Value(rt, obj);
2530
+ }
2531
+
2532
+ // Methods calling directly into the uniffi generated C API of the Rust crate.
2533
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_fn_clone_edgellm(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2534
+ RustCallStatus status = uniffi::el_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
2535
+ auto value = uniffi_el_ffi_fn_clone_edgellm(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
2536
+ &status
2537
+ );
2538
+ uniffi::el_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
2539
+
2540
+
2541
+ return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker, value);
2542
+ }
2543
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_fn_free_edgellm(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2544
+ RustCallStatus status = uniffi::el_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
2545
+ uniffi_el_ffi_fn_free_edgellm(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
2546
+ &status
2547
+ );
2548
+ uniffi::el_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
2549
+
2550
+
2551
+ return jsi::Value::undefined();
2552
+ }
2553
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_fn_constructor_edgellm_cloud(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2554
+ RustCallStatus status = uniffi::el_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
2555
+ auto value = uniffi_el_ffi_fn_constructor_edgellm_cloud(uniffi::el_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]),
2556
+ &status
2557
+ );
2558
+ uniffi::el_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
2559
+
2560
+
2561
+ return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker, value);
2562
+ }
2563
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_fn_constructor_edgellm_local(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2564
+ RustCallStatus status = uniffi::el_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
2565
+ auto value = uniffi_el_ffi_fn_constructor_edgellm_local(uniffi::el_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[0]),
2566
+ &status
2567
+ );
2568
+ uniffi::el_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
2569
+
2570
+
2571
+ return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker, value);
2572
+ }
2573
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_fn_method_edgellm_ask(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2574
+ RustCallStatus status = uniffi::el_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
2575
+ auto value = uniffi_el_ffi_fn_method_edgellm_ask(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]),
2576
+ &status
2577
+ );
2578
+ uniffi::el_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
2579
+
2580
+
2581
+ return uniffi::el_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, value);
2582
+ }
2583
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_fn_method_edgellm_ask_stream_cb(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2584
+ RustCallStatus status = uniffi::el_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
2585
+ uniffi_el_ffi_fn_method_edgellm_ask_stream_cb(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::el_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]), uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[2]),
2586
+ &status
2587
+ );
2588
+ uniffi::el_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
2589
+
2590
+
2591
+ return jsi::Value::undefined();
2592
+ }
2593
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_fn_method_edgellm_reset(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2594
+ RustCallStatus status = uniffi::el_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
2595
+ uniffi_el_ffi_fn_method_edgellm_reset(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
2596
+ &status
2597
+ );
2598
+ uniffi::el_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
2599
+
2600
+
2601
+ return jsi::Value::undefined();
2602
+ }
2603
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_fn_init_callback_vtable_streamhandler(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2604
+ auto vtableInstance =
2605
+ uniffi::el_ffi::Bridging<UniffiVTableCallbackInterfaceStreamHandler>::fromJs(
2606
+ rt,
2607
+ callInvoker,
2608
+ args[0]
2609
+ );
2610
+
2611
+ std::lock_guard<std::mutex> lock(uniffi::el_ffi::registry::vtableMutex);
2612
+ uniffi_el_ffi_fn_init_callback_vtable_streamhandler(
2613
+ uniffi::el_ffi::registry::putTable(
2614
+ "UniffiVTableCallbackInterfaceStreamHandler",
2615
+ vtableInstance
2616
+ )
2617
+ );
2618
+ return jsi::Value::undefined();
2619
+ }
2620
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_checksum_method_edgellm_ask(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2621
+ auto value = uniffi_el_ffi_checksum_method_edgellm_ask(
2622
+ );
2623
+
2624
+
2625
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
2626
+ }
2627
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_checksum_method_edgellm_ask_stream_cb(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2628
+ auto value = uniffi_el_ffi_checksum_method_edgellm_ask_stream_cb(
2629
+ );
2630
+
2631
+
2632
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
2633
+ }
2634
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_checksum_method_edgellm_reset(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2635
+ auto value = uniffi_el_ffi_checksum_method_edgellm_reset(
2636
+ );
2637
+
2638
+
2639
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
2640
+ }
2641
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_checksum_constructor_edgellm_cloud(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2642
+ auto value = uniffi_el_ffi_checksum_constructor_edgellm_cloud(
2643
+ );
2644
+
2645
+
2646
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
2647
+ }
2648
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_checksum_constructor_edgellm_local(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2649
+ auto value = uniffi_el_ffi_checksum_constructor_edgellm_local(
2650
+ );
2651
+
2652
+
2653
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
2654
+ }
2655
+ jsi::Value NativeElFfi::cpp_uniffi_el_ffi_checksum_method_streamhandler_on_token(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2656
+ auto value = uniffi_el_ffi_checksum_method_streamhandler_on_token(
2657
+ );
2658
+
2659
+
2660
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
2661
+ }
2662
+ jsi::Value NativeElFfi::cpp_ffi_el_ffi_uniffi_contract_version(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
2663
+ auto value = ffi_el_ffi_uniffi_contract_version(
2664
+ );
2665
+
2666
+
2667
+ return uniffi_jsi::Bridging<uint32_t>::toJs(rt, callInvoker, value);
2668
+ }