stem-mqtt 0.0.0-stage → 0.3.5

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,1601 @@
1
+ import koffi from "koffi";
2
+
3
+
4
+ import {
5
+
6
+ configureRuntimeHooks,
7
+
8
+ ffiFunctions,
9
+
10
+ getFfiBindings,
11
+
12
+ getFfiTypes,
13
+
14
+ } from "./mqtt_broker-ffi.js";
15
+
16
+
17
+ import {
18
+
19
+ createForeignBytes,
20
+
21
+ RustBufferValue,
22
+
23
+ } from "../runtime/ffi-types.js";
24
+
25
+
26
+ import {
27
+
28
+ AbstractFfiConverterByteArray,
29
+
30
+ FfiConverterArray,
31
+
32
+ FfiConverterBool,
33
+
34
+ FfiConverterBytes,
35
+
36
+ FfiConverterOptional,
37
+
38
+ FfiConverterString,
39
+
40
+ FfiConverterUInt16,
41
+
42
+ FfiConverterUInt32,
43
+
44
+ FfiConverterUInt64,
45
+
46
+ } from "../runtime/ffi-converters.js";
47
+
48
+
49
+ import {
50
+
51
+ UnexpectedEnumCase,
52
+
53
+ } from "../runtime/errors.js";
54
+
55
+
56
+ import {
57
+
58
+ rustCallAsync,
59
+
60
+ rustFutureContinuationCallback,
61
+
62
+ } from "../runtime/async-rust-call.js";
63
+
64
+
65
+ import {
66
+
67
+ clearPendingForeignFutures,
68
+
69
+ createCallbackRegistry,
70
+
71
+ invokeCallbackMethod,
72
+
73
+ } from "../runtime/callbacks.js";
74
+
75
+
76
+ import {
77
+
78
+ createObjectConverter,
79
+
80
+ createObjectFactory,
81
+
82
+ UniffiObjectBase,
83
+
84
+ UNIFFI_OBJECT_HANDLE_SIZE,
85
+
86
+ } from "../runtime/objects.js";
87
+
88
+
89
+ import {
90
+
91
+ CALL_SUCCESS,
92
+
93
+ UniffiRustCaller,
94
+
95
+ createRustCallStatus,
96
+
97
+ } from "../runtime/rust-call.js";
98
+
99
+
100
+ export const componentMetadata = Object.freeze({
101
+ namespace: "mqtt_broker",
102
+ packageName: "mqtt_broker",
103
+ cdylibName: "mqtt_broker",
104
+ nodeEngine: ">=16",
105
+ bundledPrebuilds: true,
106
+ manualLoad: false,
107
+ });
108
+
109
+ export { ffiMetadata } from "./mqtt_broker-ffi.js";
110
+
111
+
112
+ function uniffiNotImplemented(member) {
113
+ throw new Error(`${member} is not implemented yet. Koffi-backed bindings are still pending.`);
114
+ }
115
+
116
+ const uniffiTextEncoder = new TextEncoder();
117
+ const uniffiTextDecoder = new TextDecoder();
118
+ const uniffiSuccessRustCallStatus = createRustCallStatus();
119
+ const UNIFFI_MAX_CACHED_RUST_CALL_STATUSES = 32;
120
+ const uniffiRustCallStatusPool = [];
121
+
122
+ function uniffiLiftString(bytes) {
123
+ return uniffiTextDecoder.decode(bytes);
124
+ }
125
+
126
+ function uniffiDecodeRustCallStatus(status) {
127
+ return status == null
128
+ ? uniffiSuccessRustCallStatus
129
+ : koffi.decode(status, 0, "int8_t") === 0
130
+ ? uniffiSuccessRustCallStatus
131
+ : koffi.decode(status, getFfiTypes().RustCallStatus);
132
+ }
133
+
134
+ function uniffiWriteRustCallStatus(status, value) {
135
+ if (
136
+ status != null
137
+ && (
138
+ value.code !== 0
139
+ || value.error_buf.data !== null
140
+ || value.error_buf.len !== 0n
141
+ || value.error_buf.capacity !== 0n
142
+ )
143
+ ) {
144
+ koffi.encode(status, getFfiTypes().RustCallStatus, value);
145
+ }
146
+ return status;
147
+ }
148
+
149
+ function uniffiAcquireRustCallStatus() {
150
+ const status = uniffiRustCallStatusPool.pop();
151
+ if (status != null) {
152
+ return status;
153
+ }
154
+ return koffi.alloc(getFfiTypes().RustCallStatus, 1);
155
+ }
156
+
157
+ function uniffiReleaseRustCallStatus(status) {
158
+ if (status == null) {
159
+ return;
160
+ }
161
+
162
+ koffi.encode(status, getFfiTypes().RustCallStatus, uniffiSuccessRustCallStatus);
163
+ if (uniffiRustCallStatusPool.length < UNIFFI_MAX_CACHED_RUST_CALL_STATUSES) {
164
+ uniffiRustCallStatusPool.push(status);
165
+ return;
166
+ }
167
+
168
+ koffi.free(status);
169
+ }
170
+
171
+ const uniffiRustCaller = new UniffiRustCaller({
172
+ createStatus: uniffiAcquireRustCallStatus,
173
+ disposeStatus: uniffiReleaseRustCallStatus,
174
+ readStatus: uniffiDecodeRustCallStatus,
175
+ writeStatus: uniffiWriteRustCallStatus,
176
+ liftString: uniffiLiftString,
177
+ });
178
+
179
+ function uniffiFreeRustBuffer(buffer) {
180
+ return uniffiRustCaller.rustCall(
181
+ (status) => ffiFunctions.ffi_mqtt_broker_rustbuffer_free(buffer, status),
182
+ { liftString: uniffiLiftString },
183
+ );
184
+ }
185
+
186
+ const uniffiDefaultRustCallOptions = Object.freeze({
187
+ freeRustBuffer: uniffiFreeRustBuffer,
188
+ liftString: uniffiLiftString,
189
+ rustCaller: uniffiRustCaller,
190
+ });
191
+ const uniffiRustCallOptionsByErrorConverter = new WeakMap();
192
+ const uniffiOptionalConverterCache = new WeakMap();
193
+ const uniffiArrayConverterCache = new WeakMap();
194
+ const uniffiLibraryFunctionCache = new WeakMap();
195
+
196
+ function uniffiRustCallOptions(errorConverter = undefined) {
197
+ if (errorConverter == null) {
198
+ return uniffiDefaultRustCallOptions;
199
+ }
200
+
201
+ if (typeof errorConverter !== "object" && typeof errorConverter !== "function") {
202
+ return Object.freeze({
203
+ errorHandler: (errorBytes) => errorConverter.lift(errorBytes),
204
+ freeRustBuffer: uniffiFreeRustBuffer,
205
+ liftString: uniffiLiftString,
206
+ rustCaller: uniffiRustCaller,
207
+ });
208
+ }
209
+
210
+ const cachedOptions = uniffiRustCallOptionsByErrorConverter.get(errorConverter);
211
+ if (cachedOptions != null) {
212
+ return cachedOptions;
213
+ }
214
+
215
+ const options = Object.freeze({
216
+ errorHandler: (errorBytes) => errorConverter.lift(errorBytes),
217
+ freeRustBuffer: uniffiFreeRustBuffer,
218
+ liftString: uniffiLiftString,
219
+ rustCaller: uniffiRustCaller,
220
+ });
221
+ uniffiRustCallOptionsByErrorConverter.set(errorConverter, options);
222
+ return options;
223
+ }
224
+
225
+ function uniffiOptionalConverter(innerConverter) {
226
+ let converter = uniffiOptionalConverterCache.get(innerConverter);
227
+ if (converter == null) {
228
+ converter = new FfiConverterOptional(innerConverter);
229
+ uniffiOptionalConverterCache.set(innerConverter, converter);
230
+ }
231
+ return converter;
232
+ }
233
+
234
+ function uniffiArrayConverter(innerConverter) {
235
+ let converter = uniffiArrayConverterCache.get(innerConverter);
236
+ if (converter == null) {
237
+ converter = new FfiConverterArray(innerConverter);
238
+ uniffiArrayConverterCache.set(innerConverter, converter);
239
+ }
240
+ return converter;
241
+ }
242
+
243
+ function uniffiGetCachedLibraryFunction(cacheKey, create) {
244
+ const bindings = getFfiBindings();
245
+ const library = bindings.library;
246
+ let libraryCache = uniffiLibraryFunctionCache.get(library);
247
+ if (libraryCache == null) {
248
+ libraryCache = new Map();
249
+ uniffiLibraryFunctionCache.set(library, libraryCache);
250
+ }
251
+
252
+ let cachedFunction = libraryCache.get(cacheKey);
253
+ if (cachedFunction == null) {
254
+ cachedFunction = create(bindings);
255
+ libraryCache.set(cacheKey, cachedFunction);
256
+ }
257
+ return cachedFunction;
258
+ }
259
+
260
+ function uniffiCopyIntoRustBuffer(bytes) {
261
+ return uniffiRustCaller.rustCall(
262
+ (status) => ffiFunctions.ffi_mqtt_broker_rustbuffer_from_bytes(createForeignBytes(bytes), status),
263
+ uniffiRustCallOptions(),
264
+ );
265
+ }
266
+
267
+ function uniffiLowerString(value) {
268
+ return uniffiCopyIntoRustBuffer(uniffiTextEncoder.encode(value));
269
+ }
270
+
271
+ function uniffiLiftStringFromRustBuffer(value) {
272
+ return uniffiLiftString(new RustBufferValue(value).consumeIntoUint8Array(uniffiFreeRustBuffer));
273
+ }
274
+
275
+ function uniffiLowerBytes(value) {
276
+ return uniffiCopyIntoRustBuffer(value);
277
+ }
278
+
279
+ function uniffiLiftBytesFromRustBuffer(value) {
280
+ return new RustBufferValue(value).consumeIntoUint8Array(uniffiFreeRustBuffer);
281
+ }
282
+
283
+ function uniffiLowerIntoRustBuffer(converter, value) {
284
+ return uniffiCopyIntoRustBuffer(converter.lower(value));
285
+ }
286
+
287
+ function uniffiLiftFromRustBuffer(converter, value) {
288
+ return converter.lift(uniffiLiftBytesFromRustBuffer(value));
289
+ }
290
+
291
+ function uniffiRequireRecordObject(typeName, value) {
292
+ if (typeof value !== "object" || value == null) {
293
+ throw new TypeError(`${typeName} values must be non-null objects.`);
294
+ }
295
+ return value;
296
+ }
297
+
298
+ function uniffiRequireFlatEnumValue(enumValues, typeName, value) {
299
+ for (const enumValue of Object.values(enumValues)) {
300
+ if (enumValue === value) {
301
+ return enumValue;
302
+ }
303
+ }
304
+ throw new TypeError(`${typeName} values must be one of ${Object.values(enumValues).map((item) => JSON.stringify(item)).join(", ")}.`);
305
+ }
306
+
307
+ function uniffiRequireTaggedEnumValue(typeName, value) {
308
+ const enumValue = uniffiRequireRecordObject(typeName, value);
309
+ if (typeof enumValue.tag !== "string") {
310
+ throw new TypeError(`${typeName} values must be tagged objects with a string tag field.`);
311
+ }
312
+ return enumValue;
313
+ }
314
+
315
+ function uniffiNotImplementedConverter(typeName) {
316
+ const fail = (member) => {
317
+ throw new Error(`${typeName} converter ${member} is not implemented yet.`);
318
+ };
319
+ return Object.freeze({
320
+ lower() {
321
+ return fail("lower");
322
+ },
323
+ lift() {
324
+ return fail("lift");
325
+ },
326
+ write() {
327
+ return fail("write");
328
+ },
329
+ read() {
330
+ return fail("read");
331
+ },
332
+ allocationSize() {
333
+ return fail("allocationSize");
334
+ },
335
+ });
336
+ }
337
+
338
+ let uniffiRustFutureContinuationPointer = null;
339
+
340
+ function uniffiGetRustFutureContinuationPointer() {
341
+ if (uniffiRustFutureContinuationPointer == null) {
342
+ const bindings = getFfiBindings();
343
+ uniffiRustFutureContinuationPointer = koffi.register(
344
+ rustFutureContinuationCallback,
345
+ koffi.pointer(bindings.ffiCallbacks.RustFutureContinuationCallback),
346
+ );
347
+ }
348
+ return uniffiRustFutureContinuationPointer;
349
+ }
350
+
351
+ /**
352
+ * The verdict of one round of an MQTT 5.0 enhanced authentication exchange.
353
+ */
354
+ export const EnhancedAuthOutcome = Object.freeze({
355
+ /**
356
+ * Send [`EnhancedAuthStep::data`] to the client as a challenge and wait
357
+ * for its response.
358
+ */
359
+ "Continue": "Continue",
360
+ /**
361
+ * Authentication succeeded; [`EnhancedAuthStep::data`] (if non-empty) is
362
+ * returned to the client in the CONNACK (e.g. a SCRAM server-final message).
363
+ */
364
+ "Success": "Success",
365
+ /**
366
+ * Refuse the connection.
367
+ */
368
+ "Failure": "Failure",
369
+ });
370
+
371
+ /**
372
+ * MQTT Quality of Service level, as used in the broker's own API
373
+ * ([`MqttBrokerConfig::max_qos`], [`MqttBrokerEventListener`], [`crate::BrokerEvent`]).
374
+ *
375
+ * This is deliberately the **broker's own** enum rather than a re-export of
376
+ * `mqtt_client::QoS`. A type defined in another crate is an *external type*
377
+ * to UniFFI, and several binding generators (Node.js) can't handle those;
378
+ * owning it makes `mqtt_broker`'s bindings fully self-contained in every
379
+ * language — one package, no dependency on the client component's generated
380
+ * code. The cost is a second `QoS` next to the client's (identical, with
381
+ * lossless `From` conversions in Rust).
382
+ */
383
+ export const QoS = Object.freeze({
384
+ /**
385
+ * QoS 0 — fire and forget.
386
+ */
387
+ "AtMostOnce": "AtMostOnce",
388
+ /**
389
+ * QoS 1 — acknowledged delivery, may be duplicated.
390
+ */
391
+ "AtLeastOnce": "AtLeastOnce",
392
+ /**
393
+ * QoS 2 — exactly-once delivery.
394
+ */
395
+ "ExactlyOnce": "ExactlyOnce",
396
+ });
397
+
398
+ /**
399
+ * A broker event, as returned by the pull-style `MqttBroker::next_event`
400
+ * (the polling twin of [`MqttBrokerEventListener`](crate::config::MqttBrokerEventListener)).
401
+ */
402
+ export const BrokerEvent = Object.freeze({
403
+ ClientConnected(client_id) {
404
+ return Object.freeze({
405
+ tag: "ClientConnected",
406
+ "client_id": client_id,
407
+ });
408
+ },
409
+ ClientDisconnected(client_id, reason) {
410
+ return Object.freeze({
411
+ tag: "ClientDisconnected",
412
+ "client_id": client_id,
413
+ "reason": reason,
414
+ });
415
+ },
416
+ MessagePublished(client_id, topic, qos) {
417
+ return Object.freeze({
418
+ tag: "MessagePublished",
419
+ "client_id": client_id,
420
+ "topic": topic,
421
+ "qos": qos,
422
+ });
423
+ },
424
+ });
425
+
426
+ /**
427
+ * Errors produced while starting or stopping an [`crate::MqttBroker`].
428
+ */
429
+ export class MqttBrokerError extends globalThis.Error {
430
+ constructor(tag, message = tag) {
431
+ super(message);
432
+ this.name = "MqttBrokerError";
433
+ this.tag = tag;
434
+ }
435
+ }
436
+
437
+ /**
438
+ * `start()` was called while the broker was already running.
439
+ */
440
+ export class MqttBrokerErrorAlreadyRunning extends MqttBrokerError {
441
+ constructor(message = undefined) {
442
+ super("AlreadyRunning", message ?? "AlreadyRunning");
443
+ this.name = "MqttBrokerErrorAlreadyRunning";
444
+ this.message = message ?? "AlreadyRunning";
445
+ }
446
+ }
447
+
448
+ /**
449
+ * A listening socket could not be bound or queried.
450
+ */
451
+ export class MqttBrokerErrorIo extends MqttBrokerError {
452
+ constructor(message = undefined) {
453
+ super("Io", message ?? "Io");
454
+ this.name = "MqttBrokerErrorIo";
455
+ this.message = message ?? "Io";
456
+ }
457
+ }
458
+
459
+ /**
460
+ * TLS certificate, key, or verifier configuration was invalid.
461
+ */
462
+ export class MqttBrokerErrorTls extends MqttBrokerError {
463
+ constructor(message = undefined) {
464
+ super("Tls", message ?? "Tls");
465
+ this.name = "MqttBrokerErrorTls";
466
+ this.message = message ?? "Tls";
467
+ }
468
+ }
469
+
470
+ const FfiConverterAuthRequest = new (class extends AbstractFfiConverterByteArray {
471
+ allocationSize(value) {
472
+ const recordValue = uniffiRequireRecordObject("AuthRequest", value);
473
+ return FfiConverterUInt64.allocationSize(recordValue["id"]) + FfiConverterString.allocationSize(recordValue["client_id"]) + uniffiOptionalConverter(FfiConverterString).allocationSize(recordValue["username"]) + uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["password"]);
474
+ }
475
+
476
+ write(value, writer) {
477
+ const recordValue = uniffiRequireRecordObject("AuthRequest", value);
478
+ FfiConverterUInt64.write(recordValue["id"], writer);
479
+ FfiConverterString.write(recordValue["client_id"], writer);
480
+ uniffiOptionalConverter(FfiConverterString).write(recordValue["username"], writer);
481
+ uniffiOptionalConverter(FfiConverterBytes).write(recordValue["password"], writer);
482
+ }
483
+
484
+ read(reader) {
485
+ return {
486
+ "id": FfiConverterUInt64.read(reader),
487
+ "client_id": FfiConverterString.read(reader),
488
+ "username": uniffiOptionalConverter(FfiConverterString).read(reader),
489
+ "password": uniffiOptionalConverter(FfiConverterBytes).read(reader),
490
+ };
491
+ }
492
+ })();
493
+ const FfiConverterBrokerTlsConfig = new (class extends AbstractFfiConverterByteArray {
494
+ allocationSize(value) {
495
+ const recordValue = uniffiRequireRecordObject("BrokerTlsConfig", value);
496
+ return FfiConverterUInt16.allocationSize(recordValue["port"]) + FfiConverterBytes.allocationSize(recordValue["cert_pem"]) + FfiConverterBytes.allocationSize(recordValue["key_pem"]) + uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["client_ca_pem"]);
497
+ }
498
+
499
+ write(value, writer) {
500
+ const recordValue = uniffiRequireRecordObject("BrokerTlsConfig", value);
501
+ FfiConverterUInt16.write(recordValue["port"], writer);
502
+ FfiConverterBytes.write(recordValue["cert_pem"], writer);
503
+ FfiConverterBytes.write(recordValue["key_pem"], writer);
504
+ uniffiOptionalConverter(FfiConverterBytes).write(recordValue["client_ca_pem"], writer);
505
+ }
506
+
507
+ read(reader) {
508
+ return {
509
+ "port": FfiConverterUInt16.read(reader),
510
+ "cert_pem": FfiConverterBytes.read(reader),
511
+ "key_pem": FfiConverterBytes.read(reader),
512
+ "client_ca_pem": uniffiOptionalConverter(FfiConverterBytes).read(reader),
513
+ };
514
+ }
515
+ })();
516
+ const FfiConverterEnhancedAuthStep = new (class extends AbstractFfiConverterByteArray {
517
+ allocationSize(value) {
518
+ const recordValue = uniffiRequireRecordObject("EnhancedAuthStep", value);
519
+ return FfiConverterEnhancedAuthOutcome.allocationSize(recordValue["outcome"]) + FfiConverterBytes.allocationSize(recordValue["data"]);
520
+ }
521
+
522
+ write(value, writer) {
523
+ const recordValue = uniffiRequireRecordObject("EnhancedAuthStep", value);
524
+ FfiConverterEnhancedAuthOutcome.write(recordValue["outcome"], writer);
525
+ FfiConverterBytes.write(recordValue["data"], writer);
526
+ }
527
+
528
+ read(reader) {
529
+ return {
530
+ "outcome": FfiConverterEnhancedAuthOutcome.read(reader),
531
+ "data": FfiConverterBytes.read(reader),
532
+ };
533
+ }
534
+ })();
535
+ const FfiConverterMqttBrokerConfig = new (class extends AbstractFfiConverterByteArray {
536
+ allocationSize(value) {
537
+ const recordValue = uniffiRequireRecordObject("MqttBrokerConfig", value);
538
+ return FfiConverterString.allocationSize(recordValue["bind_address"]) + FfiConverterUInt16.allocationSize(recordValue["port"]) + uniffiOptionalConverter(FfiConverterUInt16).allocationSize(recordValue["ws_port"]) + FfiConverterBool.allocationSize(recordValue["allow_anonymous"]) + FfiConverterUInt32.allocationSize(recordValue["max_clients"]) + FfiConverterQoS.allocationSize(recordValue["max_qos"]) + FfiConverterUInt32.allocationSize(recordValue["max_retained_messages"]) + FfiConverterUInt32.allocationSize(recordValue["max_queued_per_client"]) + FfiConverterUInt32.allocationSize(recordValue["redelivery_interval_secs"]) + uniffiOptionalConverter(FfiConverterBrokerTlsConfig).allocationSize(recordValue["tls"]) + FfiConverterUInt32.allocationSize(recordValue["max_packet_size"]) + FfiConverterUInt32.allocationSize(recordValue["max_outbound_queue"]) + FfiConverterUInt32.allocationSize(recordValue["session_expiry_secs"]);
539
+ }
540
+
541
+ write(value, writer) {
542
+ const recordValue = uniffiRequireRecordObject("MqttBrokerConfig", value);
543
+ FfiConverterString.write(recordValue["bind_address"], writer);
544
+ FfiConverterUInt16.write(recordValue["port"], writer);
545
+ uniffiOptionalConverter(FfiConverterUInt16).write(recordValue["ws_port"], writer);
546
+ FfiConverterBool.write(recordValue["allow_anonymous"], writer);
547
+ FfiConverterUInt32.write(recordValue["max_clients"], writer);
548
+ FfiConverterQoS.write(recordValue["max_qos"], writer);
549
+ FfiConverterUInt32.write(recordValue["max_retained_messages"], writer);
550
+ FfiConverterUInt32.write(recordValue["max_queued_per_client"], writer);
551
+ FfiConverterUInt32.write(recordValue["redelivery_interval_secs"], writer);
552
+ uniffiOptionalConverter(FfiConverterBrokerTlsConfig).write(recordValue["tls"], writer);
553
+ FfiConverterUInt32.write(recordValue["max_packet_size"], writer);
554
+ FfiConverterUInt32.write(recordValue["max_outbound_queue"], writer);
555
+ FfiConverterUInt32.write(recordValue["session_expiry_secs"], writer);
556
+ }
557
+
558
+ read(reader) {
559
+ return {
560
+ "bind_address": FfiConverterString.read(reader),
561
+ "port": FfiConverterUInt16.read(reader),
562
+ "ws_port": uniffiOptionalConverter(FfiConverterUInt16).read(reader),
563
+ "allow_anonymous": FfiConverterBool.read(reader),
564
+ "max_clients": FfiConverterUInt32.read(reader),
565
+ "max_qos": FfiConverterQoS.read(reader),
566
+ "max_retained_messages": FfiConverterUInt32.read(reader),
567
+ "max_queued_per_client": FfiConverterUInt32.read(reader),
568
+ "redelivery_interval_secs": FfiConverterUInt32.read(reader),
569
+ "tls": uniffiOptionalConverter(FfiConverterBrokerTlsConfig).read(reader),
570
+ "max_packet_size": FfiConverterUInt32.read(reader),
571
+ "max_outbound_queue": FfiConverterUInt32.read(reader),
572
+ "session_expiry_secs": FfiConverterUInt32.read(reader),
573
+ };
574
+ }
575
+ })();
576
+ const FfiConverterEnhancedAuthOutcome = new (class extends AbstractFfiConverterByteArray {
577
+ allocationSize(value) {
578
+ uniffiRequireFlatEnumValue(EnhancedAuthOutcome, "EnhancedAuthOutcome", value);
579
+ return 4;
580
+ }
581
+
582
+ write(value, writer) {
583
+ const enumValue = uniffiRequireFlatEnumValue(EnhancedAuthOutcome, "EnhancedAuthOutcome", value);
584
+ switch (enumValue) {
585
+ case EnhancedAuthOutcome["Continue"]:
586
+ writer.writeInt32(1);
587
+ return;
588
+ case EnhancedAuthOutcome["Success"]:
589
+ writer.writeInt32(2);
590
+ return;
591
+ case EnhancedAuthOutcome["Failure"]:
592
+ writer.writeInt32(3);
593
+ return;
594
+ default:
595
+ throw new UnexpectedEnumCase(`Unexpected EnhancedAuthOutcome case ${String(enumValue)}.`);
596
+ }
597
+ }
598
+
599
+ read(reader) {
600
+ const enumTag = reader.readInt32();
601
+ switch (enumTag) {
602
+ case 1:
603
+ return EnhancedAuthOutcome["Continue"];
604
+ case 2:
605
+ return EnhancedAuthOutcome["Success"];
606
+ case 3:
607
+ return EnhancedAuthOutcome["Failure"];
608
+ default:
609
+ throw new UnexpectedEnumCase(`Unexpected EnhancedAuthOutcome case ${String(enumTag)}.`);
610
+ }
611
+ }
612
+ })();
613
+ const FfiConverterQoS = new (class extends AbstractFfiConverterByteArray {
614
+ allocationSize(value) {
615
+ uniffiRequireFlatEnumValue(QoS, "QoS", value);
616
+ return 4;
617
+ }
618
+
619
+ write(value, writer) {
620
+ const enumValue = uniffiRequireFlatEnumValue(QoS, "QoS", value);
621
+ switch (enumValue) {
622
+ case QoS["AtMostOnce"]:
623
+ writer.writeInt32(1);
624
+ return;
625
+ case QoS["AtLeastOnce"]:
626
+ writer.writeInt32(2);
627
+ return;
628
+ case QoS["ExactlyOnce"]:
629
+ writer.writeInt32(3);
630
+ return;
631
+ default:
632
+ throw new UnexpectedEnumCase(`Unexpected QoS case ${String(enumValue)}.`);
633
+ }
634
+ }
635
+
636
+ read(reader) {
637
+ const enumTag = reader.readInt32();
638
+ switch (enumTag) {
639
+ case 1:
640
+ return QoS["AtMostOnce"];
641
+ case 2:
642
+ return QoS["AtLeastOnce"];
643
+ case 3:
644
+ return QoS["ExactlyOnce"];
645
+ default:
646
+ throw new UnexpectedEnumCase(`Unexpected QoS case ${String(enumTag)}.`);
647
+ }
648
+ }
649
+ })();
650
+ const FfiConverterBrokerEvent = new (class extends AbstractFfiConverterByteArray {
651
+ allocationSize(value) {
652
+ const enumValue = uniffiRequireTaggedEnumValue("BrokerEvent", value);
653
+ switch (enumValue.tag) {
654
+ case "ClientConnected":
655
+ return 4 + FfiConverterString.allocationSize(enumValue["client_id"]);
656
+ case "ClientDisconnected":
657
+ return 4 + FfiConverterString.allocationSize(enumValue["client_id"]) + FfiConverterString.allocationSize(enumValue["reason"]);
658
+ case "MessagePublished":
659
+ return 4 + FfiConverterString.allocationSize(enumValue["client_id"]) + FfiConverterString.allocationSize(enumValue["topic"]) + FfiConverterQoS.allocationSize(enumValue["qos"]);
660
+ default:
661
+ throw new UnexpectedEnumCase(`Unexpected BrokerEvent case ${String(enumValue.tag)}.`);
662
+ }
663
+ }
664
+
665
+ write(value, writer) {
666
+ const enumValue = uniffiRequireTaggedEnumValue("BrokerEvent", value);
667
+ switch (enumValue.tag) {
668
+ case "ClientConnected":
669
+ writer.writeInt32(1);
670
+ FfiConverterString.write(enumValue["client_id"], writer);
671
+ return;
672
+ case "ClientDisconnected":
673
+ writer.writeInt32(2);
674
+ FfiConverterString.write(enumValue["client_id"], writer);
675
+ FfiConverterString.write(enumValue["reason"], writer);
676
+ return;
677
+ case "MessagePublished":
678
+ writer.writeInt32(3);
679
+ FfiConverterString.write(enumValue["client_id"], writer);
680
+ FfiConverterString.write(enumValue["topic"], writer);
681
+ FfiConverterQoS.write(enumValue["qos"], writer);
682
+ return;
683
+ default:
684
+ throw new UnexpectedEnumCase(`Unexpected BrokerEvent case ${String(enumValue.tag)}.`);
685
+ }
686
+ }
687
+
688
+ read(reader) {
689
+ const enumTag = reader.readInt32();
690
+ switch (enumTag) {
691
+ case 1:
692
+ return BrokerEvent.ClientConnected(FfiConverterString.read(reader));
693
+ case 2:
694
+ return BrokerEvent.ClientDisconnected(FfiConverterString.read(reader), FfiConverterString.read(reader));
695
+ case 3:
696
+ return BrokerEvent.MessagePublished(FfiConverterString.read(reader), FfiConverterString.read(reader), FfiConverterQoS.read(reader));
697
+ default:
698
+ throw new UnexpectedEnumCase(`Unexpected BrokerEvent case ${String(enumTag)}.`);
699
+ }
700
+ }
701
+ })();
702
+ const FfiConverterMqttBrokerError = new (class extends AbstractFfiConverterByteArray {
703
+ allocationSize(value) {
704
+ if (value instanceof MqttBrokerErrorAlreadyRunning) {
705
+ return 4;
706
+ }
707
+ if (value instanceof MqttBrokerErrorIo) {
708
+ return 4;
709
+ }
710
+ if (value instanceof MqttBrokerErrorTls) {
711
+ return 4;
712
+ }
713
+ throw new TypeError("MqttBrokerError values must be instances of MqttBrokerErrorAlreadyRunning, MqttBrokerErrorIo, MqttBrokerErrorTls.");
714
+ }
715
+
716
+ write(value, writer) {
717
+ if (value instanceof MqttBrokerErrorAlreadyRunning) {
718
+ writer.writeInt32(1);
719
+ return;
720
+ }
721
+ if (value instanceof MqttBrokerErrorIo) {
722
+ writer.writeInt32(2);
723
+ return;
724
+ }
725
+ if (value instanceof MqttBrokerErrorTls) {
726
+ writer.writeInt32(3);
727
+ return;
728
+ }
729
+ throw new TypeError("MqttBrokerError values must be instances of MqttBrokerErrorAlreadyRunning, MqttBrokerErrorIo, MqttBrokerErrorTls.");
730
+ }
731
+
732
+ read(reader) {
733
+ const enumTag = reader.readInt32();
734
+ switch (enumTag) {
735
+ case 1:
736
+ return new MqttBrokerErrorAlreadyRunning(FfiConverterString.read(reader));
737
+ case 2:
738
+ return new MqttBrokerErrorIo(FfiConverterString.read(reader));
739
+ case 3:
740
+ return new MqttBrokerErrorTls(FfiConverterString.read(reader));
741
+ default:
742
+ throw new UnexpectedEnumCase(`Unexpected MqttBrokerError case ${String(enumTag)}.`);
743
+ }
744
+ }
745
+ })();
746
+ class UniffiMqttAuthProviderProxy extends UniffiObjectBase {
747
+
748
+ authenticate(client_id, username, password) {
749
+ const loweredSelf = uniffiMqttAuthProviderFactory.cloneHandle(this);
750
+ const ffiMethod =
751
+ uniffiMqttAuthProviderFactory.usesGenericAbi(this)
752
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttauthprovider_authenticate_generic_abi
753
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttauthprovider_authenticate;
754
+ const loweredClientId = uniffiLowerString(client_id);
755
+ const loweredUsername = uniffiLowerIntoRustBuffer(uniffiOptionalConverter(FfiConverterString), username);
756
+ const loweredPassword = uniffiLowerIntoRustBuffer(uniffiOptionalConverter(FfiConverterBytes), password);
757
+ const uniffiResult = uniffiRustCaller.rustCall(
758
+ (status) => ffiMethod(loweredSelf, loweredClientId, loweredUsername, loweredPassword, status),
759
+ uniffiRustCallOptions(),
760
+ );
761
+ return FfiConverterBool.lift(uniffiResult);
762
+ }
763
+ }
764
+
765
+ const uniffiMqttAuthProviderFactory = createObjectFactory({
766
+ typeName: "MqttAuthProvider",
767
+ createInstance: () => Object.create(UniffiMqttAuthProviderProxy.prototype),
768
+ cloneHandle(handle) {
769
+ return uniffiRustCaller.rustCall(
770
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_clone_mqttauthprovider(handle, status),
771
+ uniffiRustCallOptions(),
772
+ );
773
+ },
774
+ freeHandle(handle) {
775
+ uniffiRustCaller.rustCall(
776
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_free_mqttauthprovider(handle, status),
777
+ uniffiRustCallOptions(),
778
+ );
779
+ },
780
+ });
781
+
782
+ function uniffiValidateMqttAuthProviderImplementation(implementation) {
783
+ if ((typeof implementation !== "object" && typeof implementation !== "function") || implementation == null) {
784
+ throw new TypeError(`${"MqttAuthProvider"} implementations must be objects with callable methods.`);
785
+ }
786
+ if (typeof implementation.authenticate !== "function") {
787
+ throw new TypeError(`${"MqttAuthProvider"} is missing required method authenticate().`);
788
+ }
789
+ return implementation;
790
+ }
791
+
792
+ const uniffiMqttAuthProviderRegistry = createCallbackRegistry({
793
+ interfaceName: "MqttAuthProvider",
794
+ validate: uniffiValidateMqttAuthProviderImplementation,
795
+ });
796
+
797
+ function uniffiRegisterMqttAuthProviderVtable(bindings, registrations, vtableReferences) {
798
+ const authenticateCallback = koffi.register(
799
+ (uniffiHandle, client_id, username, password, uniffiOutReturn, callStatus) => {
800
+ const uniffiStatus = callStatus == null
801
+ ? createRustCallStatus()
802
+ : koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
803
+ const uniffiResult = invokeCallbackMethod({
804
+ registry: uniffiMqttAuthProviderRegistry,
805
+ handle: uniffiHandle,
806
+ methodName: "authenticate",
807
+ args: [
808
+ uniffiLiftStringFromRustBuffer(client_id),
809
+ uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterString), username),
810
+ uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterBytes), password),
811
+ ],
812
+ lowerString: (value) => uniffiLowerString(value),
813
+ status: uniffiStatus,
814
+ });
815
+ if (callStatus != null) {
816
+ koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
817
+ }
818
+ if (uniffiStatus.code !== CALL_SUCCESS) {
819
+ return;
820
+ }
821
+ const loweredReturn = FfiConverterBool.lower(uniffiResult);
822
+ koffi.encode(uniffiOutReturn, "int8_t", loweredReturn);
823
+ },
824
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttAuthProviderMethod0),
825
+ );
826
+ registrations.push(authenticateCallback);
827
+ const uniffiFree = koffi.register(
828
+ (uniffiHandle) => uniffiMqttAuthProviderRegistry.remove(uniffiHandle),
829
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceFree),
830
+ );
831
+ registrations.push(uniffiFree);
832
+ const uniffiClone = koffi.register(
833
+ (uniffiHandle) => uniffiMqttAuthProviderRegistry.cloneHandle(uniffiHandle),
834
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceClone),
835
+ );
836
+ registrations.push(uniffiClone);
837
+ const uniffiVtable = koffi.alloc(bindings.ffiStructs.VTableCallbackInterfaceMqttAuthProvider, 1);
838
+ koffi.encode(uniffiVtable, bindings.ffiStructs.VTableCallbackInterfaceMqttAuthProvider, {
839
+ uniffi_free: uniffiFree,
840
+ uniffi_clone: uniffiClone,
841
+ "authenticate": authenticateCallback,
842
+
843
+ });
844
+ vtableReferences.push(uniffiVtable);
845
+ bindings.ffiFunctions.uniffi_mqtt_broker_fn_init_callback_vtable_mqttauthprovider(uniffiVtable);
846
+ }
847
+
848
+ const FfiConverterMqttAuthProvider = Object.freeze({
849
+ lower(value) {
850
+ if (uniffiMqttAuthProviderFactory.isInstance(value)) {
851
+ return uniffiMqttAuthProviderFactory.cloneHandle(value);
852
+ }
853
+ return uniffiMqttAuthProviderRegistry.register(value);
854
+ },
855
+ lift(handle) {
856
+ return uniffiMqttAuthProviderFactory.create(handle);
857
+ },
858
+ write(value, writer) {
859
+ writer.writeUInt64(this.lower(value));
860
+ },
861
+ read(reader) {
862
+ return this.lift(reader.readUInt64());
863
+ },
864
+ allocationSize() {
865
+ return UNIFFI_OBJECT_HANDLE_SIZE;
866
+ },
867
+ });
868
+ class UniffiMqttBrokerEventListenerProxy extends UniffiObjectBase {
869
+
870
+ on_client_connected(client_id) {
871
+ const loweredSelf = uniffiMqttBrokerEventListenerFactory.cloneHandle(this);
872
+ const ffiMethod =
873
+ uniffiMqttBrokerEventListenerFactory.usesGenericAbi(this)
874
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_client_connected_generic_abi
875
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_client_connected;
876
+ const loweredClientId = uniffiLowerString(client_id);
877
+ uniffiRustCaller.rustCall(
878
+ (status) => ffiMethod(loweredSelf, loweredClientId, status),
879
+ uniffiRustCallOptions(),
880
+ );
881
+ }
882
+
883
+ on_client_disconnected(client_id, reason) {
884
+ const loweredSelf = uniffiMqttBrokerEventListenerFactory.cloneHandle(this);
885
+ const ffiMethod =
886
+ uniffiMqttBrokerEventListenerFactory.usesGenericAbi(this)
887
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_client_disconnected_generic_abi
888
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_client_disconnected;
889
+ const loweredClientId = uniffiLowerString(client_id);
890
+ const loweredReason = uniffiLowerString(reason);
891
+ uniffiRustCaller.rustCall(
892
+ (status) => ffiMethod(loweredSelf, loweredClientId, loweredReason, status),
893
+ uniffiRustCallOptions(),
894
+ );
895
+ }
896
+
897
+ on_message_published(client_id, topic, qos) {
898
+ const loweredSelf = uniffiMqttBrokerEventListenerFactory.cloneHandle(this);
899
+ const ffiMethod =
900
+ uniffiMqttBrokerEventListenerFactory.usesGenericAbi(this)
901
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_message_published_generic_abi
902
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_message_published;
903
+ const loweredClientId = uniffiLowerString(client_id);
904
+ const loweredTopic = uniffiLowerString(topic);
905
+ const loweredQos = uniffiLowerIntoRustBuffer(FfiConverterQoS, qos);
906
+ uniffiRustCaller.rustCall(
907
+ (status) => ffiMethod(loweredSelf, loweredClientId, loweredTopic, loweredQos, status),
908
+ uniffiRustCallOptions(),
909
+ );
910
+ }
911
+ }
912
+
913
+ const uniffiMqttBrokerEventListenerFactory = createObjectFactory({
914
+ typeName: "MqttBrokerEventListener",
915
+ createInstance: () => Object.create(UniffiMqttBrokerEventListenerProxy.prototype),
916
+ cloneHandle(handle) {
917
+ return uniffiRustCaller.rustCall(
918
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_clone_mqttbrokereventlistener(handle, status),
919
+ uniffiRustCallOptions(),
920
+ );
921
+ },
922
+ freeHandle(handle) {
923
+ uniffiRustCaller.rustCall(
924
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_free_mqttbrokereventlistener(handle, status),
925
+ uniffiRustCallOptions(),
926
+ );
927
+ },
928
+ });
929
+
930
+ function uniffiValidateMqttBrokerEventListenerImplementation(implementation) {
931
+ if ((typeof implementation !== "object" && typeof implementation !== "function") || implementation == null) {
932
+ throw new TypeError(`${"MqttBrokerEventListener"} implementations must be objects with callable methods.`);
933
+ }
934
+ if (typeof implementation.on_client_connected !== "function") {
935
+ throw new TypeError(`${"MqttBrokerEventListener"} is missing required method on_client_connected().`);
936
+ }
937
+ if (typeof implementation.on_client_disconnected !== "function") {
938
+ throw new TypeError(`${"MqttBrokerEventListener"} is missing required method on_client_disconnected().`);
939
+ }
940
+ if (typeof implementation.on_message_published !== "function") {
941
+ throw new TypeError(`${"MqttBrokerEventListener"} is missing required method on_message_published().`);
942
+ }
943
+ return implementation;
944
+ }
945
+
946
+ const uniffiMqttBrokerEventListenerRegistry = createCallbackRegistry({
947
+ interfaceName: "MqttBrokerEventListener",
948
+ validate: uniffiValidateMqttBrokerEventListenerImplementation,
949
+ });
950
+
951
+ function uniffiRegisterMqttBrokerEventListenerVtable(bindings, registrations, vtableReferences) {
952
+ const on_client_connectedCallback = koffi.register(
953
+ (uniffiHandle, client_id, uniffiOutReturn, callStatus) => {
954
+ const uniffiStatus = callStatus == null
955
+ ? createRustCallStatus()
956
+ : koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
957
+ const uniffiResult = invokeCallbackMethod({
958
+ registry: uniffiMqttBrokerEventListenerRegistry,
959
+ handle: uniffiHandle,
960
+ methodName: "on_client_connected",
961
+ args: [
962
+ uniffiLiftStringFromRustBuffer(client_id),
963
+ ],
964
+ lowerString: (value) => uniffiLowerString(value),
965
+ status: uniffiStatus,
966
+ });
967
+ if (callStatus != null) {
968
+ koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
969
+ }
970
+ if (uniffiStatus.code !== CALL_SUCCESS) {
971
+ return;
972
+ }
973
+ },
974
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttBrokerEventListenerMethod0),
975
+ );
976
+ registrations.push(on_client_connectedCallback);
977
+ const on_client_disconnectedCallback = koffi.register(
978
+ (uniffiHandle, client_id, reason, uniffiOutReturn, callStatus) => {
979
+ const uniffiStatus = callStatus == null
980
+ ? createRustCallStatus()
981
+ : koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
982
+ const uniffiResult = invokeCallbackMethod({
983
+ registry: uniffiMqttBrokerEventListenerRegistry,
984
+ handle: uniffiHandle,
985
+ methodName: "on_client_disconnected",
986
+ args: [
987
+ uniffiLiftStringFromRustBuffer(client_id),
988
+ uniffiLiftStringFromRustBuffer(reason),
989
+ ],
990
+ lowerString: (value) => uniffiLowerString(value),
991
+ status: uniffiStatus,
992
+ });
993
+ if (callStatus != null) {
994
+ koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
995
+ }
996
+ if (uniffiStatus.code !== CALL_SUCCESS) {
997
+ return;
998
+ }
999
+ },
1000
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttBrokerEventListenerMethod1),
1001
+ );
1002
+ registrations.push(on_client_disconnectedCallback);
1003
+ const on_message_publishedCallback = koffi.register(
1004
+ (uniffiHandle, client_id, topic, qos, uniffiOutReturn, callStatus) => {
1005
+ const uniffiStatus = callStatus == null
1006
+ ? createRustCallStatus()
1007
+ : koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
1008
+ const uniffiResult = invokeCallbackMethod({
1009
+ registry: uniffiMqttBrokerEventListenerRegistry,
1010
+ handle: uniffiHandle,
1011
+ methodName: "on_message_published",
1012
+ args: [
1013
+ uniffiLiftStringFromRustBuffer(client_id),
1014
+ uniffiLiftStringFromRustBuffer(topic),
1015
+ uniffiLiftFromRustBuffer(FfiConverterQoS, qos),
1016
+ ],
1017
+ lowerString: (value) => uniffiLowerString(value),
1018
+ status: uniffiStatus,
1019
+ });
1020
+ if (callStatus != null) {
1021
+ koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
1022
+ }
1023
+ if (uniffiStatus.code !== CALL_SUCCESS) {
1024
+ return;
1025
+ }
1026
+ },
1027
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttBrokerEventListenerMethod2),
1028
+ );
1029
+ registrations.push(on_message_publishedCallback);
1030
+ const uniffiFree = koffi.register(
1031
+ (uniffiHandle) => uniffiMqttBrokerEventListenerRegistry.remove(uniffiHandle),
1032
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceFree),
1033
+ );
1034
+ registrations.push(uniffiFree);
1035
+ const uniffiClone = koffi.register(
1036
+ (uniffiHandle) => uniffiMqttBrokerEventListenerRegistry.cloneHandle(uniffiHandle),
1037
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceClone),
1038
+ );
1039
+ registrations.push(uniffiClone);
1040
+ const uniffiVtable = koffi.alloc(bindings.ffiStructs.VTableCallbackInterfaceMqttBrokerEventListener, 1);
1041
+ koffi.encode(uniffiVtable, bindings.ffiStructs.VTableCallbackInterfaceMqttBrokerEventListener, {
1042
+ uniffi_free: uniffiFree,
1043
+ uniffi_clone: uniffiClone,
1044
+ "on_client_connected": on_client_connectedCallback,
1045
+ "on_client_disconnected": on_client_disconnectedCallback,
1046
+ "on_message_published": on_message_publishedCallback,
1047
+
1048
+ });
1049
+ vtableReferences.push(uniffiVtable);
1050
+ bindings.ffiFunctions.uniffi_mqtt_broker_fn_init_callback_vtable_mqttbrokereventlistener(uniffiVtable);
1051
+ }
1052
+
1053
+ const FfiConverterMqttBrokerEventListener = Object.freeze({
1054
+ lower(value) {
1055
+ if (uniffiMqttBrokerEventListenerFactory.isInstance(value)) {
1056
+ return uniffiMqttBrokerEventListenerFactory.cloneHandle(value);
1057
+ }
1058
+ return uniffiMqttBrokerEventListenerRegistry.register(value);
1059
+ },
1060
+ lift(handle) {
1061
+ return uniffiMqttBrokerEventListenerFactory.create(handle);
1062
+ },
1063
+ write(value, writer) {
1064
+ writer.writeUInt64(this.lower(value));
1065
+ },
1066
+ read(reader) {
1067
+ return this.lift(reader.readUInt64());
1068
+ },
1069
+ allocationSize() {
1070
+ return UNIFFI_OBJECT_HANDLE_SIZE;
1071
+ },
1072
+ });
1073
+ class UniffiMqttEnhancedAuthProviderProxy extends UniffiObjectBase {
1074
+
1075
+ step(client_id, method, data, round) {
1076
+ const loweredSelf = uniffiMqttEnhancedAuthProviderFactory.cloneHandle(this);
1077
+ const ffiMethod =
1078
+ uniffiMqttEnhancedAuthProviderFactory.usesGenericAbi(this)
1079
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttenhancedauthprovider_step_generic_abi
1080
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttenhancedauthprovider_step;
1081
+ const loweredClientId = uniffiLowerString(client_id);
1082
+ const loweredMethod = uniffiLowerString(method);
1083
+ const loweredData = uniffiLowerIntoRustBuffer(uniffiOptionalConverter(FfiConverterBytes), data);
1084
+ const loweredRound = FfiConverterUInt32.lower(round);
1085
+ const uniffiResult = uniffiRustCaller.rustCall(
1086
+ (status) => ffiMethod(loweredSelf, loweredClientId, loweredMethod, loweredData, loweredRound, status),
1087
+ uniffiRustCallOptions(),
1088
+ );
1089
+ return uniffiLiftFromRustBuffer(FfiConverterEnhancedAuthStep, uniffiResult);
1090
+ }
1091
+ }
1092
+
1093
+ const uniffiMqttEnhancedAuthProviderFactory = createObjectFactory({
1094
+ typeName: "MqttEnhancedAuthProvider",
1095
+ createInstance: () => Object.create(UniffiMqttEnhancedAuthProviderProxy.prototype),
1096
+ cloneHandle(handle) {
1097
+ return uniffiRustCaller.rustCall(
1098
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_clone_mqttenhancedauthprovider(handle, status),
1099
+ uniffiRustCallOptions(),
1100
+ );
1101
+ },
1102
+ freeHandle(handle) {
1103
+ uniffiRustCaller.rustCall(
1104
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_free_mqttenhancedauthprovider(handle, status),
1105
+ uniffiRustCallOptions(),
1106
+ );
1107
+ },
1108
+ });
1109
+
1110
+ function uniffiValidateMqttEnhancedAuthProviderImplementation(implementation) {
1111
+ if ((typeof implementation !== "object" && typeof implementation !== "function") || implementation == null) {
1112
+ throw new TypeError(`${"MqttEnhancedAuthProvider"} implementations must be objects with callable methods.`);
1113
+ }
1114
+ if (typeof implementation.step !== "function") {
1115
+ throw new TypeError(`${"MqttEnhancedAuthProvider"} is missing required method step().`);
1116
+ }
1117
+ return implementation;
1118
+ }
1119
+
1120
+ const uniffiMqttEnhancedAuthProviderRegistry = createCallbackRegistry({
1121
+ interfaceName: "MqttEnhancedAuthProvider",
1122
+ validate: uniffiValidateMqttEnhancedAuthProviderImplementation,
1123
+ });
1124
+
1125
+ function uniffiRegisterMqttEnhancedAuthProviderVtable(bindings, registrations, vtableReferences) {
1126
+ const stepCallback = koffi.register(
1127
+ (uniffiHandle, client_id, method, data, round, uniffiOutReturn, callStatus) => {
1128
+ const uniffiStatus = callStatus == null
1129
+ ? createRustCallStatus()
1130
+ : koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
1131
+ const uniffiResult = invokeCallbackMethod({
1132
+ registry: uniffiMqttEnhancedAuthProviderRegistry,
1133
+ handle: uniffiHandle,
1134
+ methodName: "step",
1135
+ args: [
1136
+ uniffiLiftStringFromRustBuffer(client_id),
1137
+ uniffiLiftStringFromRustBuffer(method),
1138
+ uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterBytes), data),
1139
+ FfiConverterUInt32.lift(round),
1140
+ ],
1141
+ lowerString: (value) => uniffiLowerString(value),
1142
+ status: uniffiStatus,
1143
+ });
1144
+ if (callStatus != null) {
1145
+ koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
1146
+ }
1147
+ if (uniffiStatus.code !== CALL_SUCCESS) {
1148
+ return;
1149
+ }
1150
+ const loweredReturn = uniffiLowerIntoRustBuffer(FfiConverterEnhancedAuthStep, uniffiResult);
1151
+ koffi.encode(uniffiOutReturn, bindings.ffiTypes.RustBuffer, loweredReturn);
1152
+ },
1153
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttEnhancedAuthProviderMethod0),
1154
+ );
1155
+ registrations.push(stepCallback);
1156
+ const uniffiFree = koffi.register(
1157
+ (uniffiHandle) => uniffiMqttEnhancedAuthProviderRegistry.remove(uniffiHandle),
1158
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceFree),
1159
+ );
1160
+ registrations.push(uniffiFree);
1161
+ const uniffiClone = koffi.register(
1162
+ (uniffiHandle) => uniffiMqttEnhancedAuthProviderRegistry.cloneHandle(uniffiHandle),
1163
+ koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceClone),
1164
+ );
1165
+ registrations.push(uniffiClone);
1166
+ const uniffiVtable = koffi.alloc(bindings.ffiStructs.VTableCallbackInterfaceMqttEnhancedAuthProvider, 1);
1167
+ koffi.encode(uniffiVtable, bindings.ffiStructs.VTableCallbackInterfaceMqttEnhancedAuthProvider, {
1168
+ uniffi_free: uniffiFree,
1169
+ uniffi_clone: uniffiClone,
1170
+ "step": stepCallback,
1171
+
1172
+ });
1173
+ vtableReferences.push(uniffiVtable);
1174
+ bindings.ffiFunctions.uniffi_mqtt_broker_fn_init_callback_vtable_mqttenhancedauthprovider(uniffiVtable);
1175
+ }
1176
+
1177
+ const FfiConverterMqttEnhancedAuthProvider = Object.freeze({
1178
+ lower(value) {
1179
+ if (uniffiMqttEnhancedAuthProviderFactory.isInstance(value)) {
1180
+ return uniffiMqttEnhancedAuthProviderFactory.cloneHandle(value);
1181
+ }
1182
+ return uniffiMqttEnhancedAuthProviderRegistry.register(value);
1183
+ },
1184
+ lift(handle) {
1185
+ return uniffiMqttEnhancedAuthProviderFactory.create(handle);
1186
+ },
1187
+ write(value, writer) {
1188
+ writer.writeUInt64(this.lower(value));
1189
+ },
1190
+ read(reader) {
1191
+ return this.lift(reader.readUInt64());
1192
+ },
1193
+ allocationSize() {
1194
+ return UNIFFI_OBJECT_HANDLE_SIZE;
1195
+ },
1196
+ });
1197
+
1198
+ const uniffiRegisteredCallbackPointers = [];
1199
+ const uniffiRegisteredCallbackVtables = [];
1200
+
1201
+ function uniffiRegisterCallbackVtables(bindings) {
1202
+ uniffiRegisterMqttAuthProviderVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
1203
+ uniffiRegisterMqttBrokerEventListenerVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
1204
+ uniffiRegisterMqttEnhancedAuthProviderVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
1205
+ }
1206
+
1207
+ function uniffiUnregisterCallbackVtables() {
1208
+ clearPendingForeignFutures();
1209
+ uniffiMqttAuthProviderRegistry.clear();
1210
+ uniffiMqttBrokerEventListenerRegistry.clear();
1211
+ uniffiMqttEnhancedAuthProviderRegistry.clear();
1212
+ while (uniffiRegisteredCallbackPointers.length > 0) {
1213
+ koffi.unregister(uniffiRegisteredCallbackPointers.pop());
1214
+ }
1215
+ uniffiRegisteredCallbackVtables.length = 0;
1216
+ }
1217
+
1218
+ configureRuntimeHooks({
1219
+ onLoad(bindings) {
1220
+ uniffiRegisterCallbackVtables(bindings);
1221
+ },
1222
+ onUnload() {
1223
+ if (uniffiRustFutureContinuationPointer != null) {
1224
+ koffi.unregister(uniffiRustFutureContinuationPointer);
1225
+ uniffiRustFutureContinuationPointer = null;
1226
+ }
1227
+ uniffiUnregisterCallbackVtables();
1228
+ },
1229
+ });
1230
+
1231
+ /**
1232
+ * A running (or not-yet-started) MQTT broker instance, speaking both MQTT
1233
+ * 3.1.1 and MQTT 5.0 — the protocol version is negotiated independently
1234
+ * per connection from each client's CONNECT packet.
1235
+ *
1236
+ * Dropping a broker stops it (listeners are closed and live connections
1237
+ * told to shut down); there is no way to reach a broker that has no
1238
+ * remaining handle, so leaving it running would just leak its ports.
1239
+ */
1240
+ export class MqttBroker extends UniffiObjectBase {
1241
+ constructor(config) {
1242
+ super();
1243
+ const loweredConfig = uniffiLowerIntoRustBuffer(FfiConverterMqttBrokerConfig, config);
1244
+ const pointer = uniffiRustCaller.rustCall(
1245
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_constructor_mqttbroker_new(loweredConfig, status),
1246
+ uniffiRustCallOptions(),
1247
+ );
1248
+ return uniffiMqttBrokerObjectFactory.attach(this, pointer);
1249
+ }
1250
+
1251
+ /**
1252
+ * The TCP port actually bound (useful when `config.port == 0` was used
1253
+ * to request an ephemeral port, e.g. in tests).
1254
+ */
1255
+ bound_port() {
1256
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1257
+ const ffiMethod =
1258
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1259
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_bound_port_generic_abi
1260
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_bound_port;
1261
+ const uniffiResult = uniffiRustCaller.rustCall(
1262
+ (status) => ffiMethod(loweredSelf, status),
1263
+ uniffiRustCallOptions(),
1264
+ );
1265
+ return uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterUInt16), uniffiResult);
1266
+ }
1267
+
1268
+ /**
1269
+ * The TLS port actually bound, if `config.tls` is set.
1270
+ */
1271
+ bound_tls_port() {
1272
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1273
+ const ffiMethod =
1274
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1275
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_bound_tls_port_generic_abi
1276
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_bound_tls_port;
1277
+ const uniffiResult = uniffiRustCaller.rustCall(
1278
+ (status) => ffiMethod(loweredSelf, status),
1279
+ uniffiRustCallOptions(),
1280
+ );
1281
+ return uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterUInt16), uniffiResult);
1282
+ }
1283
+
1284
+ /**
1285
+ * The WebSocket port actually bound, if `config.ws_port` is set.
1286
+ */
1287
+ bound_ws_port() {
1288
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1289
+ const ffiMethod =
1290
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1291
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_bound_ws_port_generic_abi
1292
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_bound_ws_port;
1293
+ const uniffiResult = uniffiRustCaller.rustCall(
1294
+ (status) => ffiMethod(loweredSelf, status),
1295
+ uniffiRustCallOptions(),
1296
+ );
1297
+ return uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterUInt16), uniffiResult);
1298
+ }
1299
+
1300
+ /**
1301
+ * Number of currently connected clients.
1302
+ */
1303
+ client_count() {
1304
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1305
+ const ffiMethod =
1306
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1307
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_client_count_generic_abi
1308
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_client_count;
1309
+ const uniffiResult = uniffiRustCaller.rustCall(
1310
+ (status) => ffiMethod(loweredSelf, status),
1311
+ uniffiRustCallOptions(),
1312
+ );
1313
+ return FfiConverterUInt32.lift(uniffiResult);
1314
+ }
1315
+
1316
+ /**
1317
+ * Pull-style authentication for runtimes that can't implement
1318
+ * [`MqttAuthProvider`] (Dart, Haskell). Once enabled — and with no
1319
+ * provider set — every CONNECT is queued as an [`AuthRequest`](crate::AuthRequest)
1320
+ * for [`next_auth_request`](Self::next_auth_request); answer it with
1321
+ * [`resolve_auth_request`](Self::resolve_auth_request). A request left
1322
+ * unanswered for 10 seconds, or dropped because more than `capacity` are
1323
+ * waiting, is **denied**. `0` disables the queue (and denies anything
1324
+ * waiting); the broker then falls back to `allow_anonymous`.
1325
+ */
1326
+ enable_auth_queue(capacity) {
1327
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1328
+ const ffiMethod =
1329
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1330
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_enable_auth_queue_generic_abi
1331
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_enable_auth_queue;
1332
+ const loweredCapacity = FfiConverterUInt32.lower(capacity);
1333
+ uniffiRustCaller.rustCall(
1334
+ (status) => ffiMethod(loweredSelf, loweredCapacity, status),
1335
+ uniffiRustCallOptions(),
1336
+ );
1337
+ }
1338
+
1339
+ /**
1340
+ * Pull-style alternative to [`set_event_listener`](Self::set_event_listener)
1341
+ * for runtimes that can't receive callbacks from Rust threads (Dart,
1342
+ * Haskell): keep up to `capacity` events for [`next_event`](Self::next_event).
1343
+ * `0` turns the queue off; when it fills up the oldest event is dropped.
1344
+ */
1345
+ enable_event_queue(capacity) {
1346
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1347
+ const ffiMethod =
1348
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1349
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_enable_event_queue_generic_abi
1350
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_enable_event_queue;
1351
+ const loweredCapacity = FfiConverterUInt32.lower(capacity);
1352
+ uniffiRustCaller.rustCall(
1353
+ (status) => ffiMethod(loweredSelf, loweredCapacity, status),
1354
+ uniffiRustCallOptions(),
1355
+ );
1356
+ }
1357
+
1358
+ is_running() {
1359
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1360
+ const ffiMethod =
1361
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1362
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_is_running_generic_abi
1363
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_is_running;
1364
+ const uniffiResult = uniffiRustCaller.rustCall(
1365
+ (status) => ffiMethod(loweredSelf, status),
1366
+ uniffiRustCallOptions(),
1367
+ );
1368
+ return FfiConverterBool.lift(uniffiResult);
1369
+ }
1370
+
1371
+ /**
1372
+ * The next CONNECT awaiting a decision, waiting up to `timeout_ms`
1373
+ * milliseconds; `None` if none arrived. Requires
1374
+ * [`enable_auth_queue`](Self::enable_auth_queue).
1375
+ */
1376
+ async next_auth_request(timeout_ms) {
1377
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1378
+ const ffiMethod =
1379
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1380
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_next_auth_request_generic_abi
1381
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_next_auth_request;
1382
+ const loweredTimeoutMs = FfiConverterUInt32.lower(timeout_ms);
1383
+ const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_broker_rust_future_complete_rust_buffer(rustFuture, status);
1384
+ return rustCallAsync({
1385
+ rustFutureFunc: () => ffiMethod(loweredSelf, loweredTimeoutMs),
1386
+ pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_broker_rust_future_poll_rust_buffer(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
1387
+ cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_broker_rust_future_cancel_rust_buffer(rustFuture),
1388
+ completeFunc,
1389
+ freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_broker_rust_future_free_rust_buffer(rustFuture),
1390
+ liftFunc: (uniffiResult) => uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterAuthRequest), uniffiResult),
1391
+ ...uniffiRustCallOptions(),
1392
+ });
1393
+ }
1394
+
1395
+ /**
1396
+ * The next queued [`BrokerEvent`], waiting up to `timeout_ms`
1397
+ * milliseconds; `None` if none arrived. Requires
1398
+ * [`enable_event_queue`](Self::enable_event_queue).
1399
+ */
1400
+ async next_event(timeout_ms) {
1401
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1402
+ const ffiMethod =
1403
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1404
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_next_event_generic_abi
1405
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_next_event;
1406
+ const loweredTimeoutMs = FfiConverterUInt32.lower(timeout_ms);
1407
+ const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_broker_rust_future_complete_rust_buffer(rustFuture, status);
1408
+ return rustCallAsync({
1409
+ rustFutureFunc: () => ffiMethod(loweredSelf, loweredTimeoutMs),
1410
+ pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_broker_rust_future_poll_rust_buffer(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
1411
+ cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_broker_rust_future_cancel_rust_buffer(rustFuture),
1412
+ completeFunc,
1413
+ freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_broker_rust_future_free_rust_buffer(rustFuture),
1414
+ liftFunc: (uniffiResult) => uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterBrokerEvent), uniffiResult),
1415
+ ...uniffiRustCallOptions(),
1416
+ });
1417
+ }
1418
+
1419
+ /**
1420
+ * Admit (`allow = true`) or refuse the CONNECT behind request `id`.
1421
+ * Returns `false` if the request is unknown or already expired.
1422
+ */
1423
+ resolve_auth_request(id, allow) {
1424
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1425
+ const ffiMethod =
1426
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1427
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_resolve_auth_request_generic_abi
1428
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_resolve_auth_request;
1429
+ const loweredId = FfiConverterUInt64.lower(id);
1430
+ const loweredAllow = FfiConverterBool.lower(allow);
1431
+ const uniffiResult = uniffiRustCaller.rustCall(
1432
+ (status) => ffiMethod(loweredSelf, loweredId, loweredAllow, status),
1433
+ uniffiRustCallOptions(),
1434
+ );
1435
+ return FfiConverterBool.lift(uniffiResult);
1436
+ }
1437
+
1438
+ /**
1439
+ * Register a pluggable authentication provider. Must be called before
1440
+ * [`start`](Self::start) to affect connections made right away, but
1441
+ * may be replaced at any time.
1442
+ */
1443
+ set_auth_provider(provider) {
1444
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1445
+ const ffiMethod =
1446
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1447
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_auth_provider_generic_abi
1448
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_auth_provider;
1449
+ const loweredProvider = FfiConverterMqttAuthProvider.lower(provider);
1450
+ uniffiRustCaller.rustCall(
1451
+ (status) => ffiMethod(loweredSelf, loweredProvider, status),
1452
+ uniffiRustCallOptions(),
1453
+ );
1454
+ }
1455
+
1456
+ /**
1457
+ * Register the MQTT 5.0 enhanced-authentication provider (multi-round
1458
+ * challenge/response during CONNECT). Without one, a CONNECT that names
1459
+ * an `Authentication Method` is refused with "Bad authentication method".
1460
+ */
1461
+ set_enhanced_auth_provider(provider) {
1462
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1463
+ const ffiMethod =
1464
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1465
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_enhanced_auth_provider_generic_abi
1466
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_enhanced_auth_provider;
1467
+ const loweredProvider = FfiConverterMqttEnhancedAuthProvider.lower(provider);
1468
+ uniffiRustCaller.rustCall(
1469
+ (status) => ffiMethod(loweredSelf, loweredProvider, status),
1470
+ uniffiRustCallOptions(),
1471
+ );
1472
+ }
1473
+
1474
+ /**
1475
+ * Register a listener for connect/disconnect/publish events.
1476
+ */
1477
+ set_event_listener(listener) {
1478
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1479
+ const ffiMethod =
1480
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1481
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_event_listener_generic_abi
1482
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_event_listener;
1483
+ const loweredListener = FfiConverterMqttBrokerEventListener.lower(listener);
1484
+ uniffiRustCaller.rustCall(
1485
+ (status) => ffiMethod(loweredSelf, loweredListener, status),
1486
+ uniffiRustCallOptions(),
1487
+ );
1488
+ }
1489
+
1490
+ /**
1491
+ * Bind the listening socket(s) and start accepting connections. Also
1492
+ * binds a second, MQTT-over-WebSocket listener on `config.ws_port` and
1493
+ * a TLS listener on `config.tls` when those are configured.
1494
+ *
1495
+ * All-or-nothing: every socket is bound (and the TLS configuration
1496
+ * validated) *before* anything starts accepting, so a failure — say
1497
+ * the WebSocket port is taken — leaves the broker cleanly stopped
1498
+ * instead of half-running with some listeners already live.
1499
+ */
1500
+ async start() {
1501
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1502
+ const ffiMethod =
1503
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1504
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_start_generic_abi
1505
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_start;
1506
+ const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_broker_rust_future_complete_void(rustFuture, status);
1507
+ return rustCallAsync({
1508
+ rustFutureFunc: () => ffiMethod(loweredSelf),
1509
+ pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_broker_rust_future_poll_void(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
1510
+ cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_broker_rust_future_cancel_void(rustFuture),
1511
+ completeFunc,
1512
+ freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_broker_rust_future_free_void(rustFuture),
1513
+ liftFunc: (_uniffiResult) => undefined,
1514
+ ...uniffiRustCallOptions(FfiConverterMqttBrokerError),
1515
+ });
1516
+ }
1517
+
1518
+ /**
1519
+ * Stop the broker: close the listening sockets and ask every
1520
+ * connected client's connection to shut down. Sessions that persist
1521
+ * across disconnects (`clean_start = false`) are kept in memory, so a
1522
+ * later [`start`](Self::start) resumes them. Calling `stop()` on a
1523
+ * broker that isn't running is a no-op.
1524
+ */
1525
+ async stop() {
1526
+ const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
1527
+ const ffiMethod =
1528
+ uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
1529
+ ? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_stop_generic_abi
1530
+ : ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_stop;
1531
+ const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_broker_rust_future_complete_void(rustFuture, status);
1532
+ return rustCallAsync({
1533
+ rustFutureFunc: () => ffiMethod(loweredSelf),
1534
+ pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_broker_rust_future_poll_void(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
1535
+ cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_broker_rust_future_cancel_void(rustFuture),
1536
+ completeFunc,
1537
+ freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_broker_rust_future_free_void(rustFuture),
1538
+ liftFunc: (_uniffiResult) => undefined,
1539
+ ...uniffiRustCallOptions(FfiConverterMqttBrokerError),
1540
+ });
1541
+ }
1542
+ }
1543
+
1544
+ const uniffiMqttBrokerObjectFactory = createObjectFactory({
1545
+ typeName: "MqttBroker",
1546
+ createInstance: () => Object.create(MqttBroker.prototype),
1547
+ cloneFreeUsesUniffiHandle: true,
1548
+ cloneHandleGeneric(handle) {
1549
+ return uniffiRustCaller.rustCall(
1550
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_clone_mqttbroker_generic_abi(handle, status),
1551
+ uniffiRustCallOptions(),
1552
+ );
1553
+ },
1554
+ cloneHandleRawExternal(handle) {
1555
+ const rawExternalCloneHandle = uniffiGetCachedLibraryFunction(
1556
+ "uniffi_mqtt_broker_fn_clone_mqttbroker:raw-external",
1557
+ (bindings) => bindings.library.func(
1558
+ "uniffi_mqtt_broker_fn_clone_mqttbroker",
1559
+ bindings.ffiTypes.VoidPointer,
1560
+ [bindings.ffiTypes.VoidPointer, koffi.pointer(bindings.ffiTypes.RustCallStatus)],
1561
+ ),
1562
+ );
1563
+ return uniffiRustCaller.rustCall(
1564
+ (status) => rawExternalCloneHandle(handle, status),
1565
+ uniffiRustCallOptions(),
1566
+ );
1567
+ },
1568
+ cloneHandle(handle) {
1569
+ return uniffiRustCaller.rustCall(
1570
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_clone_mqttbroker(handle, status),
1571
+ uniffiRustCallOptions(),
1572
+ );
1573
+ },
1574
+ freeHandleGeneric(handle) {
1575
+ uniffiRustCaller.rustCall(
1576
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_free_mqttbroker_generic_abi(handle, status),
1577
+ uniffiRustCallOptions(),
1578
+ );
1579
+ },
1580
+ freeHandleRawExternal(handle) {
1581
+ const rawExternalFreeHandle = uniffiGetCachedLibraryFunction(
1582
+ "uniffi_mqtt_broker_fn_free_mqttbroker:raw-external",
1583
+ (bindings) => bindings.library.func(
1584
+ "uniffi_mqtt_broker_fn_free_mqttbroker",
1585
+ "void",
1586
+ [bindings.ffiTypes.VoidPointer, koffi.pointer(bindings.ffiTypes.RustCallStatus)],
1587
+ ),
1588
+ );
1589
+ uniffiRustCaller.rustCall(
1590
+ (status) => rawExternalFreeHandle(handle, status),
1591
+ uniffiRustCallOptions(),
1592
+ );
1593
+ },
1594
+ freeHandle(handle) {
1595
+ uniffiRustCaller.rustCall(
1596
+ (status) => ffiFunctions.uniffi_mqtt_broker_fn_free_mqttbroker(handle, status),
1597
+ uniffiRustCallOptions(),
1598
+ );
1599
+ },
1600
+ });
1601
+ const FfiConverterMqttBroker = createObjectConverter(uniffiMqttBrokerObjectFactory);