@minip2p/react-native 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/android/CMakeLists.txt +1 -0
  2. package/android/src/main/jniLibs/arm64-v8a/libminip2p_ffi.so +0 -0
  3. package/android/src/main/jniLibs/x86_64/libminip2p_ffi.so +0 -0
  4. package/build/Minip2pFfi.xcframework/Info.plist +4 -4
  5. package/build/Minip2pFfi.xcframework/ios-arm64/libminip2p_ffi.a +2 -2
  6. package/build/Minip2pFfi.xcframework/ios-arm64-simulator/libminip2p_ffi.a +2 -2
  7. package/cpp/generated/minip2p_ffi_core.cpp +1999 -0
  8. package/cpp/generated/minip2p_ffi_core.hpp +51 -0
  9. package/cpp/react-native-minip2p.cpp +2 -0
  10. package/lib/module/adapter.js +64 -61
  11. package/lib/module/adapter.js.map +1 -1
  12. package/lib/module/generated/minip2p_ffi.js +47 -3284
  13. package/lib/module/generated/minip2p_ffi.js.map +1 -1
  14. package/lib/module/generated/minip2p_ffi_core-ffi.js +20 -0
  15. package/lib/module/generated/minip2p_ffi_core-ffi.js.map +1 -0
  16. package/lib/module/generated/minip2p_ffi_core.js +3342 -0
  17. package/lib/module/generated/minip2p_ffi_core.js.map +1 -0
  18. package/lib/module/low-level.js +1 -0
  19. package/lib/module/low-level.js.map +1 -1
  20. package/lib/module/native.js +5 -1
  21. package/lib/module/native.js.map +1 -1
  22. package/lib/typescript/src/adapter.d.ts.map +1 -1
  23. package/lib/typescript/src/generated/minip2p_ffi.d.ts +2 -3394
  24. package/lib/typescript/src/generated/minip2p_ffi.d.ts.map +1 -1
  25. package/lib/typescript/src/generated/minip2p_ffi_core-ffi.d.ts +67 -0
  26. package/lib/typescript/src/generated/minip2p_ffi_core-ffi.d.ts.map +1 -0
  27. package/lib/typescript/src/generated/minip2p_ffi_core.d.ts +3417 -0
  28. package/lib/typescript/src/generated/minip2p_ffi_core.d.ts.map +1 -0
  29. package/lib/typescript/src/low-level.d.ts +1 -0
  30. package/lib/typescript/src/low-level.d.ts.map +1 -1
  31. package/lib/typescript/src/native.d.ts +3 -0
  32. package/lib/typescript/src/native.d.ts.map +1 -1
  33. package/package.json +4 -4
  34. package/src/adapter.ts +85 -67
  35. package/src/generated/minip2p_ffi.ts +36 -3860
  36. package/src/generated/minip2p_ffi_core-ffi.ts +97 -0
  37. package/src/generated/minip2p_ffi_core.ts +3939 -0
  38. package/src/low-level.ts +1 -0
  39. package/src/native.tsx +4 -0
  40. package/lib/module/event-drain.js +0 -71
  41. package/lib/module/event-drain.js.map +0 -1
  42. package/lib/typescript/src/event-drain.d.ts +0 -10
  43. package/lib/typescript/src/event-drain.d.ts.map +0 -1
  44. package/src/event-drain.ts +0 -80
@@ -0,0 +1,1999 @@
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 "minip2p_ffi_core.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
+ RustBuffer ffi_minip2p_ffi_core_rustbuffer_alloc(
133
+ uint64_t size,
134
+ RustCallStatus *uniffi_out_err
135
+ );
136
+ RustBuffer ffi_minip2p_ffi_core_rustbuffer_from_bytes(
137
+ ForeignBytes bytes,
138
+ RustCallStatus *uniffi_out_err
139
+ );
140
+ void ffi_minip2p_ffi_core_rustbuffer_free(
141
+ RustBuffer buf,
142
+ RustCallStatus *uniffi_out_err
143
+ );
144
+ RustBuffer ffi_minip2p_ffi_core_rustbuffer_reserve(
145
+ RustBuffer buf,
146
+ uint64_t additional,
147
+ RustCallStatus *uniffi_out_err
148
+ );
149
+ void ffi_minip2p_ffi_core_rust_future_poll_u8(
150
+ /*handle*/ uint64_t handle,
151
+ UniffiRustFutureContinuationCallback callback,
152
+ /*handle*/ uint64_t callback_data
153
+ );
154
+ void ffi_minip2p_ffi_core_rust_future_cancel_u8(
155
+ /*handle*/ uint64_t handle
156
+ );
157
+ void ffi_minip2p_ffi_core_rust_future_free_u8(
158
+ /*handle*/ uint64_t handle
159
+ );
160
+ uint8_t ffi_minip2p_ffi_core_rust_future_complete_u8(
161
+ /*handle*/ uint64_t handle,
162
+ RustCallStatus *uniffi_out_err
163
+ );
164
+ void ffi_minip2p_ffi_core_rust_future_poll_i8(
165
+ /*handle*/ uint64_t handle,
166
+ UniffiRustFutureContinuationCallback callback,
167
+ /*handle*/ uint64_t callback_data
168
+ );
169
+ void ffi_minip2p_ffi_core_rust_future_cancel_i8(
170
+ /*handle*/ uint64_t handle
171
+ );
172
+ void ffi_minip2p_ffi_core_rust_future_free_i8(
173
+ /*handle*/ uint64_t handle
174
+ );
175
+ int8_t ffi_minip2p_ffi_core_rust_future_complete_i8(
176
+ /*handle*/ uint64_t handle,
177
+ RustCallStatus *uniffi_out_err
178
+ );
179
+ void ffi_minip2p_ffi_core_rust_future_poll_u16(
180
+ /*handle*/ uint64_t handle,
181
+ UniffiRustFutureContinuationCallback callback,
182
+ /*handle*/ uint64_t callback_data
183
+ );
184
+ void ffi_minip2p_ffi_core_rust_future_cancel_u16(
185
+ /*handle*/ uint64_t handle
186
+ );
187
+ void ffi_minip2p_ffi_core_rust_future_free_u16(
188
+ /*handle*/ uint64_t handle
189
+ );
190
+ uint16_t ffi_minip2p_ffi_core_rust_future_complete_u16(
191
+ /*handle*/ uint64_t handle,
192
+ RustCallStatus *uniffi_out_err
193
+ );
194
+ void ffi_minip2p_ffi_core_rust_future_poll_i16(
195
+ /*handle*/ uint64_t handle,
196
+ UniffiRustFutureContinuationCallback callback,
197
+ /*handle*/ uint64_t callback_data
198
+ );
199
+ void ffi_minip2p_ffi_core_rust_future_cancel_i16(
200
+ /*handle*/ uint64_t handle
201
+ );
202
+ void ffi_minip2p_ffi_core_rust_future_free_i16(
203
+ /*handle*/ uint64_t handle
204
+ );
205
+ int16_t ffi_minip2p_ffi_core_rust_future_complete_i16(
206
+ /*handle*/ uint64_t handle,
207
+ RustCallStatus *uniffi_out_err
208
+ );
209
+ void ffi_minip2p_ffi_core_rust_future_poll_u32(
210
+ /*handle*/ uint64_t handle,
211
+ UniffiRustFutureContinuationCallback callback,
212
+ /*handle*/ uint64_t callback_data
213
+ );
214
+ void ffi_minip2p_ffi_core_rust_future_cancel_u32(
215
+ /*handle*/ uint64_t handle
216
+ );
217
+ void ffi_minip2p_ffi_core_rust_future_free_u32(
218
+ /*handle*/ uint64_t handle
219
+ );
220
+ uint32_t ffi_minip2p_ffi_core_rust_future_complete_u32(
221
+ /*handle*/ uint64_t handle,
222
+ RustCallStatus *uniffi_out_err
223
+ );
224
+ void ffi_minip2p_ffi_core_rust_future_poll_i32(
225
+ /*handle*/ uint64_t handle,
226
+ UniffiRustFutureContinuationCallback callback,
227
+ /*handle*/ uint64_t callback_data
228
+ );
229
+ void ffi_minip2p_ffi_core_rust_future_cancel_i32(
230
+ /*handle*/ uint64_t handle
231
+ );
232
+ void ffi_minip2p_ffi_core_rust_future_free_i32(
233
+ /*handle*/ uint64_t handle
234
+ );
235
+ int32_t ffi_minip2p_ffi_core_rust_future_complete_i32(
236
+ /*handle*/ uint64_t handle,
237
+ RustCallStatus *uniffi_out_err
238
+ );
239
+ void ffi_minip2p_ffi_core_rust_future_poll_u64(
240
+ /*handle*/ uint64_t handle,
241
+ UniffiRustFutureContinuationCallback callback,
242
+ /*handle*/ uint64_t callback_data
243
+ );
244
+ void ffi_minip2p_ffi_core_rust_future_cancel_u64(
245
+ /*handle*/ uint64_t handle
246
+ );
247
+ void ffi_minip2p_ffi_core_rust_future_free_u64(
248
+ /*handle*/ uint64_t handle
249
+ );
250
+ uint64_t ffi_minip2p_ffi_core_rust_future_complete_u64(
251
+ /*handle*/ uint64_t handle,
252
+ RustCallStatus *uniffi_out_err
253
+ );
254
+ void ffi_minip2p_ffi_core_rust_future_poll_i64(
255
+ /*handle*/ uint64_t handle,
256
+ UniffiRustFutureContinuationCallback callback,
257
+ /*handle*/ uint64_t callback_data
258
+ );
259
+ void ffi_minip2p_ffi_core_rust_future_cancel_i64(
260
+ /*handle*/ uint64_t handle
261
+ );
262
+ void ffi_minip2p_ffi_core_rust_future_free_i64(
263
+ /*handle*/ uint64_t handle
264
+ );
265
+ int64_t ffi_minip2p_ffi_core_rust_future_complete_i64(
266
+ /*handle*/ uint64_t handle,
267
+ RustCallStatus *uniffi_out_err
268
+ );
269
+ void ffi_minip2p_ffi_core_rust_future_poll_f32(
270
+ /*handle*/ uint64_t handle,
271
+ UniffiRustFutureContinuationCallback callback,
272
+ /*handle*/ uint64_t callback_data
273
+ );
274
+ void ffi_minip2p_ffi_core_rust_future_cancel_f32(
275
+ /*handle*/ uint64_t handle
276
+ );
277
+ void ffi_minip2p_ffi_core_rust_future_free_f32(
278
+ /*handle*/ uint64_t handle
279
+ );
280
+ float ffi_minip2p_ffi_core_rust_future_complete_f32(
281
+ /*handle*/ uint64_t handle,
282
+ RustCallStatus *uniffi_out_err
283
+ );
284
+ void ffi_minip2p_ffi_core_rust_future_poll_f64(
285
+ /*handle*/ uint64_t handle,
286
+ UniffiRustFutureContinuationCallback callback,
287
+ /*handle*/ uint64_t callback_data
288
+ );
289
+ void ffi_minip2p_ffi_core_rust_future_cancel_f64(
290
+ /*handle*/ uint64_t handle
291
+ );
292
+ void ffi_minip2p_ffi_core_rust_future_free_f64(
293
+ /*handle*/ uint64_t handle
294
+ );
295
+ double ffi_minip2p_ffi_core_rust_future_complete_f64(
296
+ /*handle*/ uint64_t handle,
297
+ RustCallStatus *uniffi_out_err
298
+ );
299
+ void ffi_minip2p_ffi_core_rust_future_poll_rust_buffer(
300
+ /*handle*/ uint64_t handle,
301
+ UniffiRustFutureContinuationCallback callback,
302
+ /*handle*/ uint64_t callback_data
303
+ );
304
+ void ffi_minip2p_ffi_core_rust_future_cancel_rust_buffer(
305
+ /*handle*/ uint64_t handle
306
+ );
307
+ void ffi_minip2p_ffi_core_rust_future_free_rust_buffer(
308
+ /*handle*/ uint64_t handle
309
+ );
310
+ RustBuffer ffi_minip2p_ffi_core_rust_future_complete_rust_buffer(
311
+ /*handle*/ uint64_t handle,
312
+ RustCallStatus *uniffi_out_err
313
+ );
314
+ void ffi_minip2p_ffi_core_rust_future_poll_void(
315
+ /*handle*/ uint64_t handle,
316
+ UniffiRustFutureContinuationCallback callback,
317
+ /*handle*/ uint64_t callback_data
318
+ );
319
+ void ffi_minip2p_ffi_core_rust_future_cancel_void(
320
+ /*handle*/ uint64_t handle
321
+ );
322
+ void ffi_minip2p_ffi_core_rust_future_free_void(
323
+ /*handle*/ uint64_t handle
324
+ );
325
+ void ffi_minip2p_ffi_core_rust_future_complete_void(
326
+ /*handle*/ uint64_t handle,
327
+ RustCallStatus *uniffi_out_err
328
+ );
329
+ uint32_t ffi_minip2p_ffi_core_uniffi_contract_version(
330
+ );
331
+ }
332
+
333
+
334
+ namespace uniffi::minip2p_ffi_core {
335
+ template <typename T> struct Bridging;
336
+
337
+ using namespace facebook;
338
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
339
+
340
+ template <typename T> struct Bridging<ReferenceHolder<T>> {
341
+ static jsi::Value jsNew(jsi::Runtime &rt) {
342
+ auto holder = jsi::Object(rt);
343
+ return holder;
344
+ }
345
+ static T fromJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker,
346
+ const jsi::Value &value) {
347
+ auto obj = value.asObject(rt);
348
+ if (obj.hasProperty(rt, "pointee")) {
349
+ auto pointee = obj.getProperty(rt, "pointee");
350
+ return uniffi::minip2p_ffi_core::Bridging<T>::fromJs(rt, callInvoker, pointee);
351
+ }
352
+ throw jsi::JSError(
353
+ rt,
354
+ "Expected ReferenceHolder to have a pointee property. This is likely a bug in uniffi-bindgen-react-native"
355
+ );
356
+ }
357
+ };
358
+ } // namespace uniffi::minip2p_ffi_core
359
+ namespace uniffi::minip2p_ffi_core {
360
+ using namespace facebook;
361
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
362
+
363
+ template <> struct Bridging<RustBuffer> {
364
+ static RustBuffer rustbuffer_alloc(int32_t size) {
365
+ RustCallStatus status = { UNIFFI_CALL_STATUS_OK };
366
+ return ffi_minip2p_ffi_core_rustbuffer_alloc(
367
+ size,
368
+ &status
369
+ );
370
+ }
371
+
372
+ static void rustbuffer_free(RustBuffer buf) {
373
+ RustCallStatus status = { UNIFFI_CALL_STATUS_OK };
374
+ ffi_minip2p_ffi_core_rustbuffer_free(
375
+ buf,
376
+ &status
377
+ );
378
+ }
379
+
380
+ static RustBuffer rustbuffer_from_bytes(ForeignBytes bytes) {
381
+ RustCallStatus status = { UNIFFI_CALL_STATUS_OK };
382
+ return ffi_minip2p_ffi_core_rustbuffer_from_bytes(
383
+ bytes,
384
+ &status
385
+ );
386
+ }
387
+
388
+ static RustBuffer fromJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker>,
389
+ const jsi::Value &value) {
390
+ try {
391
+ auto obj = value.asObject(rt);
392
+
393
+ // Adoption vs copy. Two kinds of view arrive here:
394
+ //
395
+ // * Library-owned views from `rustbuffer_alloc`. Codegen allocates one,
396
+ // fills it in place, and ships it as an argument — and never frees a
397
+ // lowered argument, while the view's backing `CMutableBuffer` is
398
+ // non-owning (its destructor leaves `data` alone). Such a view carries
399
+ // a capacity hint (stamped by `rustbuffer_alloc` in the wrapper). We
400
+ // *adopt* it: hand the existing allocation to the callee, which frees
401
+ // it. Copying instead would orphan the allocation and leak one whole
402
+ // payload per call.
403
+ // * Ordinary JS-owned arrays, which carry no hint. These are *copied*
404
+ // into a fresh library allocation — they are not ours to give away.
405
+ //
406
+ // On adoption we reset the hint to 0 so a later `rustbuffer_free(view)` is
407
+ // a no-op rather than a double free.
408
+ if (obj.hasProperty(rt, uniffi_jsi::kUbrnRustCapacity)) {
409
+ auto capacity = static_cast<uint64_t>(
410
+ obj.getProperty(rt, uniffi_jsi::kUbrnRustCapacity).asNumber());
411
+ if (capacity == 0) {
412
+ // Hint present but zeroed: the view was already adopted by a previous
413
+ // call and its memory has been freed. Reading it would be a
414
+ // use-after-free, so refuse rather than hand over a dangling pointer.
415
+ throw jsi::JSError(
416
+ rt,
417
+ "RustBuffer argument was already consumed by a previous FFI call");
418
+ }
419
+ auto arrayBuffer =
420
+ obj.getPropertyAsObject(rt, "buffer").getArrayBuffer(rt);
421
+ auto byteOffset =
422
+ static_cast<size_t>(obj.getProperty(rt, "byteOffset").asNumber());
423
+ auto byteLength =
424
+ static_cast<size_t>(obj.getProperty(rt, "byteLength").asNumber());
425
+ obj.setProperty(rt, uniffi_jsi::kUbrnRustCapacity, jsi::Value(0));
426
+ return RustBuffer{
427
+ .capacity = capacity,
428
+ .len = static_cast<uint64_t>(byteLength),
429
+ .data = arrayBuffer.data(rt) + byteOffset,
430
+ };
431
+ }
432
+
433
+ auto buffer = uniffi_jsi::Bridging<jsi::ArrayBuffer>::value_to_arraybuffer(rt, value);
434
+ auto bytes = ForeignBytes{
435
+ .len = static_cast<int32_t>(buffer.length(rt)),
436
+ .data = buffer.data(rt),
437
+ };
438
+
439
+ // No hint: an ordinary JS-owned array. Rust scaffolding copies the bytes
440
+ // to make the RustBuffer; the copy is destroyed when the callee
441
+ // deserializes its arguments.
442
+ auto buf = rustbuffer_from_bytes(bytes);
443
+ return buf;
444
+ } catch (const std::logic_error &e) {
445
+ throw jsi::JSError(rt, e.what());
446
+ }
447
+ }
448
+
449
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker>,
450
+ RustBuffer buf) {
451
+ // View-handoff: hand JS a `Uint8Array` view aliasing the Rust-owned bytes
452
+ // (no boundary copy). The single mandatory copy now happens inside
453
+ // `converter.lift(view)` (string decode, byte-array `set`, field-by-field
454
+ // record reads). The codegen-emitted try/finally calls `rustbuffer_free`
455
+ // on the view after `lift` returns, releasing the Rust allocation.
456
+ //
457
+ // Capacity hint: Rust may return a buffer where `capacity > len`. The
458
+ // view's `byteLength` is `len` (so converters that decode the whole view
459
+ // see only the message bytes), but `rustbuffer_free` needs `capacity` to
460
+ // free correctly. We stash `capacity` on the view via a string-keyed
461
+ // property when it differs from `len`; the JSI `rustbufferFree` host
462
+ // function reads it back and falls back to `byteLength` for views from
463
+ // `rustbufferAlloc(n)` where `byteLength == capacity` already.
464
+ //
465
+ // CMutableBuffer is non-owning here: its destructor leaves `buf.data`
466
+ // alone. Only the codegen-emitted `rustbuffer_free` path frees it.
467
+ auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(
468
+ buf.data, static_cast<size_t>(buf.len));
469
+ auto view = uniffi_jsi::arraybufferToUint8Array(
470
+ rt, jsi::ArrayBuffer(rt, payload));
471
+ if (buf.capacity != static_cast<uint64_t>(buf.len)) {
472
+ view.setProperty(rt, uniffi_jsi::kUbrnRustCapacity,
473
+ jsi::Value(static_cast<double>(buf.capacity)));
474
+ }
475
+ return jsi::Value(rt, view);
476
+ }
477
+ };
478
+
479
+ } // namespace uniffi::minip2p_ffi_core
480
+
481
+ namespace uniffi::minip2p_ffi_core {
482
+ using namespace facebook;
483
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
484
+
485
+ template <> struct Bridging<RustCallStatus> {
486
+ static jsi::Value jsSuccess(jsi::Runtime &rt) {
487
+ auto statusObject = jsi::Object(rt);
488
+ statusObject.setProperty(rt, "code", jsi::Value(rt, UNIFFI_CALL_STATUS_OK));
489
+ return statusObject;
490
+ }
491
+ static RustCallStatus rustSuccess(jsi::Runtime &rt) {
492
+ return {UNIFFI_CALL_STATUS_OK};
493
+ }
494
+ static void copyIntoJs(jsi::Runtime &rt,
495
+ std::shared_ptr<CallInvoker> callInvoker,
496
+ const RustCallStatus status,
497
+ const jsi::Value &jsStatus) {
498
+ auto statusObject = jsStatus.asObject(rt);
499
+ if (status.error_buf.data != nullptr) {
500
+ // The error path is NOT wrapped in the codegen-emitted try/finally that
501
+ // covers normal returns: `errorBuf` is read by the runtime's call-status
502
+ // dispatcher (rust-call.ts) which throws straight to the user without
503
+ // ever calling `rustbuffer_free`. Switching this site to view-handoff
504
+ // would leak the Rust allocation, so we keep the copy semantics here:
505
+ // copy the bytes into a JS-owned ArrayBuffer and free the Rust buffer
506
+ // immediately. The errorBuf is small (a serialized error variant) and
507
+ // only allocated on the cold error path, so the boundary copy is cheap.
508
+ auto len = static_cast<size_t>(status.error_buf.len);
509
+ uint8_t *bytes = new uint8_t[len];
510
+ std::memcpy(bytes, status.error_buf.data, len);
511
+ auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(bytes, len);
512
+ auto view = uniffi_jsi::arraybufferToUint8Array(
513
+ rt, jsi::ArrayBuffer(rt, payload));
514
+ statusObject.setProperty(rt, "errorBuf", view);
515
+ Bridging<RustBuffer>::rustbuffer_free(status.error_buf);
516
+ }
517
+ if (status.code != UNIFFI_CALL_STATUS_OK) {
518
+ auto code =
519
+ uniffi_jsi::Bridging<uint8_t>::toJs(rt, callInvoker, status.code);
520
+ statusObject.setProperty(rt, "code", code);
521
+ }
522
+ }
523
+
524
+ static RustCallStatus fromJs(jsi::Runtime &rt,
525
+ std::shared_ptr<CallInvoker> invoker,
526
+ const jsi::Value &jsStatus) {
527
+ RustCallStatus status;
528
+ auto statusObject = jsStatus.asObject(rt);
529
+ if (statusObject.hasProperty(rt, "errorBuf")) {
530
+ auto rbuf = statusObject.getProperty(rt, "errorBuf");
531
+ status.error_buf =
532
+ Bridging<RustBuffer>::fromJs(rt, invoker, rbuf);
533
+ }
534
+ if (statusObject.hasProperty(rt, "code")) {
535
+ auto code = statusObject.getProperty(rt, "code");
536
+ status.code = uniffi_jsi::Bridging<uint8_t>::fromJs(rt, invoker, code);
537
+ }
538
+ return status;
539
+ }
540
+
541
+ static void copyFromJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> invoker,
542
+ const jsi::Value &jsStatus, RustCallStatus *status) {
543
+ auto statusObject = jsStatus.asObject(rt);
544
+ if (statusObject.hasProperty(rt, "errorBuf")) {
545
+ auto rbuf = statusObject.getProperty(rt, "errorBuf");
546
+ status->error_buf =
547
+ Bridging<RustBuffer>::fromJs(rt, invoker, rbuf);
548
+ }
549
+ if (statusObject.hasProperty(rt, "code")) {
550
+ auto code = statusObject.getProperty(rt, "code");
551
+ status->code = uniffi_jsi::Bridging<uint8_t>::fromJs(rt, invoker, code);
552
+ }
553
+ }
554
+ };
555
+
556
+ } // namespace uniffi::minip2p_ffi_core
557
+ // In other uniffi bindings, it is assumed that the foreign language holds on
558
+ // to the vtable, which the Rust just gets a pointer to.
559
+ // Here, we need to hold on to them, but also be able to clear them at just the
560
+ // right time so we can support hot-reloading.
561
+ namespace uniffi::minip2p_ffi_core::registry {
562
+ template <typename T>
563
+ class VTableHolder {
564
+ public:
565
+ T vtable;
566
+ VTableHolder(T v) : vtable(v) {}
567
+ };
568
+
569
+ // Mutex to bind the storage and setting of vtable together.
570
+ // We declare it here, but the lock is taken by callers of the putTable
571
+ // method who are also sending a pointer to Rust.
572
+ static std::mutex vtableMutex;
573
+
574
+ // Registry to hold all vtables so they persist even when JS objects are GC'd.
575
+ // The only reason this exists is to prevent a dangling pointer in the
576
+ // Rust machinery: i.e. we don't need to access or write to this registry
577
+ // after startup.
578
+ // Registry to hold all vtables so they persist even when JS objects are GC'd.
579
+ // Maps string identifiers to vtable holders using type erasure
580
+ static std::unordered_map<std::string, std::shared_ptr<void>> vtableRegistry;
581
+
582
+ // Add a vtable to the registry with an identifier
583
+ template <typename T>
584
+ static T* putTable(std::string_view identifier, T vtable) {
585
+ auto holder = std::make_shared<VTableHolder<T>>(vtable);
586
+ // Store the raw pointer to the vtable before type erasure
587
+ T* rawPtr = &(holder->vtable);
588
+ // Store the holder using type erasure with the string identifier
589
+ vtableRegistry[std::string(identifier)] = std::shared_ptr<void>(holder);
590
+ return rawPtr;
591
+ }
592
+
593
+ // Clear the registry.
594
+ //
595
+ // Conceptually, this is called after teardown of the module (i.e. after
596
+ // teardown of the jsi::Runtime). However, because Rust is dropping callbacks
597
+ // because the Runtime is being torn down, we must keep the registry intact
598
+ // until after the runtime goes away.
599
+ //
600
+ // Therefore, in practice we should call this when the next runtime is
601
+ // being stood up.
602
+ static void clearRegistry() {
603
+ std::lock_guard<std::mutex> lock(vtableMutex);
604
+ vtableRegistry.clear();
605
+ }
606
+ } // namespace uniffi::minip2p_ffi_core::registry
607
+
608
+ // This calls into Rust.
609
+ // Implementation of callback function calling from Rust to JS RustFutureContinuationCallback
610
+
611
+ // Callback function: uniffi::minip2p_ffi_core::cb::rustfuturecontinuationcallback::UniffiRustFutureContinuationCallback
612
+ //
613
+ // We have the following constraints:
614
+ // - we need to pass a function pointer to Rust.
615
+ // - we need a jsi::Runtime and jsi::Function to call into JS.
616
+ // - function pointers can't store state, so we can't use a lamda.
617
+ //
618
+ // For this, we store a lambda as a global, as `rsLambda`. The `callback` function calls
619
+ // the lambda, which itself calls the `body` which then calls into JS.
620
+ //
621
+ // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
622
+ // future.
623
+ namespace uniffi::minip2p_ffi_core::cb::rustfuturecontinuationcallback {
624
+ using namespace facebook;
625
+
626
+ // We need to store a lambda in a global so we can call it from
627
+ // a function pointer. The function pointer is passed to Rust.
628
+ static std::function<void(uint64_t, int8_t)> rsLambda = nullptr;
629
+
630
+ // This is the main body of the callback. It's called from the lambda,
631
+ // which itself is called from the callback function which is passed to Rust.
632
+ static void body(jsi::Runtime &rt,
633
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
634
+ std::shared_ptr<jsi::Value> callbackValue
635
+ ,uint64_t rs_data
636
+ ,int8_t rs_pollResult) {
637
+
638
+ // Convert the arguments from Rust, into jsi::Values.
639
+ // We'll use the Bridging class to do this…
640
+ auto js_data = uniffi_jsi::Bridging<uint64_t>::toJs(rt, callInvoker, rs_data);
641
+ auto js_pollResult = uniffi_jsi::Bridging<int8_t>::toJs(rt, callInvoker, rs_pollResult);
642
+
643
+ // Now we are ready to call the callback.
644
+ // We are already on the JS thread, because this `body` function was
645
+ // invoked from the CallInvoker.
646
+ try {
647
+ // Getting the callback function
648
+ auto cb = callbackValue->asObject(rt).asFunction(rt);
649
+ auto uniffiResult = cb.call(rt, js_data, js_pollResult
650
+ );
651
+
652
+
653
+
654
+
655
+ } catch (const jsi::JSError &error) {
656
+ std::cout << "Error in callback UniffiRustFutureContinuationCallback: "
657
+ << error.what() << std::endl;
658
+ throw error;
659
+ }
660
+ }
661
+
662
+ static void callback(uint64_t rs_data, int8_t rs_pollResult) {
663
+ // If the runtime has shutdown, then there is no point in trying to
664
+ // call into Javascript. BUT how do we tell if the runtime has shutdown?
665
+ //
666
+ // Answer: the module destructor calls into callback `cleanup` method,
667
+ // which nulls out the rsLamda.
668
+ //
669
+ // If rsLamda is null, then there is no runtime to call into.
670
+ if (rsLambda == nullptr) {
671
+ // This only occurs when destructors are calling into Rust free/drop,
672
+ // which causes the JS callback to be dropped.
673
+ return;
674
+ }
675
+
676
+ // The runtime, the actual callback jsi::funtion, and the callInvoker
677
+ // are all in the lambda.
678
+ rsLambda(
679
+ rs_data,
680
+ rs_pollResult);
681
+ }
682
+
683
+ [[maybe_unused]] static UniffiRustFutureContinuationCallback
684
+ makeCallbackFunction( // uniffi::minip2p_ffi_core::cb::rustfuturecontinuationcallback
685
+ jsi::Runtime &rt,
686
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
687
+ const jsi::Value &value) {
688
+ if (rsLambda != nullptr) {
689
+ // `makeCallbackFunction` is called in two circumstances:
690
+ //
691
+ // 1. at startup, when initializing callback interface vtables.
692
+ // 2. when polling futures. This happens at least once per future that is
693
+ // exposed to Javascript. We know that this is always the same function,
694
+ // `uniffiFutureContinuationCallback` in `async-rust-calls.ts`.
695
+ //
696
+ // We can therefore return the callback function without making anything
697
+ // new if we've been initialized already.
698
+ return callback;
699
+ }
700
+ auto callbackFunction = value.asObject(rt).asFunction(rt);
701
+ auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
702
+ rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_data, int8_t rs_pollResult) {
703
+ // We immediately make a lambda which will do the work of transforming the
704
+ // arguments into JSI values and calling the callback.
705
+ uniffi_runtime::UniffiCallFunc jsLambda = [
706
+ callInvoker,
707
+ callbackValue
708
+ , rs_data
709
+ , rs_pollResult](jsi::Runtime &rt) mutable {
710
+ body(rt, callInvoker, callbackValue
711
+ , rs_data
712
+ , rs_pollResult);
713
+ };
714
+ // We'll then call that lambda from the callInvoker which will
715
+ // look after calling it on the correct thread.
716
+
717
+ callInvoker->invokeNonBlocking(rt, jsLambda);
718
+ };
719
+ return callback;
720
+ }
721
+
722
+ // This method is called from the destructor of NativeMinip2pFfiCore, which only happens
723
+ // when the jsi::Runtime is being destroyed.
724
+ static void cleanup() {
725
+ // The lambda holds a reference to the the Runtime, so when this is nulled out,
726
+ // then the pointer will no longer be left dangling.
727
+ rsLambda = nullptr;
728
+ }
729
+ } // namespace uniffi::minip2p_ffi_core::cb::rustfuturecontinuationcallback
730
+ // Implementation of callback function calling from Rust to JS ForeignFutureDroppedCallback
731
+
732
+ // Callback function: uniffi::minip2p_ffi_core::cb::foreignfuturedroppedcallback::UniffiForeignFutureDroppedCallback
733
+ //
734
+ // We have the following constraints:
735
+ // - we need to pass a function pointer to Rust.
736
+ // - we need a jsi::Runtime and jsi::Function to call into JS.
737
+ // - function pointers can't store state, so we can't use a lamda.
738
+ //
739
+ // For this, we store a lambda as a global, as `rsLambda`. The `callback` function calls
740
+ // the lambda, which itself calls the `body` which then calls into JS.
741
+ //
742
+ // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
743
+ // future.
744
+ namespace uniffi::minip2p_ffi_core::cb::foreignfuturedroppedcallback {
745
+ using namespace facebook;
746
+
747
+ // We need to store a lambda in a global so we can call it from
748
+ // a function pointer. The function pointer is passed to Rust.
749
+ static std::function<void(uint64_t)> rsLambda = nullptr;
750
+
751
+ // This is the main body of the callback. It's called from the lambda,
752
+ // which itself is called from the callback function which is passed to Rust.
753
+ static void body(jsi::Runtime &rt,
754
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
755
+ std::shared_ptr<jsi::Value> callbackValue
756
+ ,uint64_t rs_handle) {
757
+
758
+ // Convert the arguments from Rust, into jsi::Values.
759
+ // We'll use the Bridging class to do this…
760
+ auto js_handle = uniffi_jsi::Bridging<uint64_t>::toJs(rt, callInvoker, rs_handle);
761
+
762
+ // Now we are ready to call the callback.
763
+ // We are already on the JS thread, because this `body` function was
764
+ // invoked from the CallInvoker.
765
+ try {
766
+ // Getting the callback function
767
+ auto cb = callbackValue->asObject(rt).asFunction(rt);
768
+ auto uniffiResult = cb.call(rt, js_handle
769
+ );
770
+
771
+
772
+
773
+
774
+ } catch (const jsi::JSError &error) {
775
+ std::cout << "Error in callback UniffiForeignFutureDroppedCallback: "
776
+ << error.what() << std::endl;
777
+ throw error;
778
+ }
779
+ }
780
+
781
+ static void callback(uint64_t rs_handle) {
782
+ // If the runtime has shutdown, then there is no point in trying to
783
+ // call into Javascript. BUT how do we tell if the runtime has shutdown?
784
+ //
785
+ // Answer: the module destructor calls into callback `cleanup` method,
786
+ // which nulls out the rsLamda.
787
+ //
788
+ // If rsLamda is null, then there is no runtime to call into.
789
+ if (rsLambda == nullptr) {
790
+ // This only occurs when destructors are calling into Rust free/drop,
791
+ // which causes the JS callback to be dropped.
792
+ return;
793
+ }
794
+
795
+ // The runtime, the actual callback jsi::funtion, and the callInvoker
796
+ // are all in the lambda.
797
+ rsLambda(
798
+ rs_handle);
799
+ }
800
+
801
+ [[maybe_unused]] static UniffiForeignFutureDroppedCallback
802
+ makeCallbackFunction( // uniffi::minip2p_ffi_core::cb::foreignfuturedroppedcallback
803
+ jsi::Runtime &rt,
804
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
805
+ const jsi::Value &value) {
806
+ if (rsLambda != nullptr) {
807
+ // `makeCallbackFunction` is called in two circumstances:
808
+ //
809
+ // 1. at startup, when initializing callback interface vtables.
810
+ // 2. when polling futures. This happens at least once per future that is
811
+ // exposed to Javascript. We know that this is always the same function,
812
+ // `uniffiFutureContinuationCallback` in `async-rust-calls.ts`.
813
+ //
814
+ // We can therefore return the callback function without making anything
815
+ // new if we've been initialized already.
816
+ return callback;
817
+ }
818
+ auto callbackFunction = value.asObject(rt).asFunction(rt);
819
+ auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
820
+ rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_handle) {
821
+ // We immediately make a lambda which will do the work of transforming the
822
+ // arguments into JSI values and calling the callback.
823
+ uniffi_runtime::UniffiCallFunc jsLambda = [
824
+ callInvoker,
825
+ callbackValue
826
+ , rs_handle](jsi::Runtime &rt) mutable {
827
+ body(rt, callInvoker, callbackValue
828
+ , rs_handle);
829
+ };
830
+ // We'll then call that lambda from the callInvoker which will
831
+ // look after calling it on the correct thread.
832
+
833
+ callInvoker->invokeNonBlocking(rt, jsLambda);
834
+ };
835
+ return callback;
836
+ }
837
+
838
+ // This method is called from the destructor of NativeMinip2pFfiCore, which only happens
839
+ // when the jsi::Runtime is being destroyed.
840
+ static void cleanup() {
841
+ // The lambda holds a reference to the the Runtime, so when this is nulled out,
842
+ // then the pointer will no longer be left dangling.
843
+ rsLambda = nullptr;
844
+ }
845
+ } // namespace uniffi::minip2p_ffi_core::cb::foreignfuturedroppedcallback
846
+ // Implementation of free callback function CallbackInterfaceFree
847
+
848
+ namespace uniffi::minip2p_ffi_core {
849
+ using namespace facebook;
850
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
851
+
852
+ template <> struct Bridging<UniffiForeignFutureDroppedCallbackStruct> {
853
+ static UniffiForeignFutureDroppedCallbackStruct fromJs(jsi::Runtime &rt,
854
+ std::shared_ptr<CallInvoker> callInvoker,
855
+ const jsi::Value &jsValue
856
+ ) {
857
+ // Check if the input is an object
858
+ if (!jsValue.isObject()) {
859
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureDroppedCallbackStruct");
860
+ }
861
+
862
+ // Get the object from the jsi::Value
863
+ auto jsObject = jsValue.getObject(rt);
864
+
865
+ // Create the vtable struct
866
+ UniffiForeignFutureDroppedCallbackStruct rsObject;
867
+
868
+ // Create the vtable from the js callbacks.
869
+ rsObject.handle = uniffi_jsi::Bridging<uint64_t>::fromJs(
870
+ rt, callInvoker,
871
+ jsObject.getProperty(rt, "handle")
872
+ );
873
+ rsObject.free = uniffi::minip2p_ffi_core::cb::foreignfuturedroppedcallback::makeCallbackFunction(
874
+ rt, callInvoker, jsObject.getProperty(rt, "free")
875
+ );
876
+
877
+ return rsObject;
878
+ }
879
+ };
880
+
881
+ } // namespace uniffi::minip2p_ffi_core
882
+ namespace uniffi::minip2p_ffi_core {
883
+ using namespace facebook;
884
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
885
+
886
+ template <> struct Bridging<UniffiForeignFutureResultU8> {
887
+ static UniffiForeignFutureResultU8 fromJs(jsi::Runtime &rt,
888
+ std::shared_ptr<CallInvoker> callInvoker,
889
+ const jsi::Value &jsValue
890
+ ) {
891
+ // Check if the input is an object
892
+ if (!jsValue.isObject()) {
893
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultU8");
894
+ }
895
+
896
+ // Get the object from the jsi::Value
897
+ auto jsObject = jsValue.getObject(rt);
898
+
899
+ // Create the vtable struct
900
+ UniffiForeignFutureResultU8 rsObject;
901
+
902
+ // Create the vtable from the js callbacks.
903
+ rsObject.return_value = uniffi_jsi::Bridging<uint8_t>::fromJs(
904
+ rt, callInvoker,
905
+ jsObject.getProperty(rt, "return_value")
906
+ );
907
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
908
+ rt, callInvoker,
909
+ jsObject.getProperty(rt, "call_status")
910
+ );
911
+
912
+ return rsObject;
913
+ }
914
+ };
915
+
916
+ } // namespace uniffi::minip2p_ffi_core
917
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteU8,
918
+ // passed from Rust to JS as part of async callbacks.
919
+ namespace uniffi::minip2p_ffi_core {
920
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
921
+
922
+ template <> struct Bridging<UniffiForeignFutureCompleteU8> {
923
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteU8 rsCallback) {
924
+ return jsi::Function::createFromHostFunction(
925
+ rt,
926
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteU8"),
927
+ 2,
928
+ [rsCallback, callInvoker](
929
+ jsi::Runtime &rt,
930
+ const jsi::Value &thisValue,
931
+ const jsi::Value *arguments,
932
+ size_t count) -> jsi::Value
933
+ {
934
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
935
+ }
936
+ );
937
+ }
938
+
939
+ static jsi::Value intoRust(
940
+ jsi::Runtime &rt,
941
+ std::shared_ptr<CallInvoker> callInvoker,
942
+ const jsi::Value &thisValue,
943
+ const jsi::Value *args,
944
+ size_t count,
945
+ UniffiForeignFutureCompleteU8 func) {
946
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
947
+ // then call the rs_callback with those arguments.
948
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultU8>::fromJs(rt, callInvoker, args[1])
949
+ );
950
+
951
+
952
+ return jsi::Value::undefined();
953
+ }
954
+ };
955
+ } // namespace uniffi::minip2p_ffi_core
956
+ namespace uniffi::minip2p_ffi_core {
957
+ using namespace facebook;
958
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
959
+
960
+ template <> struct Bridging<UniffiForeignFutureResultI8> {
961
+ static UniffiForeignFutureResultI8 fromJs(jsi::Runtime &rt,
962
+ std::shared_ptr<CallInvoker> callInvoker,
963
+ const jsi::Value &jsValue
964
+ ) {
965
+ // Check if the input is an object
966
+ if (!jsValue.isObject()) {
967
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultI8");
968
+ }
969
+
970
+ // Get the object from the jsi::Value
971
+ auto jsObject = jsValue.getObject(rt);
972
+
973
+ // Create the vtable struct
974
+ UniffiForeignFutureResultI8 rsObject;
975
+
976
+ // Create the vtable from the js callbacks.
977
+ rsObject.return_value = uniffi_jsi::Bridging<int8_t>::fromJs(
978
+ rt, callInvoker,
979
+ jsObject.getProperty(rt, "return_value")
980
+ );
981
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
982
+ rt, callInvoker,
983
+ jsObject.getProperty(rt, "call_status")
984
+ );
985
+
986
+ return rsObject;
987
+ }
988
+ };
989
+
990
+ } // namespace uniffi::minip2p_ffi_core
991
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteI8,
992
+ // passed from Rust to JS as part of async callbacks.
993
+ namespace uniffi::minip2p_ffi_core {
994
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
995
+
996
+ template <> struct Bridging<UniffiForeignFutureCompleteI8> {
997
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteI8 rsCallback) {
998
+ return jsi::Function::createFromHostFunction(
999
+ rt,
1000
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteI8"),
1001
+ 2,
1002
+ [rsCallback, callInvoker](
1003
+ jsi::Runtime &rt,
1004
+ const jsi::Value &thisValue,
1005
+ const jsi::Value *arguments,
1006
+ size_t count) -> jsi::Value
1007
+ {
1008
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1009
+ }
1010
+ );
1011
+ }
1012
+
1013
+ static jsi::Value intoRust(
1014
+ jsi::Runtime &rt,
1015
+ std::shared_ptr<CallInvoker> callInvoker,
1016
+ const jsi::Value &thisValue,
1017
+ const jsi::Value *args,
1018
+ size_t count,
1019
+ UniffiForeignFutureCompleteI8 func) {
1020
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1021
+ // then call the rs_callback with those arguments.
1022
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultI8>::fromJs(rt, callInvoker, args[1])
1023
+ );
1024
+
1025
+
1026
+ return jsi::Value::undefined();
1027
+ }
1028
+ };
1029
+ } // namespace uniffi::minip2p_ffi_core
1030
+ namespace uniffi::minip2p_ffi_core {
1031
+ using namespace facebook;
1032
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1033
+
1034
+ template <> struct Bridging<UniffiForeignFutureResultU16> {
1035
+ static UniffiForeignFutureResultU16 fromJs(jsi::Runtime &rt,
1036
+ std::shared_ptr<CallInvoker> callInvoker,
1037
+ const jsi::Value &jsValue
1038
+ ) {
1039
+ // Check if the input is an object
1040
+ if (!jsValue.isObject()) {
1041
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultU16");
1042
+ }
1043
+
1044
+ // Get the object from the jsi::Value
1045
+ auto jsObject = jsValue.getObject(rt);
1046
+
1047
+ // Create the vtable struct
1048
+ UniffiForeignFutureResultU16 rsObject;
1049
+
1050
+ // Create the vtable from the js callbacks.
1051
+ rsObject.return_value = uniffi_jsi::Bridging<uint16_t>::fromJs(
1052
+ rt, callInvoker,
1053
+ jsObject.getProperty(rt, "return_value")
1054
+ );
1055
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1056
+ rt, callInvoker,
1057
+ jsObject.getProperty(rt, "call_status")
1058
+ );
1059
+
1060
+ return rsObject;
1061
+ }
1062
+ };
1063
+
1064
+ } // namespace uniffi::minip2p_ffi_core
1065
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteU16,
1066
+ // passed from Rust to JS as part of async callbacks.
1067
+ namespace uniffi::minip2p_ffi_core {
1068
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1069
+
1070
+ template <> struct Bridging<UniffiForeignFutureCompleteU16> {
1071
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteU16 rsCallback) {
1072
+ return jsi::Function::createFromHostFunction(
1073
+ rt,
1074
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteU16"),
1075
+ 2,
1076
+ [rsCallback, callInvoker](
1077
+ jsi::Runtime &rt,
1078
+ const jsi::Value &thisValue,
1079
+ const jsi::Value *arguments,
1080
+ size_t count) -> jsi::Value
1081
+ {
1082
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1083
+ }
1084
+ );
1085
+ }
1086
+
1087
+ static jsi::Value intoRust(
1088
+ jsi::Runtime &rt,
1089
+ std::shared_ptr<CallInvoker> callInvoker,
1090
+ const jsi::Value &thisValue,
1091
+ const jsi::Value *args,
1092
+ size_t count,
1093
+ UniffiForeignFutureCompleteU16 func) {
1094
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1095
+ // then call the rs_callback with those arguments.
1096
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultU16>::fromJs(rt, callInvoker, args[1])
1097
+ );
1098
+
1099
+
1100
+ return jsi::Value::undefined();
1101
+ }
1102
+ };
1103
+ } // namespace uniffi::minip2p_ffi_core
1104
+ namespace uniffi::minip2p_ffi_core {
1105
+ using namespace facebook;
1106
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1107
+
1108
+ template <> struct Bridging<UniffiForeignFutureResultI16> {
1109
+ static UniffiForeignFutureResultI16 fromJs(jsi::Runtime &rt,
1110
+ std::shared_ptr<CallInvoker> callInvoker,
1111
+ const jsi::Value &jsValue
1112
+ ) {
1113
+ // Check if the input is an object
1114
+ if (!jsValue.isObject()) {
1115
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultI16");
1116
+ }
1117
+
1118
+ // Get the object from the jsi::Value
1119
+ auto jsObject = jsValue.getObject(rt);
1120
+
1121
+ // Create the vtable struct
1122
+ UniffiForeignFutureResultI16 rsObject;
1123
+
1124
+ // Create the vtable from the js callbacks.
1125
+ rsObject.return_value = uniffi_jsi::Bridging<int16_t>::fromJs(
1126
+ rt, callInvoker,
1127
+ jsObject.getProperty(rt, "return_value")
1128
+ );
1129
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1130
+ rt, callInvoker,
1131
+ jsObject.getProperty(rt, "call_status")
1132
+ );
1133
+
1134
+ return rsObject;
1135
+ }
1136
+ };
1137
+
1138
+ } // namespace uniffi::minip2p_ffi_core
1139
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteI16,
1140
+ // passed from Rust to JS as part of async callbacks.
1141
+ namespace uniffi::minip2p_ffi_core {
1142
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1143
+
1144
+ template <> struct Bridging<UniffiForeignFutureCompleteI16> {
1145
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteI16 rsCallback) {
1146
+ return jsi::Function::createFromHostFunction(
1147
+ rt,
1148
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteI16"),
1149
+ 2,
1150
+ [rsCallback, callInvoker](
1151
+ jsi::Runtime &rt,
1152
+ const jsi::Value &thisValue,
1153
+ const jsi::Value *arguments,
1154
+ size_t count) -> jsi::Value
1155
+ {
1156
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1157
+ }
1158
+ );
1159
+ }
1160
+
1161
+ static jsi::Value intoRust(
1162
+ jsi::Runtime &rt,
1163
+ std::shared_ptr<CallInvoker> callInvoker,
1164
+ const jsi::Value &thisValue,
1165
+ const jsi::Value *args,
1166
+ size_t count,
1167
+ UniffiForeignFutureCompleteI16 func) {
1168
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1169
+ // then call the rs_callback with those arguments.
1170
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultI16>::fromJs(rt, callInvoker, args[1])
1171
+ );
1172
+
1173
+
1174
+ return jsi::Value::undefined();
1175
+ }
1176
+ };
1177
+ } // namespace uniffi::minip2p_ffi_core
1178
+ namespace uniffi::minip2p_ffi_core {
1179
+ using namespace facebook;
1180
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1181
+
1182
+ template <> struct Bridging<UniffiForeignFutureResultU32> {
1183
+ static UniffiForeignFutureResultU32 fromJs(jsi::Runtime &rt,
1184
+ std::shared_ptr<CallInvoker> callInvoker,
1185
+ const jsi::Value &jsValue
1186
+ ) {
1187
+ // Check if the input is an object
1188
+ if (!jsValue.isObject()) {
1189
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultU32");
1190
+ }
1191
+
1192
+ // Get the object from the jsi::Value
1193
+ auto jsObject = jsValue.getObject(rt);
1194
+
1195
+ // Create the vtable struct
1196
+ UniffiForeignFutureResultU32 rsObject;
1197
+
1198
+ // Create the vtable from the js callbacks.
1199
+ rsObject.return_value = uniffi_jsi::Bridging<uint32_t>::fromJs(
1200
+ rt, callInvoker,
1201
+ jsObject.getProperty(rt, "return_value")
1202
+ );
1203
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1204
+ rt, callInvoker,
1205
+ jsObject.getProperty(rt, "call_status")
1206
+ );
1207
+
1208
+ return rsObject;
1209
+ }
1210
+ };
1211
+
1212
+ } // namespace uniffi::minip2p_ffi_core
1213
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteU32,
1214
+ // passed from Rust to JS as part of async callbacks.
1215
+ namespace uniffi::minip2p_ffi_core {
1216
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1217
+
1218
+ template <> struct Bridging<UniffiForeignFutureCompleteU32> {
1219
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteU32 rsCallback) {
1220
+ return jsi::Function::createFromHostFunction(
1221
+ rt,
1222
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteU32"),
1223
+ 2,
1224
+ [rsCallback, callInvoker](
1225
+ jsi::Runtime &rt,
1226
+ const jsi::Value &thisValue,
1227
+ const jsi::Value *arguments,
1228
+ size_t count) -> jsi::Value
1229
+ {
1230
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1231
+ }
1232
+ );
1233
+ }
1234
+
1235
+ static jsi::Value intoRust(
1236
+ jsi::Runtime &rt,
1237
+ std::shared_ptr<CallInvoker> callInvoker,
1238
+ const jsi::Value &thisValue,
1239
+ const jsi::Value *args,
1240
+ size_t count,
1241
+ UniffiForeignFutureCompleteU32 func) {
1242
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1243
+ // then call the rs_callback with those arguments.
1244
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultU32>::fromJs(rt, callInvoker, args[1])
1245
+ );
1246
+
1247
+
1248
+ return jsi::Value::undefined();
1249
+ }
1250
+ };
1251
+ } // namespace uniffi::minip2p_ffi_core
1252
+ namespace uniffi::minip2p_ffi_core {
1253
+ using namespace facebook;
1254
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1255
+
1256
+ template <> struct Bridging<UniffiForeignFutureResultI32> {
1257
+ static UniffiForeignFutureResultI32 fromJs(jsi::Runtime &rt,
1258
+ std::shared_ptr<CallInvoker> callInvoker,
1259
+ const jsi::Value &jsValue
1260
+ ) {
1261
+ // Check if the input is an object
1262
+ if (!jsValue.isObject()) {
1263
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultI32");
1264
+ }
1265
+
1266
+ // Get the object from the jsi::Value
1267
+ auto jsObject = jsValue.getObject(rt);
1268
+
1269
+ // Create the vtable struct
1270
+ UniffiForeignFutureResultI32 rsObject;
1271
+
1272
+ // Create the vtable from the js callbacks.
1273
+ rsObject.return_value = uniffi_jsi::Bridging<int32_t>::fromJs(
1274
+ rt, callInvoker,
1275
+ jsObject.getProperty(rt, "return_value")
1276
+ );
1277
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1278
+ rt, callInvoker,
1279
+ jsObject.getProperty(rt, "call_status")
1280
+ );
1281
+
1282
+ return rsObject;
1283
+ }
1284
+ };
1285
+
1286
+ } // namespace uniffi::minip2p_ffi_core
1287
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteI32,
1288
+ // passed from Rust to JS as part of async callbacks.
1289
+ namespace uniffi::minip2p_ffi_core {
1290
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1291
+
1292
+ template <> struct Bridging<UniffiForeignFutureCompleteI32> {
1293
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteI32 rsCallback) {
1294
+ return jsi::Function::createFromHostFunction(
1295
+ rt,
1296
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteI32"),
1297
+ 2,
1298
+ [rsCallback, callInvoker](
1299
+ jsi::Runtime &rt,
1300
+ const jsi::Value &thisValue,
1301
+ const jsi::Value *arguments,
1302
+ size_t count) -> jsi::Value
1303
+ {
1304
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1305
+ }
1306
+ );
1307
+ }
1308
+
1309
+ static jsi::Value intoRust(
1310
+ jsi::Runtime &rt,
1311
+ std::shared_ptr<CallInvoker> callInvoker,
1312
+ const jsi::Value &thisValue,
1313
+ const jsi::Value *args,
1314
+ size_t count,
1315
+ UniffiForeignFutureCompleteI32 func) {
1316
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1317
+ // then call the rs_callback with those arguments.
1318
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultI32>::fromJs(rt, callInvoker, args[1])
1319
+ );
1320
+
1321
+
1322
+ return jsi::Value::undefined();
1323
+ }
1324
+ };
1325
+ } // namespace uniffi::minip2p_ffi_core
1326
+ namespace uniffi::minip2p_ffi_core {
1327
+ using namespace facebook;
1328
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1329
+
1330
+ template <> struct Bridging<UniffiForeignFutureResultU64> {
1331
+ static UniffiForeignFutureResultU64 fromJs(jsi::Runtime &rt,
1332
+ std::shared_ptr<CallInvoker> callInvoker,
1333
+ const jsi::Value &jsValue
1334
+ ) {
1335
+ // Check if the input is an object
1336
+ if (!jsValue.isObject()) {
1337
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultU64");
1338
+ }
1339
+
1340
+ // Get the object from the jsi::Value
1341
+ auto jsObject = jsValue.getObject(rt);
1342
+
1343
+ // Create the vtable struct
1344
+ UniffiForeignFutureResultU64 rsObject;
1345
+
1346
+ // Create the vtable from the js callbacks.
1347
+ rsObject.return_value = uniffi_jsi::Bridging<uint64_t>::fromJs(
1348
+ rt, callInvoker,
1349
+ jsObject.getProperty(rt, "return_value")
1350
+ );
1351
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1352
+ rt, callInvoker,
1353
+ jsObject.getProperty(rt, "call_status")
1354
+ );
1355
+
1356
+ return rsObject;
1357
+ }
1358
+ };
1359
+
1360
+ } // namespace uniffi::minip2p_ffi_core
1361
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteU64,
1362
+ // passed from Rust to JS as part of async callbacks.
1363
+ namespace uniffi::minip2p_ffi_core {
1364
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1365
+
1366
+ template <> struct Bridging<UniffiForeignFutureCompleteU64> {
1367
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteU64 rsCallback) {
1368
+ return jsi::Function::createFromHostFunction(
1369
+ rt,
1370
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteU64"),
1371
+ 2,
1372
+ [rsCallback, callInvoker](
1373
+ jsi::Runtime &rt,
1374
+ const jsi::Value &thisValue,
1375
+ const jsi::Value *arguments,
1376
+ size_t count) -> jsi::Value
1377
+ {
1378
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1379
+ }
1380
+ );
1381
+ }
1382
+
1383
+ static jsi::Value intoRust(
1384
+ jsi::Runtime &rt,
1385
+ std::shared_ptr<CallInvoker> callInvoker,
1386
+ const jsi::Value &thisValue,
1387
+ const jsi::Value *args,
1388
+ size_t count,
1389
+ UniffiForeignFutureCompleteU64 func) {
1390
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1391
+ // then call the rs_callback with those arguments.
1392
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultU64>::fromJs(rt, callInvoker, args[1])
1393
+ );
1394
+
1395
+
1396
+ return jsi::Value::undefined();
1397
+ }
1398
+ };
1399
+ } // namespace uniffi::minip2p_ffi_core
1400
+ namespace uniffi::minip2p_ffi_core {
1401
+ using namespace facebook;
1402
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1403
+
1404
+ template <> struct Bridging<UniffiForeignFutureResultI64> {
1405
+ static UniffiForeignFutureResultI64 fromJs(jsi::Runtime &rt,
1406
+ std::shared_ptr<CallInvoker> callInvoker,
1407
+ const jsi::Value &jsValue
1408
+ ) {
1409
+ // Check if the input is an object
1410
+ if (!jsValue.isObject()) {
1411
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultI64");
1412
+ }
1413
+
1414
+ // Get the object from the jsi::Value
1415
+ auto jsObject = jsValue.getObject(rt);
1416
+
1417
+ // Create the vtable struct
1418
+ UniffiForeignFutureResultI64 rsObject;
1419
+
1420
+ // Create the vtable from the js callbacks.
1421
+ rsObject.return_value = uniffi_jsi::Bridging<int64_t>::fromJs(
1422
+ rt, callInvoker,
1423
+ jsObject.getProperty(rt, "return_value")
1424
+ );
1425
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1426
+ rt, callInvoker,
1427
+ jsObject.getProperty(rt, "call_status")
1428
+ );
1429
+
1430
+ return rsObject;
1431
+ }
1432
+ };
1433
+
1434
+ } // namespace uniffi::minip2p_ffi_core
1435
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteI64,
1436
+ // passed from Rust to JS as part of async callbacks.
1437
+ namespace uniffi::minip2p_ffi_core {
1438
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1439
+
1440
+ template <> struct Bridging<UniffiForeignFutureCompleteI64> {
1441
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteI64 rsCallback) {
1442
+ return jsi::Function::createFromHostFunction(
1443
+ rt,
1444
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteI64"),
1445
+ 2,
1446
+ [rsCallback, callInvoker](
1447
+ jsi::Runtime &rt,
1448
+ const jsi::Value &thisValue,
1449
+ const jsi::Value *arguments,
1450
+ size_t count) -> jsi::Value
1451
+ {
1452
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1453
+ }
1454
+ );
1455
+ }
1456
+
1457
+ static jsi::Value intoRust(
1458
+ jsi::Runtime &rt,
1459
+ std::shared_ptr<CallInvoker> callInvoker,
1460
+ const jsi::Value &thisValue,
1461
+ const jsi::Value *args,
1462
+ size_t count,
1463
+ UniffiForeignFutureCompleteI64 func) {
1464
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1465
+ // then call the rs_callback with those arguments.
1466
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultI64>::fromJs(rt, callInvoker, args[1])
1467
+ );
1468
+
1469
+
1470
+ return jsi::Value::undefined();
1471
+ }
1472
+ };
1473
+ } // namespace uniffi::minip2p_ffi_core
1474
+ namespace uniffi::minip2p_ffi_core {
1475
+ using namespace facebook;
1476
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1477
+
1478
+ template <> struct Bridging<UniffiForeignFutureResultF32> {
1479
+ static UniffiForeignFutureResultF32 fromJs(jsi::Runtime &rt,
1480
+ std::shared_ptr<CallInvoker> callInvoker,
1481
+ const jsi::Value &jsValue
1482
+ ) {
1483
+ // Check if the input is an object
1484
+ if (!jsValue.isObject()) {
1485
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultF32");
1486
+ }
1487
+
1488
+ // Get the object from the jsi::Value
1489
+ auto jsObject = jsValue.getObject(rt);
1490
+
1491
+ // Create the vtable struct
1492
+ UniffiForeignFutureResultF32 rsObject;
1493
+
1494
+ // Create the vtable from the js callbacks.
1495
+ rsObject.return_value = uniffi_jsi::Bridging<float>::fromJs(
1496
+ rt, callInvoker,
1497
+ jsObject.getProperty(rt, "return_value")
1498
+ );
1499
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1500
+ rt, callInvoker,
1501
+ jsObject.getProperty(rt, "call_status")
1502
+ );
1503
+
1504
+ return rsObject;
1505
+ }
1506
+ };
1507
+
1508
+ } // namespace uniffi::minip2p_ffi_core
1509
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteF32,
1510
+ // passed from Rust to JS as part of async callbacks.
1511
+ namespace uniffi::minip2p_ffi_core {
1512
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1513
+
1514
+ template <> struct Bridging<UniffiForeignFutureCompleteF32> {
1515
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteF32 rsCallback) {
1516
+ return jsi::Function::createFromHostFunction(
1517
+ rt,
1518
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteF32"),
1519
+ 2,
1520
+ [rsCallback, callInvoker](
1521
+ jsi::Runtime &rt,
1522
+ const jsi::Value &thisValue,
1523
+ const jsi::Value *arguments,
1524
+ size_t count) -> jsi::Value
1525
+ {
1526
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1527
+ }
1528
+ );
1529
+ }
1530
+
1531
+ static jsi::Value intoRust(
1532
+ jsi::Runtime &rt,
1533
+ std::shared_ptr<CallInvoker> callInvoker,
1534
+ const jsi::Value &thisValue,
1535
+ const jsi::Value *args,
1536
+ size_t count,
1537
+ UniffiForeignFutureCompleteF32 func) {
1538
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1539
+ // then call the rs_callback with those arguments.
1540
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultF32>::fromJs(rt, callInvoker, args[1])
1541
+ );
1542
+
1543
+
1544
+ return jsi::Value::undefined();
1545
+ }
1546
+ };
1547
+ } // namespace uniffi::minip2p_ffi_core
1548
+ namespace uniffi::minip2p_ffi_core {
1549
+ using namespace facebook;
1550
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1551
+
1552
+ template <> struct Bridging<UniffiForeignFutureResultF64> {
1553
+ static UniffiForeignFutureResultF64 fromJs(jsi::Runtime &rt,
1554
+ std::shared_ptr<CallInvoker> callInvoker,
1555
+ const jsi::Value &jsValue
1556
+ ) {
1557
+ // Check if the input is an object
1558
+ if (!jsValue.isObject()) {
1559
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultF64");
1560
+ }
1561
+
1562
+ // Get the object from the jsi::Value
1563
+ auto jsObject = jsValue.getObject(rt);
1564
+
1565
+ // Create the vtable struct
1566
+ UniffiForeignFutureResultF64 rsObject;
1567
+
1568
+ // Create the vtable from the js callbacks.
1569
+ rsObject.return_value = uniffi_jsi::Bridging<double>::fromJs(
1570
+ rt, callInvoker,
1571
+ jsObject.getProperty(rt, "return_value")
1572
+ );
1573
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1574
+ rt, callInvoker,
1575
+ jsObject.getProperty(rt, "call_status")
1576
+ );
1577
+
1578
+ return rsObject;
1579
+ }
1580
+ };
1581
+
1582
+ } // namespace uniffi::minip2p_ffi_core
1583
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteF64,
1584
+ // passed from Rust to JS as part of async callbacks.
1585
+ namespace uniffi::minip2p_ffi_core {
1586
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1587
+
1588
+ template <> struct Bridging<UniffiForeignFutureCompleteF64> {
1589
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteF64 rsCallback) {
1590
+ return jsi::Function::createFromHostFunction(
1591
+ rt,
1592
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteF64"),
1593
+ 2,
1594
+ [rsCallback, callInvoker](
1595
+ jsi::Runtime &rt,
1596
+ const jsi::Value &thisValue,
1597
+ const jsi::Value *arguments,
1598
+ size_t count) -> jsi::Value
1599
+ {
1600
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1601
+ }
1602
+ );
1603
+ }
1604
+
1605
+ static jsi::Value intoRust(
1606
+ jsi::Runtime &rt,
1607
+ std::shared_ptr<CallInvoker> callInvoker,
1608
+ const jsi::Value &thisValue,
1609
+ const jsi::Value *args,
1610
+ size_t count,
1611
+ UniffiForeignFutureCompleteF64 func) {
1612
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1613
+ // then call the rs_callback with those arguments.
1614
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultF64>::fromJs(rt, callInvoker, args[1])
1615
+ );
1616
+
1617
+
1618
+ return jsi::Value::undefined();
1619
+ }
1620
+ };
1621
+ } // namespace uniffi::minip2p_ffi_core
1622
+ namespace uniffi::minip2p_ffi_core {
1623
+ using namespace facebook;
1624
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1625
+
1626
+ template <> struct Bridging<UniffiForeignFutureResultRustBuffer> {
1627
+ static UniffiForeignFutureResultRustBuffer fromJs(jsi::Runtime &rt,
1628
+ std::shared_ptr<CallInvoker> callInvoker,
1629
+ const jsi::Value &jsValue
1630
+ ) {
1631
+ // Check if the input is an object
1632
+ if (!jsValue.isObject()) {
1633
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultRustBuffer");
1634
+ }
1635
+
1636
+ // Get the object from the jsi::Value
1637
+ auto jsObject = jsValue.getObject(rt);
1638
+
1639
+ // Create the vtable struct
1640
+ UniffiForeignFutureResultRustBuffer rsObject;
1641
+
1642
+ // Create the vtable from the js callbacks.
1643
+ rsObject.return_value = uniffi::minip2p_ffi_core::Bridging<RustBuffer>::fromJs(
1644
+ rt, callInvoker,
1645
+ jsObject.getProperty(rt, "return_value")
1646
+ );
1647
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1648
+ rt, callInvoker,
1649
+ jsObject.getProperty(rt, "call_status")
1650
+ );
1651
+
1652
+ return rsObject;
1653
+ }
1654
+ };
1655
+
1656
+ } // namespace uniffi::minip2p_ffi_core
1657
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteRustBuffer,
1658
+ // passed from Rust to JS as part of async callbacks.
1659
+ namespace uniffi::minip2p_ffi_core {
1660
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1661
+
1662
+ template <> struct Bridging<UniffiForeignFutureCompleteRustBuffer> {
1663
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteRustBuffer rsCallback) {
1664
+ return jsi::Function::createFromHostFunction(
1665
+ rt,
1666
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteRustBuffer"),
1667
+ 2,
1668
+ [rsCallback, callInvoker](
1669
+ jsi::Runtime &rt,
1670
+ const jsi::Value &thisValue,
1671
+ const jsi::Value *arguments,
1672
+ size_t count) -> jsi::Value
1673
+ {
1674
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1675
+ }
1676
+ );
1677
+ }
1678
+
1679
+ static jsi::Value intoRust(
1680
+ jsi::Runtime &rt,
1681
+ std::shared_ptr<CallInvoker> callInvoker,
1682
+ const jsi::Value &thisValue,
1683
+ const jsi::Value *args,
1684
+ size_t count,
1685
+ UniffiForeignFutureCompleteRustBuffer func) {
1686
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1687
+ // then call the rs_callback with those arguments.
1688
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultRustBuffer>::fromJs(rt, callInvoker, args[1])
1689
+ );
1690
+
1691
+
1692
+ return jsi::Value::undefined();
1693
+ }
1694
+ };
1695
+ } // namespace uniffi::minip2p_ffi_core
1696
+ namespace uniffi::minip2p_ffi_core {
1697
+ using namespace facebook;
1698
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1699
+
1700
+ template <> struct Bridging<UniffiForeignFutureResultVoid> {
1701
+ static UniffiForeignFutureResultVoid fromJs(jsi::Runtime &rt,
1702
+ std::shared_ptr<CallInvoker> callInvoker,
1703
+ const jsi::Value &jsValue
1704
+ ) {
1705
+ // Check if the input is an object
1706
+ if (!jsValue.isObject()) {
1707
+ throw jsi::JSError(rt, "Expected an object for UniffiForeignFutureResultVoid");
1708
+ }
1709
+
1710
+ // Get the object from the jsi::Value
1711
+ auto jsObject = jsValue.getObject(rt);
1712
+
1713
+ // Create the vtable struct
1714
+ UniffiForeignFutureResultVoid rsObject;
1715
+
1716
+ // Create the vtable from the js callbacks.
1717
+ rsObject.call_status = uniffi::minip2p_ffi_core::Bridging<RustCallStatus>::fromJs(
1718
+ rt, callInvoker,
1719
+ jsObject.getProperty(rt, "call_status")
1720
+ );
1721
+
1722
+ return rsObject;
1723
+ }
1724
+ };
1725
+
1726
+ } // namespace uniffi::minip2p_ffi_core
1727
+ // Implementation of callback function calling from JS to Rust ForeignFutureCompleteVoid,
1728
+ // passed from Rust to JS as part of async callbacks.
1729
+ namespace uniffi::minip2p_ffi_core {
1730
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1731
+
1732
+ template <> struct Bridging<UniffiForeignFutureCompleteVoid> {
1733
+ static jsi::Value toJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker> callInvoker, UniffiForeignFutureCompleteVoid rsCallback) {
1734
+ return jsi::Function::createFromHostFunction(
1735
+ rt,
1736
+ jsi::PropNameID::forAscii(rt, "--ForeignFutureCompleteVoid"),
1737
+ 2,
1738
+ [rsCallback, callInvoker](
1739
+ jsi::Runtime &rt,
1740
+ const jsi::Value &thisValue,
1741
+ const jsi::Value *arguments,
1742
+ size_t count) -> jsi::Value
1743
+ {
1744
+ return intoRust(rt, callInvoker, thisValue, arguments, count, rsCallback);
1745
+ }
1746
+ );
1747
+ }
1748
+
1749
+ static jsi::Value intoRust(
1750
+ jsi::Runtime &rt,
1751
+ std::shared_ptr<CallInvoker> callInvoker,
1752
+ const jsi::Value &thisValue,
1753
+ const jsi::Value *args,
1754
+ size_t count,
1755
+ UniffiForeignFutureCompleteVoid func) {
1756
+ // Convert the arguments into the Rust, with Bridging<T>::fromJs,
1757
+ // then call the rs_callback with those arguments.
1758
+ func(uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi_core::Bridging<UniffiForeignFutureResultVoid>::fromJs(rt, callInvoker, args[1])
1759
+ );
1760
+
1761
+
1762
+ return jsi::Value::undefined();
1763
+ }
1764
+ };
1765
+ } // namespace uniffi::minip2p_ffi_core
1766
+
1767
+
1768
+ namespace uniffi::minip2p_ffi_core {
1769
+ using namespace facebook;
1770
+ using CallInvoker = uniffi_runtime::UniffiCallInvoker;
1771
+
1772
+ template <> struct Bridging<UniffiRustFutureContinuationCallback> {
1773
+ static UniffiRustFutureContinuationCallback fromJs(
1774
+ jsi::Runtime &rt,
1775
+ std::shared_ptr<CallInvoker> callInvoker,
1776
+ const jsi::Value &value
1777
+ ) {
1778
+ try {
1779
+ return uniffi::minip2p_ffi_core::cb::rustfuturecontinuationcallback::makeCallbackFunction(
1780
+ rt,
1781
+ callInvoker,
1782
+ value
1783
+ );
1784
+ } catch (const std::logic_error &e) {
1785
+ throw jsi::JSError(rt, e.what());
1786
+ }
1787
+ }
1788
+ };
1789
+
1790
+ } // namespace uniffi::minip2p_ffi_core
1791
+
1792
+ NativeMinip2pFfiCore::NativeMinip2pFfiCore(
1793
+ jsi::Runtime &rt,
1794
+ std::shared_ptr<uniffi_runtime::UniffiCallInvoker> invoker
1795
+ ) : callInvoker(invoker), props() {
1796
+ // Map from Javascript names to the cpp names
1797
+ props["ubrn_uniffi_internal_fn_func_ffi__string_to_byte_length"] = jsi::Function::createFromHostFunction(
1798
+ rt,
1799
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_to_byte_length"),
1800
+ 1,
1801
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
1802
+ return this->cpp_uniffi_internal_fn_func_ffi__string_to_byte_length(rt, thisVal, args, count);
1803
+ }
1804
+ );
1805
+ props["ubrn_uniffi_internal_fn_func_ffi__string_to_buffer"] = jsi::Function::createFromHostFunction(
1806
+ rt,
1807
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_to_buffer"),
1808
+ 1,
1809
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
1810
+ return this->cpp_uniffi_internal_fn_func_ffi__string_to_buffer(rt, thisVal, args, count);
1811
+ }
1812
+ );
1813
+ props["ubrn_uniffi_internal_fn_func_ffi__string_from_buffer"] = jsi::Function::createFromHostFunction(
1814
+ rt,
1815
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__string_from_buffer"),
1816
+ 1,
1817
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
1818
+ return this->cpp_uniffi_internal_fn_func_ffi__string_from_buffer(rt, thisVal, args, count);
1819
+ }
1820
+ );
1821
+ props["ubrn_uniffi_internal_fn_func_ffi__read_string_from_buffer"] = jsi::Function::createFromHostFunction(
1822
+ rt,
1823
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_func_ffi__read_string_from_buffer"),
1824
+ 3,
1825
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
1826
+ return this->cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(rt, thisVal, args, count);
1827
+ }
1828
+ );
1829
+ props["ubrn_ffi_minip2p_ffi_core_uniffi_contract_version"] = jsi::Function::createFromHostFunction(
1830
+ rt,
1831
+ jsi::PropNameID::forAscii(rt, "ubrn_ffi_minip2p_ffi_core_uniffi_contract_version"),
1832
+ 0,
1833
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
1834
+ return this->cpp_ffi_minip2p_ffi_core_uniffi_contract_version(rt, thisVal, args, count);
1835
+ }
1836
+ );
1837
+
1838
+ // `rustbuffer_alloc(n)` -> Uint8Array view over Rust-owned memory of capacity `n`.
1839
+ // `rustbuffer_free(view)` -> hands the underlying (ptr, capacity) back to the
1840
+ // crate's `rustbuffer_free`. Together they let JS allocate buffers that the
1841
+ // codegen-emitted lowering path can fill in place and ship to Rust without copying.
1842
+ props["rustbuffer_alloc"] = jsi::Function::createFromHostFunction(
1843
+ rt,
1844
+ jsi::PropNameID::forAscii(rt, "rustbuffer_alloc"),
1845
+ 1,
1846
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
1847
+ if (count < 1 || !args[0].isNumber()) {
1848
+ throw jsi::JSError(rt, "rustbuffer_alloc expected a number argument");
1849
+ }
1850
+ double size = args[0].asNumber();
1851
+ if (size < 0) {
1852
+ throw jsi::JSError(rt, "rustbuffer_alloc: size must be non-negative");
1853
+ }
1854
+ if (size > INT32_MAX) {
1855
+ throw jsi::JSError(rt, "rustbuffer_alloc: size exceeds INT32_MAX");
1856
+ }
1857
+ auto rb = uniffi::minip2p_ffi_core::Bridging<RustBuffer>::rustbuffer_alloc(static_cast<int32_t>(size));
1858
+ if (rb.data == nullptr) {
1859
+ throw jsi::JSError(rt, "rustbuffer_alloc failed: alloc returned null");
1860
+ }
1861
+ // Non-owning view over Rust-allocated memory; CMutableBuffer's destructor
1862
+ // is the default and does not free `rb.data`. The allocation is released
1863
+ // either by an explicit `rustbuffer_free(view)` or by being adopted when
1864
+ // the view is lowered as an FFI argument.
1865
+ auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(
1866
+ rb.data, static_cast<size_t>(rb.capacity));
1867
+ // Wrap as Uint8Array so JS can index/assign bytes directly.
1868
+ auto view = uniffi_jsi::arraybufferToUint8Array(
1869
+ rt, jsi::ArrayBuffer(rt, payload));
1870
+ // Stamp the capacity so the argument-lowering path
1871
+ // (`Bridging<RustBuffer>::fromJs`) recognises this view as
1872
+ // library-owned and adopts the allocation instead of copying it.
1873
+ // Without the stamp, a lowered argument is copied and this
1874
+ // allocation is orphaned — one leaked payload per call.
1875
+ if (rb.capacity > 0) {
1876
+ view.setProperty(rt, uniffi_jsi::kUbrnRustCapacity,
1877
+ jsi::Value(static_cast<double>(rb.capacity)));
1878
+ }
1879
+ return jsi::Value(rt, view);
1880
+ }
1881
+ );
1882
+
1883
+ props["rustbuffer_free"] = jsi::Function::createFromHostFunction(
1884
+ rt,
1885
+ jsi::PropNameID::forAscii(rt, "rustbuffer_free"),
1886
+ 1,
1887
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
1888
+ if (count < 1 || !args[0].isObject()) {
1889
+ throw jsi::JSError(rt, "rustbuffer_free expected a Uint8Array argument");
1890
+ }
1891
+ auto view = args[0].asObject(rt);
1892
+ auto byteLength =
1893
+ static_cast<size_t>(view.getProperty(rt, "byteLength").asNumber());
1894
+ // Empty views were never allocated by `rustbuffer_alloc`; nothing
1895
+ // to free. Bail out before reading buffer/byteOffset/capacity to
1896
+ // skip three JSI property traversals on the empty path.
1897
+ if (byteLength == 0) {
1898
+ return jsi::Value::undefined();
1899
+ }
1900
+ // Capacity resolution:
1901
+ // * For a view from `rustbuffer_alloc(n)`, `byteLength == n == capacity`,
1902
+ // and no `__ubrnRustCapacity` hint was set.
1903
+ // * For a view from a lift-handoff, the codegen-emitted
1904
+ // `Bridging<RustBuffer>::toJs` set `byteLength = len` and stashed
1905
+ // the original `capacity` on `__ubrnRustCapacity` whenever
1906
+ // `capacity != len`.
1907
+ // So: prefer the hint, fall back to byteLength.
1908
+ size_t capacity = byteLength;
1909
+ if (view.hasProperty(rt, uniffi_jsi::kUbrnRustCapacity)) {
1910
+ capacity = static_cast<size_t>(
1911
+ view.getProperty(rt, uniffi_jsi::kUbrnRustCapacity).asNumber());
1912
+ }
1913
+ // A zero capacity marks a view already adopted as an FFI argument
1914
+ // (its hint was reset to 0) and freed by the callee. Freeing again
1915
+ // would be a double free, so this is a no-op.
1916
+ if (capacity == 0) {
1917
+ return jsi::Value::undefined();
1918
+ }
1919
+ auto buffer = view.getPropertyAsObject(rt, "buffer").getArrayBuffer(rt);
1920
+ auto byteOffset =
1921
+ static_cast<size_t>(view.getProperty(rt, "byteOffset").asNumber());
1922
+ // Honour byteOffset for safety (defensive; currently always 0).
1923
+ RustBuffer rb {
1924
+ .capacity = static_cast<uint64_t>(capacity),
1925
+ .len = 0,
1926
+ .data = buffer.data(rt) + byteOffset,
1927
+ };
1928
+ uniffi::minip2p_ffi_core::Bridging<RustBuffer>::rustbuffer_free(rb);
1929
+ return jsi::Value::undefined();
1930
+ }
1931
+ );
1932
+ }
1933
+
1934
+ void NativeMinip2pFfiCore::registerModule(jsi::Runtime &rt, std::shared_ptr<react::CallInvoker> callInvoker) {
1935
+ auto invoker = std::make_shared<uniffi_runtime::UniffiCallInvoker>(callInvoker);
1936
+ auto tm = std::make_shared<NativeMinip2pFfiCore>(rt, invoker);
1937
+ auto obj = rt.global().createFromHostObject(rt, tm);
1938
+ rt.global().setProperty(rt, "NativeMinip2pFfiCore", obj);
1939
+ }
1940
+
1941
+ void NativeMinip2pFfiCore::unregisterModule(jsi::Runtime &rt) {
1942
+ uniffi::minip2p_ffi_core::registry::clearRegistry();
1943
+ }
1944
+
1945
+ jsi::Value NativeMinip2pFfiCore::get(jsi::Runtime& rt, const jsi::PropNameID& name) {
1946
+ try {
1947
+ return jsi::Value(rt, props.at(name.utf8(rt)));
1948
+ }
1949
+ catch (std::out_of_range &) {
1950
+ return jsi::Value::undefined();
1951
+ }
1952
+ }
1953
+
1954
+ std::vector<jsi::PropNameID> NativeMinip2pFfiCore::getPropertyNames(jsi::Runtime& rt) {
1955
+ std::vector<jsi::PropNameID> rval;
1956
+ for (auto& [key, value] : props) {
1957
+ rval.push_back(jsi::PropNameID::forUtf8(rt, key));
1958
+ }
1959
+ return rval;
1960
+ }
1961
+
1962
+ void NativeMinip2pFfiCore::set(jsi::Runtime& rt, const jsi::PropNameID& name, const jsi::Value& value) {
1963
+ props.insert_or_assign(name.utf8(rt), &value);
1964
+ }
1965
+
1966
+ NativeMinip2pFfiCore::~NativeMinip2pFfiCore() {
1967
+ // Cleanup for callback function RustFutureContinuationCallback
1968
+ uniffi::minip2p_ffi_core::cb::rustfuturecontinuationcallback::cleanup();
1969
+ // Cleanup for callback function ForeignFutureDroppedCallback
1970
+ uniffi::minip2p_ffi_core::cb::foreignfuturedroppedcallback::cleanup();
1971
+ // Cleanup for "free" callback function CallbackInterfaceFree
1972
+
1973
+ }
1974
+
1975
+ // Utility functions for serialization/deserialization of strings.
1976
+ jsi::Value NativeMinip2pFfiCore::cpp_uniffi_internal_fn_func_ffi__string_to_byte_length(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
1977
+ return uniffi_jsi::Bridging<std::string>::string_to_bytelength(rt, args[0]);
1978
+ }
1979
+
1980
+ jsi::Value NativeMinip2pFfiCore::cpp_uniffi_internal_fn_func_ffi__string_to_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
1981
+ return uniffi_jsi::Bridging<std::string>::string_to_buffer(rt, args[0]);
1982
+ }
1983
+
1984
+ jsi::Value NativeMinip2pFfiCore::cpp_uniffi_internal_fn_func_ffi__string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
1985
+ return uniffi_jsi::Bridging<std::string>::string_from_buffer(rt, args[0]);
1986
+ }
1987
+
1988
+ jsi::Value NativeMinip2pFfiCore::cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
1989
+ return uniffi_jsi::Bridging<std::string>::read_string_from_buffer(rt, args[0], args[1], args[2]);
1990
+ }
1991
+
1992
+ // Methods calling directly into the uniffi generated C API of the Rust crate.
1993
+ jsi::Value NativeMinip2pFfiCore::cpp_ffi_minip2p_ffi_core_uniffi_contract_version(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
1994
+ auto value = ffi_minip2p_ffi_core_uniffi_contract_version(
1995
+ );
1996
+
1997
+
1998
+ return uniffi_jsi::Bridging<uint32_t>::toJs(rt, callInvoker, value);
1999
+ }