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.
- package/LICENSE +21 -0
- package/README.md +176 -2
- package/broker/index.d.ts +1 -0
- package/broker/index.js +7 -0
- package/broker/mqtt_broker-ffi.d.ts +259 -0
- package/broker/mqtt_broker-ffi.js +3936 -0
- package/broker/mqtt_broker.d.ts +419 -0
- package/broker/mqtt_broker.js +1601 -0
- package/broker/package.json +12 -0
- package/broker/prebuilds/linux-x64-gnu/libmqtt_broker.so +0 -0
- package/client/index.d.ts +1 -0
- package/client/index.js +7 -0
- package/client/mqtt_client-ffi.d.ts +229 -0
- package/client/mqtt_client-ffi.js +3439 -0
- package/client/mqtt_client.d.ts +432 -0
- package/client/mqtt_client.js +1467 -0
- package/client/package.json +12 -0
- package/client/prebuilds/linux-x64-gnu/libmqtt_client.so +0 -0
- package/package.json +49 -3
- package/runtime/async-rust-call.d.ts +86 -0
- package/runtime/async-rust-call.js +217 -0
- package/runtime/callbacks.d.ts +122 -0
- package/runtime/callbacks.js +392 -0
- package/runtime/errors.d.ts +120 -0
- package/runtime/errors.js +274 -0
- package/runtime/ffi-converters.d.ts +100 -0
- package/runtime/ffi-converters.js +758 -0
- package/runtime/ffi-types.d.ts +120 -0
- package/runtime/ffi-types.js +456 -0
- package/runtime/handle-map.d.ts +35 -0
- package/runtime/handle-map.js +137 -0
- package/runtime/objects.d.ts +68 -0
- package/runtime/objects.js +469 -0
- package/runtime/rust-call.d.ts +77 -0
- package/runtime/rust-call.js +233 -0
|
@@ -0,0 +1,1467 @@
|
|
|
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_client-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
|
+
FfiConverterUInt8,
|
|
41
|
+
|
|
42
|
+
FfiConverterUInt16,
|
|
43
|
+
|
|
44
|
+
FfiConverterUInt32,
|
|
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_client",
|
|
102
|
+
packageName: "mqtt_client",
|
|
103
|
+
cdylibName: "mqtt_client",
|
|
104
|
+
nodeEngine: ">=16",
|
|
105
|
+
bundledPrebuilds: true,
|
|
106
|
+
manualLoad: false,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export { ffiMetadata } from "./mqtt_client-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_client_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_client_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 MQTT protocol version negotiated for a connection.
|
|
353
|
+
*/
|
|
354
|
+
export const MqttVersion = Object.freeze({
|
|
355
|
+
/**
|
|
356
|
+
* MQTT 3.1.1 (protocol level 4).
|
|
357
|
+
*/
|
|
358
|
+
"V311": "V311",
|
|
359
|
+
/**
|
|
360
|
+
* MQTT 5.0 (protocol level 5).
|
|
361
|
+
*/
|
|
362
|
+
"V5": "V5",
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* MQTT Quality of Service level.
|
|
367
|
+
*/
|
|
368
|
+
export const QoS = Object.freeze({
|
|
369
|
+
/**
|
|
370
|
+
* QoS 0 — fire and forget, no acknowledgement.
|
|
371
|
+
*/
|
|
372
|
+
"AtMostOnce": "AtMostOnce",
|
|
373
|
+
/**
|
|
374
|
+
* QoS 1 — acknowledged delivery, may be duplicated.
|
|
375
|
+
*/
|
|
376
|
+
"AtLeastOnce": "AtLeastOnce",
|
|
377
|
+
/**
|
|
378
|
+
* QoS 2 — exactly-once delivery via a four-part handshake.
|
|
379
|
+
*/
|
|
380
|
+
"ExactlyOnce": "ExactlyOnce",
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* All errors that can be produced while encoding/decoding MQTT packets or
|
|
385
|
+
* operating an [`crate::client::MqttClient`].
|
|
386
|
+
*
|
|
387
|
+
* Exposed to foreign languages through UniFFI as a plain error enum.
|
|
388
|
+
*/
|
|
389
|
+
export class MqttError extends globalThis.Error {
|
|
390
|
+
constructor(tag, message = tag) {
|
|
391
|
+
super(message);
|
|
392
|
+
this.name = "MqttError";
|
|
393
|
+
this.tag = tag;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* The peer sent a packet that violates the MQTT specification.
|
|
399
|
+
*/
|
|
400
|
+
export class MqttErrorMalformedPacket extends MqttError {
|
|
401
|
+
constructor(message = undefined) {
|
|
402
|
+
super("MalformedPacket", message ?? "MalformedPacket");
|
|
403
|
+
this.name = "MqttErrorMalformedPacket";
|
|
404
|
+
this.message = message ?? "MalformedPacket";
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* A value could not be encoded/decoded per the wire protocol.
|
|
410
|
+
*/
|
|
411
|
+
export class MqttErrorProtocol extends MqttError {
|
|
412
|
+
constructor(message = undefined) {
|
|
413
|
+
super("Protocol", message ?? "Protocol");
|
|
414
|
+
this.name = "MqttErrorProtocol";
|
|
415
|
+
this.message = message ?? "Protocol";
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Underlying I/O failure (connection reset, DNS failure, etc.).
|
|
421
|
+
*/
|
|
422
|
+
export class MqttErrorIo extends MqttError {
|
|
423
|
+
constructor(message = undefined) {
|
|
424
|
+
super("Io", message ?? "Io");
|
|
425
|
+
this.name = "MqttErrorIo";
|
|
426
|
+
this.message = message ?? "Io";
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* The broker rejected the connection attempt.
|
|
432
|
+
*/
|
|
433
|
+
export class MqttErrorConnectionRefused extends MqttError {
|
|
434
|
+
constructor(message = undefined) {
|
|
435
|
+
super("ConnectionRefused", message ?? "ConnectionRefused");
|
|
436
|
+
this.name = "MqttErrorConnectionRefused";
|
|
437
|
+
this.message = message ?? "ConnectionRefused";
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* An operation was attempted while not connected to a broker.
|
|
443
|
+
*/
|
|
444
|
+
export class MqttErrorNotConnected extends MqttError {
|
|
445
|
+
constructor(message = undefined) {
|
|
446
|
+
super("NotConnected", message ?? "NotConnected");
|
|
447
|
+
this.name = "MqttErrorNotConnected";
|
|
448
|
+
this.message = message ?? "NotConnected";
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* A packet's declared size exceeds the configured maximum packet size.
|
|
454
|
+
*/
|
|
455
|
+
export class MqttErrorPacketTooLarge extends MqttError {
|
|
456
|
+
constructor(message = undefined) {
|
|
457
|
+
super("PacketTooLarge", message ?? "PacketTooLarge");
|
|
458
|
+
this.name = "MqttErrorPacketTooLarge";
|
|
459
|
+
this.message = message ?? "PacketTooLarge";
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* The client is already connected.
|
|
465
|
+
*/
|
|
466
|
+
export class MqttErrorAlreadyConnected extends MqttError {
|
|
467
|
+
constructor(message = undefined) {
|
|
468
|
+
super("AlreadyConnected", message ?? "AlreadyConnected");
|
|
469
|
+
this.name = "MqttErrorAlreadyConnected";
|
|
470
|
+
this.message = message ?? "AlreadyConnected";
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* The peer did not acknowledge a QoS 1/2 packet before the timeout.
|
|
476
|
+
*/
|
|
477
|
+
export class MqttErrorTimeout extends MqttError {
|
|
478
|
+
constructor(message = undefined) {
|
|
479
|
+
super("Timeout", message ?? "Timeout");
|
|
480
|
+
this.name = "MqttErrorTimeout";
|
|
481
|
+
this.message = message ?? "Timeout";
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Generic keep-alive / session error.
|
|
487
|
+
*/
|
|
488
|
+
export class MqttErrorSession extends MqttError {
|
|
489
|
+
constructor(message = undefined) {
|
|
490
|
+
super("Session", message ?? "Session");
|
|
491
|
+
this.name = "MqttErrorSession";
|
|
492
|
+
this.message = message ?? "Session";
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const FfiConverterConnectOptions = new (class extends AbstractFfiConverterByteArray {
|
|
497
|
+
allocationSize(value) {
|
|
498
|
+
const recordValue = uniffiRequireRecordObject("ConnectOptions", value);
|
|
499
|
+
return FfiConverterString.allocationSize(recordValue["host"]) + FfiConverterUInt16.allocationSize(recordValue["port"]) + FfiConverterString.allocationSize(recordValue["client_id"]) + FfiConverterMqttVersion.allocationSize(recordValue["version"]) + FfiConverterBool.allocationSize(recordValue["clean_start"]) + FfiConverterUInt16.allocationSize(recordValue["keep_alive_secs"]) + uniffiOptionalConverter(FfiConverterString).allocationSize(recordValue["username"]) + uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["password"]) + uniffiOptionalConverter(FfiConverterWillOptions).allocationSize(recordValue["will"]) + FfiConverterUInt32.allocationSize(recordValue["connect_timeout_secs"]) + FfiConverterUInt32.allocationSize(recordValue["operation_timeout_secs"]) + FfiConverterBool.allocationSize(recordValue["auto_reconnect"]) + FfiConverterUInt32.allocationSize(recordValue["reconnect_backoff_secs"]) + FfiConverterUInt32.allocationSize(recordValue["reconnect_max_backoff_secs"]) + uniffiOptionalConverter(FfiConverterTlsOptions).allocationSize(recordValue["tls"]) + FfiConverterUInt32.allocationSize(recordValue["max_packet_size"]) + uniffiOptionalConverter(FfiConverterString).allocationSize(recordValue["auth_method"]) + uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["auth_data"]);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
write(value, writer) {
|
|
503
|
+
const recordValue = uniffiRequireRecordObject("ConnectOptions", value);
|
|
504
|
+
FfiConverterString.write(recordValue["host"], writer);
|
|
505
|
+
FfiConverterUInt16.write(recordValue["port"], writer);
|
|
506
|
+
FfiConverterString.write(recordValue["client_id"], writer);
|
|
507
|
+
FfiConverterMqttVersion.write(recordValue["version"], writer);
|
|
508
|
+
FfiConverterBool.write(recordValue["clean_start"], writer);
|
|
509
|
+
FfiConverterUInt16.write(recordValue["keep_alive_secs"], writer);
|
|
510
|
+
uniffiOptionalConverter(FfiConverterString).write(recordValue["username"], writer);
|
|
511
|
+
uniffiOptionalConverter(FfiConverterBytes).write(recordValue["password"], writer);
|
|
512
|
+
uniffiOptionalConverter(FfiConverterWillOptions).write(recordValue["will"], writer);
|
|
513
|
+
FfiConverterUInt32.write(recordValue["connect_timeout_secs"], writer);
|
|
514
|
+
FfiConverterUInt32.write(recordValue["operation_timeout_secs"], writer);
|
|
515
|
+
FfiConverterBool.write(recordValue["auto_reconnect"], writer);
|
|
516
|
+
FfiConverterUInt32.write(recordValue["reconnect_backoff_secs"], writer);
|
|
517
|
+
FfiConverterUInt32.write(recordValue["reconnect_max_backoff_secs"], writer);
|
|
518
|
+
uniffiOptionalConverter(FfiConverterTlsOptions).write(recordValue["tls"], writer);
|
|
519
|
+
FfiConverterUInt32.write(recordValue["max_packet_size"], writer);
|
|
520
|
+
uniffiOptionalConverter(FfiConverterString).write(recordValue["auth_method"], writer);
|
|
521
|
+
uniffiOptionalConverter(FfiConverterBytes).write(recordValue["auth_data"], writer);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
read(reader) {
|
|
525
|
+
return {
|
|
526
|
+
"host": FfiConverterString.read(reader),
|
|
527
|
+
"port": FfiConverterUInt16.read(reader),
|
|
528
|
+
"client_id": FfiConverterString.read(reader),
|
|
529
|
+
"version": FfiConverterMqttVersion.read(reader),
|
|
530
|
+
"clean_start": FfiConverterBool.read(reader),
|
|
531
|
+
"keep_alive_secs": FfiConverterUInt16.read(reader),
|
|
532
|
+
"username": uniffiOptionalConverter(FfiConverterString).read(reader),
|
|
533
|
+
"password": uniffiOptionalConverter(FfiConverterBytes).read(reader),
|
|
534
|
+
"will": uniffiOptionalConverter(FfiConverterWillOptions).read(reader),
|
|
535
|
+
"connect_timeout_secs": FfiConverterUInt32.read(reader),
|
|
536
|
+
"operation_timeout_secs": FfiConverterUInt32.read(reader),
|
|
537
|
+
"auto_reconnect": FfiConverterBool.read(reader),
|
|
538
|
+
"reconnect_backoff_secs": FfiConverterUInt32.read(reader),
|
|
539
|
+
"reconnect_max_backoff_secs": FfiConverterUInt32.read(reader),
|
|
540
|
+
"tls": uniffiOptionalConverter(FfiConverterTlsOptions).read(reader),
|
|
541
|
+
"max_packet_size": FfiConverterUInt32.read(reader),
|
|
542
|
+
"auth_method": uniffiOptionalConverter(FfiConverterString).read(reader),
|
|
543
|
+
"auth_data": uniffiOptionalConverter(FfiConverterBytes).read(reader),
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
})();
|
|
547
|
+
const FfiConverterConnectResult = new (class extends AbstractFfiConverterByteArray {
|
|
548
|
+
allocationSize(value) {
|
|
549
|
+
const recordValue = uniffiRequireRecordObject("ConnectResult", value);
|
|
550
|
+
return FfiConverterBool.allocationSize(recordValue["session_present"]) + FfiConverterUInt8.allocationSize(recordValue["reason_code"]);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
write(value, writer) {
|
|
554
|
+
const recordValue = uniffiRequireRecordObject("ConnectResult", value);
|
|
555
|
+
FfiConverterBool.write(recordValue["session_present"], writer);
|
|
556
|
+
FfiConverterUInt8.write(recordValue["reason_code"], writer);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
read(reader) {
|
|
560
|
+
return {
|
|
561
|
+
"session_present": FfiConverterBool.read(reader),
|
|
562
|
+
"reason_code": FfiConverterUInt8.read(reader),
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
})();
|
|
566
|
+
const FfiConverterMqttMessage = new (class extends AbstractFfiConverterByteArray {
|
|
567
|
+
allocationSize(value) {
|
|
568
|
+
const recordValue = uniffiRequireRecordObject("MqttMessage", value);
|
|
569
|
+
return FfiConverterString.allocationSize(recordValue["topic"]) + FfiConverterBytes.allocationSize(recordValue["payload"]) + FfiConverterQoS.allocationSize(recordValue["qos"]) + FfiConverterBool.allocationSize(recordValue["retain"]);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
write(value, writer) {
|
|
573
|
+
const recordValue = uniffiRequireRecordObject("MqttMessage", value);
|
|
574
|
+
FfiConverterString.write(recordValue["topic"], writer);
|
|
575
|
+
FfiConverterBytes.write(recordValue["payload"], writer);
|
|
576
|
+
FfiConverterQoS.write(recordValue["qos"], writer);
|
|
577
|
+
FfiConverterBool.write(recordValue["retain"], writer);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
read(reader) {
|
|
581
|
+
return {
|
|
582
|
+
"topic": FfiConverterString.read(reader),
|
|
583
|
+
"payload": FfiConverterBytes.read(reader),
|
|
584
|
+
"qos": FfiConverterQoS.read(reader),
|
|
585
|
+
"retain": FfiConverterBool.read(reader),
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
})();
|
|
589
|
+
const FfiConverterSubscribeResult = new (class extends AbstractFfiConverterByteArray {
|
|
590
|
+
allocationSize(value) {
|
|
591
|
+
const recordValue = uniffiRequireRecordObject("SubscribeResult", value);
|
|
592
|
+
return FfiConverterUInt8.allocationSize(recordValue["reason_code"]);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
write(value, writer) {
|
|
596
|
+
const recordValue = uniffiRequireRecordObject("SubscribeResult", value);
|
|
597
|
+
FfiConverterUInt8.write(recordValue["reason_code"], writer);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
read(reader) {
|
|
601
|
+
return {
|
|
602
|
+
"reason_code": FfiConverterUInt8.read(reader),
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
})();
|
|
606
|
+
const FfiConverterTlsOptions = new (class extends AbstractFfiConverterByteArray {
|
|
607
|
+
allocationSize(value) {
|
|
608
|
+
const recordValue = uniffiRequireRecordObject("TlsOptions", value);
|
|
609
|
+
return uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["ca_cert_pem"]) + uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["client_cert_pem"]) + uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["client_key_pem"]) + FfiConverterBool.allocationSize(recordValue["insecure_skip_certificate_verification"]);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
write(value, writer) {
|
|
613
|
+
const recordValue = uniffiRequireRecordObject("TlsOptions", value);
|
|
614
|
+
uniffiOptionalConverter(FfiConverterBytes).write(recordValue["ca_cert_pem"], writer);
|
|
615
|
+
uniffiOptionalConverter(FfiConverterBytes).write(recordValue["client_cert_pem"], writer);
|
|
616
|
+
uniffiOptionalConverter(FfiConverterBytes).write(recordValue["client_key_pem"], writer);
|
|
617
|
+
FfiConverterBool.write(recordValue["insecure_skip_certificate_verification"], writer);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
read(reader) {
|
|
621
|
+
return {
|
|
622
|
+
"ca_cert_pem": uniffiOptionalConverter(FfiConverterBytes).read(reader),
|
|
623
|
+
"client_cert_pem": uniffiOptionalConverter(FfiConverterBytes).read(reader),
|
|
624
|
+
"client_key_pem": uniffiOptionalConverter(FfiConverterBytes).read(reader),
|
|
625
|
+
"insecure_skip_certificate_verification": FfiConverterBool.read(reader),
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
})();
|
|
629
|
+
const FfiConverterWillOptions = new (class extends AbstractFfiConverterByteArray {
|
|
630
|
+
allocationSize(value) {
|
|
631
|
+
const recordValue = uniffiRequireRecordObject("WillOptions", value);
|
|
632
|
+
return FfiConverterString.allocationSize(recordValue["topic"]) + FfiConverterBytes.allocationSize(recordValue["payload"]) + FfiConverterQoS.allocationSize(recordValue["qos"]) + FfiConverterBool.allocationSize(recordValue["retain"]);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
write(value, writer) {
|
|
636
|
+
const recordValue = uniffiRequireRecordObject("WillOptions", value);
|
|
637
|
+
FfiConverterString.write(recordValue["topic"], writer);
|
|
638
|
+
FfiConverterBytes.write(recordValue["payload"], writer);
|
|
639
|
+
FfiConverterQoS.write(recordValue["qos"], writer);
|
|
640
|
+
FfiConverterBool.write(recordValue["retain"], writer);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
read(reader) {
|
|
644
|
+
return {
|
|
645
|
+
"topic": FfiConverterString.read(reader),
|
|
646
|
+
"payload": FfiConverterBytes.read(reader),
|
|
647
|
+
"qos": FfiConverterQoS.read(reader),
|
|
648
|
+
"retain": FfiConverterBool.read(reader),
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
})();
|
|
652
|
+
const FfiConverterMqttVersion = new (class extends AbstractFfiConverterByteArray {
|
|
653
|
+
allocationSize(value) {
|
|
654
|
+
uniffiRequireFlatEnumValue(MqttVersion, "MqttVersion", value);
|
|
655
|
+
return 4;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
write(value, writer) {
|
|
659
|
+
const enumValue = uniffiRequireFlatEnumValue(MqttVersion, "MqttVersion", value);
|
|
660
|
+
switch (enumValue) {
|
|
661
|
+
case MqttVersion["V311"]:
|
|
662
|
+
writer.writeInt32(1);
|
|
663
|
+
return;
|
|
664
|
+
case MqttVersion["V5"]:
|
|
665
|
+
writer.writeInt32(2);
|
|
666
|
+
return;
|
|
667
|
+
default:
|
|
668
|
+
throw new UnexpectedEnumCase(`Unexpected MqttVersion case ${String(enumValue)}.`);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
read(reader) {
|
|
673
|
+
const enumTag = reader.readInt32();
|
|
674
|
+
switch (enumTag) {
|
|
675
|
+
case 1:
|
|
676
|
+
return MqttVersion["V311"];
|
|
677
|
+
case 2:
|
|
678
|
+
return MqttVersion["V5"];
|
|
679
|
+
default:
|
|
680
|
+
throw new UnexpectedEnumCase(`Unexpected MqttVersion case ${String(enumTag)}.`);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
})();
|
|
684
|
+
const FfiConverterQoS = new (class extends AbstractFfiConverterByteArray {
|
|
685
|
+
allocationSize(value) {
|
|
686
|
+
uniffiRequireFlatEnumValue(QoS, "QoS", value);
|
|
687
|
+
return 4;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
write(value, writer) {
|
|
691
|
+
const enumValue = uniffiRequireFlatEnumValue(QoS, "QoS", value);
|
|
692
|
+
switch (enumValue) {
|
|
693
|
+
case QoS["AtMostOnce"]:
|
|
694
|
+
writer.writeInt32(1);
|
|
695
|
+
return;
|
|
696
|
+
case QoS["AtLeastOnce"]:
|
|
697
|
+
writer.writeInt32(2);
|
|
698
|
+
return;
|
|
699
|
+
case QoS["ExactlyOnce"]:
|
|
700
|
+
writer.writeInt32(3);
|
|
701
|
+
return;
|
|
702
|
+
default:
|
|
703
|
+
throw new UnexpectedEnumCase(`Unexpected QoS case ${String(enumValue)}.`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
read(reader) {
|
|
708
|
+
const enumTag = reader.readInt32();
|
|
709
|
+
switch (enumTag) {
|
|
710
|
+
case 1:
|
|
711
|
+
return QoS["AtMostOnce"];
|
|
712
|
+
case 2:
|
|
713
|
+
return QoS["AtLeastOnce"];
|
|
714
|
+
case 3:
|
|
715
|
+
return QoS["ExactlyOnce"];
|
|
716
|
+
default:
|
|
717
|
+
throw new UnexpectedEnumCase(`Unexpected QoS case ${String(enumTag)}.`);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
})();
|
|
721
|
+
const FfiConverterMqttError = new (class extends AbstractFfiConverterByteArray {
|
|
722
|
+
allocationSize(value) {
|
|
723
|
+
if (value instanceof MqttErrorMalformedPacket) {
|
|
724
|
+
return 4;
|
|
725
|
+
}
|
|
726
|
+
if (value instanceof MqttErrorProtocol) {
|
|
727
|
+
return 4;
|
|
728
|
+
}
|
|
729
|
+
if (value instanceof MqttErrorIo) {
|
|
730
|
+
return 4;
|
|
731
|
+
}
|
|
732
|
+
if (value instanceof MqttErrorConnectionRefused) {
|
|
733
|
+
return 4;
|
|
734
|
+
}
|
|
735
|
+
if (value instanceof MqttErrorNotConnected) {
|
|
736
|
+
return 4;
|
|
737
|
+
}
|
|
738
|
+
if (value instanceof MqttErrorPacketTooLarge) {
|
|
739
|
+
return 4;
|
|
740
|
+
}
|
|
741
|
+
if (value instanceof MqttErrorAlreadyConnected) {
|
|
742
|
+
return 4;
|
|
743
|
+
}
|
|
744
|
+
if (value instanceof MqttErrorTimeout) {
|
|
745
|
+
return 4;
|
|
746
|
+
}
|
|
747
|
+
if (value instanceof MqttErrorSession) {
|
|
748
|
+
return 4;
|
|
749
|
+
}
|
|
750
|
+
throw new TypeError("MqttError values must be instances of MqttErrorMalformedPacket, MqttErrorProtocol, MqttErrorIo, MqttErrorConnectionRefused, MqttErrorNotConnected, MqttErrorPacketTooLarge, MqttErrorAlreadyConnected, MqttErrorTimeout, MqttErrorSession.");
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
write(value, writer) {
|
|
754
|
+
if (value instanceof MqttErrorMalformedPacket) {
|
|
755
|
+
writer.writeInt32(1);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (value instanceof MqttErrorProtocol) {
|
|
759
|
+
writer.writeInt32(2);
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
if (value instanceof MqttErrorIo) {
|
|
763
|
+
writer.writeInt32(3);
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (value instanceof MqttErrorConnectionRefused) {
|
|
767
|
+
writer.writeInt32(4);
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (value instanceof MqttErrorNotConnected) {
|
|
771
|
+
writer.writeInt32(5);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
if (value instanceof MqttErrorPacketTooLarge) {
|
|
775
|
+
writer.writeInt32(6);
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
if (value instanceof MqttErrorAlreadyConnected) {
|
|
779
|
+
writer.writeInt32(7);
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
if (value instanceof MqttErrorTimeout) {
|
|
783
|
+
writer.writeInt32(8);
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
if (value instanceof MqttErrorSession) {
|
|
787
|
+
writer.writeInt32(9);
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
throw new TypeError("MqttError values must be instances of MqttErrorMalformedPacket, MqttErrorProtocol, MqttErrorIo, MqttErrorConnectionRefused, MqttErrorNotConnected, MqttErrorPacketTooLarge, MqttErrorAlreadyConnected, MqttErrorTimeout, MqttErrorSession.");
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
read(reader) {
|
|
794
|
+
const enumTag = reader.readInt32();
|
|
795
|
+
switch (enumTag) {
|
|
796
|
+
case 1:
|
|
797
|
+
return new MqttErrorMalformedPacket(FfiConverterString.read(reader));
|
|
798
|
+
case 2:
|
|
799
|
+
return new MqttErrorProtocol(FfiConverterString.read(reader));
|
|
800
|
+
case 3:
|
|
801
|
+
return new MqttErrorIo(FfiConverterString.read(reader));
|
|
802
|
+
case 4:
|
|
803
|
+
return new MqttErrorConnectionRefused(FfiConverterString.read(reader));
|
|
804
|
+
case 5:
|
|
805
|
+
return new MqttErrorNotConnected(FfiConverterString.read(reader));
|
|
806
|
+
case 6:
|
|
807
|
+
return new MqttErrorPacketTooLarge(FfiConverterString.read(reader));
|
|
808
|
+
case 7:
|
|
809
|
+
return new MqttErrorAlreadyConnected(FfiConverterString.read(reader));
|
|
810
|
+
case 8:
|
|
811
|
+
return new MqttErrorTimeout(FfiConverterString.read(reader));
|
|
812
|
+
case 9:
|
|
813
|
+
return new MqttErrorSession(FfiConverterString.read(reader));
|
|
814
|
+
default:
|
|
815
|
+
throw new UnexpectedEnumCase(`Unexpected MqttError case ${String(enumTag)}.`);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
})();
|
|
819
|
+
class UniffiMqttAuthHandlerProxy extends UniffiObjectBase {
|
|
820
|
+
|
|
821
|
+
respond(method, challenge) {
|
|
822
|
+
const loweredSelf = uniffiMqttAuthHandlerFactory.cloneHandle(this);
|
|
823
|
+
const ffiMethod =
|
|
824
|
+
uniffiMqttAuthHandlerFactory.usesGenericAbi(this)
|
|
825
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttauthhandler_respond_generic_abi
|
|
826
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttauthhandler_respond;
|
|
827
|
+
const loweredMethod = uniffiLowerString(method);
|
|
828
|
+
const loweredChallenge = uniffiLowerIntoRustBuffer(FfiConverterBytes, challenge);
|
|
829
|
+
const uniffiResult = uniffiRustCaller.rustCall(
|
|
830
|
+
(status) => ffiMethod(loweredSelf, loweredMethod, loweredChallenge, status),
|
|
831
|
+
uniffiRustCallOptions(),
|
|
832
|
+
);
|
|
833
|
+
return uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterBytes), uniffiResult);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
const uniffiMqttAuthHandlerFactory = createObjectFactory({
|
|
838
|
+
typeName: "MqttAuthHandler",
|
|
839
|
+
createInstance: () => Object.create(UniffiMqttAuthHandlerProxy.prototype),
|
|
840
|
+
cloneHandle(handle) {
|
|
841
|
+
return uniffiRustCaller.rustCall(
|
|
842
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_clone_mqttauthhandler(handle, status),
|
|
843
|
+
uniffiRustCallOptions(),
|
|
844
|
+
);
|
|
845
|
+
},
|
|
846
|
+
freeHandle(handle) {
|
|
847
|
+
uniffiRustCaller.rustCall(
|
|
848
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_free_mqttauthhandler(handle, status),
|
|
849
|
+
uniffiRustCallOptions(),
|
|
850
|
+
);
|
|
851
|
+
},
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
function uniffiValidateMqttAuthHandlerImplementation(implementation) {
|
|
855
|
+
if ((typeof implementation !== "object" && typeof implementation !== "function") || implementation == null) {
|
|
856
|
+
throw new TypeError(`${"MqttAuthHandler"} implementations must be objects with callable methods.`);
|
|
857
|
+
}
|
|
858
|
+
if (typeof implementation.respond !== "function") {
|
|
859
|
+
throw new TypeError(`${"MqttAuthHandler"} is missing required method respond().`);
|
|
860
|
+
}
|
|
861
|
+
return implementation;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
const uniffiMqttAuthHandlerRegistry = createCallbackRegistry({
|
|
865
|
+
interfaceName: "MqttAuthHandler",
|
|
866
|
+
validate: uniffiValidateMqttAuthHandlerImplementation,
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
function uniffiRegisterMqttAuthHandlerVtable(bindings, registrations, vtableReferences) {
|
|
870
|
+
const respondCallback = koffi.register(
|
|
871
|
+
(uniffiHandle, method, challenge, uniffiOutReturn, callStatus) => {
|
|
872
|
+
const uniffiStatus = callStatus == null
|
|
873
|
+
? createRustCallStatus()
|
|
874
|
+
: koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
|
|
875
|
+
const uniffiResult = invokeCallbackMethod({
|
|
876
|
+
registry: uniffiMqttAuthHandlerRegistry,
|
|
877
|
+
handle: uniffiHandle,
|
|
878
|
+
methodName: "respond",
|
|
879
|
+
args: [
|
|
880
|
+
uniffiLiftStringFromRustBuffer(method),
|
|
881
|
+
uniffiLiftFromRustBuffer(FfiConverterBytes, challenge),
|
|
882
|
+
],
|
|
883
|
+
lowerString: (value) => uniffiLowerString(value),
|
|
884
|
+
status: uniffiStatus,
|
|
885
|
+
});
|
|
886
|
+
if (callStatus != null) {
|
|
887
|
+
koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
|
|
888
|
+
}
|
|
889
|
+
if (uniffiStatus.code !== CALL_SUCCESS) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
const loweredReturn = uniffiLowerIntoRustBuffer(uniffiOptionalConverter(FfiConverterBytes), uniffiResult);
|
|
893
|
+
koffi.encode(uniffiOutReturn, bindings.ffiTypes.RustBuffer, loweredReturn);
|
|
894
|
+
},
|
|
895
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttAuthHandlerMethod0),
|
|
896
|
+
);
|
|
897
|
+
registrations.push(respondCallback);
|
|
898
|
+
const uniffiFree = koffi.register(
|
|
899
|
+
(uniffiHandle) => uniffiMqttAuthHandlerRegistry.remove(uniffiHandle),
|
|
900
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceFree),
|
|
901
|
+
);
|
|
902
|
+
registrations.push(uniffiFree);
|
|
903
|
+
const uniffiClone = koffi.register(
|
|
904
|
+
(uniffiHandle) => uniffiMqttAuthHandlerRegistry.cloneHandle(uniffiHandle),
|
|
905
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceClone),
|
|
906
|
+
);
|
|
907
|
+
registrations.push(uniffiClone);
|
|
908
|
+
const uniffiVtable = koffi.alloc(bindings.ffiStructs.VTableCallbackInterfaceMqttAuthHandler, 1);
|
|
909
|
+
koffi.encode(uniffiVtable, bindings.ffiStructs.VTableCallbackInterfaceMqttAuthHandler, {
|
|
910
|
+
uniffi_free: uniffiFree,
|
|
911
|
+
uniffi_clone: uniffiClone,
|
|
912
|
+
"respond": respondCallback,
|
|
913
|
+
|
|
914
|
+
});
|
|
915
|
+
vtableReferences.push(uniffiVtable);
|
|
916
|
+
bindings.ffiFunctions.uniffi_mqtt_client_fn_init_callback_vtable_mqttauthhandler(uniffiVtable);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
const FfiConverterMqttAuthHandler = Object.freeze({
|
|
920
|
+
lower(value) {
|
|
921
|
+
if (uniffiMqttAuthHandlerFactory.isInstance(value)) {
|
|
922
|
+
return uniffiMqttAuthHandlerFactory.cloneHandle(value);
|
|
923
|
+
}
|
|
924
|
+
return uniffiMqttAuthHandlerRegistry.register(value);
|
|
925
|
+
},
|
|
926
|
+
lift(handle) {
|
|
927
|
+
return uniffiMqttAuthHandlerFactory.create(handle);
|
|
928
|
+
},
|
|
929
|
+
write(value, writer) {
|
|
930
|
+
writer.writeUInt64(this.lower(value));
|
|
931
|
+
},
|
|
932
|
+
read(reader) {
|
|
933
|
+
return this.lift(reader.readUInt64());
|
|
934
|
+
},
|
|
935
|
+
allocationSize() {
|
|
936
|
+
return UNIFFI_OBJECT_HANDLE_SIZE;
|
|
937
|
+
},
|
|
938
|
+
});
|
|
939
|
+
class UniffiMqttMessageListenerProxy extends UniffiObjectBase {
|
|
940
|
+
|
|
941
|
+
on_message(message) {
|
|
942
|
+
const loweredSelf = uniffiMqttMessageListenerFactory.cloneHandle(this);
|
|
943
|
+
const ffiMethod =
|
|
944
|
+
uniffiMqttMessageListenerFactory.usesGenericAbi(this)
|
|
945
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttmessagelistener_on_message_generic_abi
|
|
946
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttmessagelistener_on_message;
|
|
947
|
+
const loweredMessage = uniffiLowerIntoRustBuffer(FfiConverterMqttMessage, message);
|
|
948
|
+
uniffiRustCaller.rustCall(
|
|
949
|
+
(status) => ffiMethod(loweredSelf, loweredMessage, status),
|
|
950
|
+
uniffiRustCallOptions(),
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
on_disconnected(reason) {
|
|
955
|
+
const loweredSelf = uniffiMqttMessageListenerFactory.cloneHandle(this);
|
|
956
|
+
const ffiMethod =
|
|
957
|
+
uniffiMqttMessageListenerFactory.usesGenericAbi(this)
|
|
958
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttmessagelistener_on_disconnected_generic_abi
|
|
959
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttmessagelistener_on_disconnected;
|
|
960
|
+
const loweredReason = uniffiLowerString(reason);
|
|
961
|
+
uniffiRustCaller.rustCall(
|
|
962
|
+
(status) => ffiMethod(loweredSelf, loweredReason, status),
|
|
963
|
+
uniffiRustCallOptions(),
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
const uniffiMqttMessageListenerFactory = createObjectFactory({
|
|
969
|
+
typeName: "MqttMessageListener",
|
|
970
|
+
createInstance: () => Object.create(UniffiMqttMessageListenerProxy.prototype),
|
|
971
|
+
cloneHandle(handle) {
|
|
972
|
+
return uniffiRustCaller.rustCall(
|
|
973
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_clone_mqttmessagelistener(handle, status),
|
|
974
|
+
uniffiRustCallOptions(),
|
|
975
|
+
);
|
|
976
|
+
},
|
|
977
|
+
freeHandle(handle) {
|
|
978
|
+
uniffiRustCaller.rustCall(
|
|
979
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_free_mqttmessagelistener(handle, status),
|
|
980
|
+
uniffiRustCallOptions(),
|
|
981
|
+
);
|
|
982
|
+
},
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
function uniffiValidateMqttMessageListenerImplementation(implementation) {
|
|
986
|
+
if ((typeof implementation !== "object" && typeof implementation !== "function") || implementation == null) {
|
|
987
|
+
throw new TypeError(`${"MqttMessageListener"} implementations must be objects with callable methods.`);
|
|
988
|
+
}
|
|
989
|
+
if (typeof implementation.on_message !== "function") {
|
|
990
|
+
throw new TypeError(`${"MqttMessageListener"} is missing required method on_message().`);
|
|
991
|
+
}
|
|
992
|
+
if (typeof implementation.on_disconnected !== "function") {
|
|
993
|
+
throw new TypeError(`${"MqttMessageListener"} is missing required method on_disconnected().`);
|
|
994
|
+
}
|
|
995
|
+
return implementation;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
const uniffiMqttMessageListenerRegistry = createCallbackRegistry({
|
|
999
|
+
interfaceName: "MqttMessageListener",
|
|
1000
|
+
validate: uniffiValidateMqttMessageListenerImplementation,
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
function uniffiRegisterMqttMessageListenerVtable(bindings, registrations, vtableReferences) {
|
|
1004
|
+
const on_messageCallback = koffi.register(
|
|
1005
|
+
(uniffiHandle, message, uniffiOutReturn, callStatus) => {
|
|
1006
|
+
const uniffiStatus = callStatus == null
|
|
1007
|
+
? createRustCallStatus()
|
|
1008
|
+
: koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
|
|
1009
|
+
const uniffiResult = invokeCallbackMethod({
|
|
1010
|
+
registry: uniffiMqttMessageListenerRegistry,
|
|
1011
|
+
handle: uniffiHandle,
|
|
1012
|
+
methodName: "on_message",
|
|
1013
|
+
args: [
|
|
1014
|
+
uniffiLiftFromRustBuffer(FfiConverterMqttMessage, message),
|
|
1015
|
+
],
|
|
1016
|
+
lowerString: (value) => uniffiLowerString(value),
|
|
1017
|
+
status: uniffiStatus,
|
|
1018
|
+
});
|
|
1019
|
+
if (callStatus != null) {
|
|
1020
|
+
koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
|
|
1021
|
+
}
|
|
1022
|
+
if (uniffiStatus.code !== CALL_SUCCESS) {
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttMessageListenerMethod0),
|
|
1027
|
+
);
|
|
1028
|
+
registrations.push(on_messageCallback);
|
|
1029
|
+
const on_disconnectedCallback = koffi.register(
|
|
1030
|
+
(uniffiHandle, reason, uniffiOutReturn, callStatus) => {
|
|
1031
|
+
const uniffiStatus = callStatus == null
|
|
1032
|
+
? createRustCallStatus()
|
|
1033
|
+
: koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
|
|
1034
|
+
const uniffiResult = invokeCallbackMethod({
|
|
1035
|
+
registry: uniffiMqttMessageListenerRegistry,
|
|
1036
|
+
handle: uniffiHandle,
|
|
1037
|
+
methodName: "on_disconnected",
|
|
1038
|
+
args: [
|
|
1039
|
+
uniffiLiftStringFromRustBuffer(reason),
|
|
1040
|
+
],
|
|
1041
|
+
lowerString: (value) => uniffiLowerString(value),
|
|
1042
|
+
status: uniffiStatus,
|
|
1043
|
+
});
|
|
1044
|
+
if (callStatus != null) {
|
|
1045
|
+
koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
|
|
1046
|
+
}
|
|
1047
|
+
if (uniffiStatus.code !== CALL_SUCCESS) {
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
},
|
|
1051
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttMessageListenerMethod1),
|
|
1052
|
+
);
|
|
1053
|
+
registrations.push(on_disconnectedCallback);
|
|
1054
|
+
const uniffiFree = koffi.register(
|
|
1055
|
+
(uniffiHandle) => uniffiMqttMessageListenerRegistry.remove(uniffiHandle),
|
|
1056
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceFree),
|
|
1057
|
+
);
|
|
1058
|
+
registrations.push(uniffiFree);
|
|
1059
|
+
const uniffiClone = koffi.register(
|
|
1060
|
+
(uniffiHandle) => uniffiMqttMessageListenerRegistry.cloneHandle(uniffiHandle),
|
|
1061
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceClone),
|
|
1062
|
+
);
|
|
1063
|
+
registrations.push(uniffiClone);
|
|
1064
|
+
const uniffiVtable = koffi.alloc(bindings.ffiStructs.VTableCallbackInterfaceMqttMessageListener, 1);
|
|
1065
|
+
koffi.encode(uniffiVtable, bindings.ffiStructs.VTableCallbackInterfaceMqttMessageListener, {
|
|
1066
|
+
uniffi_free: uniffiFree,
|
|
1067
|
+
uniffi_clone: uniffiClone,
|
|
1068
|
+
"on_message": on_messageCallback,
|
|
1069
|
+
"on_disconnected": on_disconnectedCallback,
|
|
1070
|
+
|
|
1071
|
+
});
|
|
1072
|
+
vtableReferences.push(uniffiVtable);
|
|
1073
|
+
bindings.ffiFunctions.uniffi_mqtt_client_fn_init_callback_vtable_mqttmessagelistener(uniffiVtable);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
const FfiConverterMqttMessageListener = Object.freeze({
|
|
1077
|
+
lower(value) {
|
|
1078
|
+
if (uniffiMqttMessageListenerFactory.isInstance(value)) {
|
|
1079
|
+
return uniffiMqttMessageListenerFactory.cloneHandle(value);
|
|
1080
|
+
}
|
|
1081
|
+
return uniffiMqttMessageListenerRegistry.register(value);
|
|
1082
|
+
},
|
|
1083
|
+
lift(handle) {
|
|
1084
|
+
return uniffiMqttMessageListenerFactory.create(handle);
|
|
1085
|
+
},
|
|
1086
|
+
write(value, writer) {
|
|
1087
|
+
writer.writeUInt64(this.lower(value));
|
|
1088
|
+
},
|
|
1089
|
+
read(reader) {
|
|
1090
|
+
return this.lift(reader.readUInt64());
|
|
1091
|
+
},
|
|
1092
|
+
allocationSize() {
|
|
1093
|
+
return UNIFFI_OBJECT_HANDLE_SIZE;
|
|
1094
|
+
},
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
const uniffiRegisteredCallbackPointers = [];
|
|
1098
|
+
const uniffiRegisteredCallbackVtables = [];
|
|
1099
|
+
|
|
1100
|
+
function uniffiRegisterCallbackVtables(bindings) {
|
|
1101
|
+
uniffiRegisterMqttAuthHandlerVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
|
|
1102
|
+
uniffiRegisterMqttMessageListenerVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
function uniffiUnregisterCallbackVtables() {
|
|
1106
|
+
clearPendingForeignFutures();
|
|
1107
|
+
uniffiMqttAuthHandlerRegistry.clear();
|
|
1108
|
+
uniffiMqttMessageListenerRegistry.clear();
|
|
1109
|
+
while (uniffiRegisteredCallbackPointers.length > 0) {
|
|
1110
|
+
koffi.unregister(uniffiRegisteredCallbackPointers.pop());
|
|
1111
|
+
}
|
|
1112
|
+
uniffiRegisteredCallbackVtables.length = 0;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
configureRuntimeHooks({
|
|
1116
|
+
onLoad(bindings) {
|
|
1117
|
+
uniffiRegisterCallbackVtables(bindings);
|
|
1118
|
+
},
|
|
1119
|
+
onUnload() {
|
|
1120
|
+
if (uniffiRustFutureContinuationPointer != null) {
|
|
1121
|
+
koffi.unregister(uniffiRustFutureContinuationPointer);
|
|
1122
|
+
uniffiRustFutureContinuationPointer = null;
|
|
1123
|
+
}
|
|
1124
|
+
uniffiUnregisterCallbackVtables();
|
|
1125
|
+
},
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* A connected (or not-yet-connected) MQTT client instance.
|
|
1130
|
+
*
|
|
1131
|
+
* One `MqttClient` corresponds to one broker connection / MQTT session.
|
|
1132
|
+
* Create it with [`MqttClient::new`], call [`MqttClient::connect`], then
|
|
1133
|
+
* use [`MqttClient::publish`] / [`MqttClient::subscribe`] /
|
|
1134
|
+
* [`MqttClient::unsubscribe`]. Call [`MqttClient::disconnect`] (or simply
|
|
1135
|
+
* drop it) to close the connection.
|
|
1136
|
+
*/
|
|
1137
|
+
export class MqttClient extends UniffiObjectBase {
|
|
1138
|
+
/**
|
|
1139
|
+
* Create a new client from `options`. Does not connect yet.
|
|
1140
|
+
*/
|
|
1141
|
+
constructor(options) {
|
|
1142
|
+
super();
|
|
1143
|
+
const loweredOptions = uniffiLowerIntoRustBuffer(FfiConverterConnectOptions, options);
|
|
1144
|
+
const pointer = uniffiRustCaller.rustCall(
|
|
1145
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_constructor_mqttclient_new(loweredOptions, status),
|
|
1146
|
+
uniffiRustCallOptions(),
|
|
1147
|
+
);
|
|
1148
|
+
return uniffiMqttClientObjectFactory.attach(this, pointer);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* Open the TCP connection and complete the CONNECT/CONNACK handshake.
|
|
1153
|
+
* Safe to call again after a connection loss (including one this
|
|
1154
|
+
* client is still in the middle of auto-reconnecting from).
|
|
1155
|
+
*
|
|
1156
|
+
* If [`ConnectOptions::auto_reconnect`] is set, a background
|
|
1157
|
+
* supervisor is started (once) that automatically re-runs this same
|
|
1158
|
+
* handshake — with exponential backoff — after any *unexpected*
|
|
1159
|
+
* connection loss (i.e. not caused by [`Self::disconnect`]), then
|
|
1160
|
+
* replays every topic this client is currently subscribed to.
|
|
1161
|
+
*/
|
|
1162
|
+
async connect() {
|
|
1163
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1164
|
+
const ffiMethod =
|
|
1165
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1166
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_connect_generic_abi
|
|
1167
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_connect;
|
|
1168
|
+
const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_client_rust_future_complete_rust_buffer(rustFuture, status);
|
|
1169
|
+
return rustCallAsync({
|
|
1170
|
+
rustFutureFunc: () => ffiMethod(loweredSelf),
|
|
1171
|
+
pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_client_rust_future_poll_rust_buffer(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
|
|
1172
|
+
cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_cancel_rust_buffer(rustFuture),
|
|
1173
|
+
completeFunc,
|
|
1174
|
+
freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_free_rust_buffer(rustFuture),
|
|
1175
|
+
liftFunc: (uniffiResult) => uniffiLiftFromRustBuffer(FfiConverterConnectResult, uniffiResult),
|
|
1176
|
+
...uniffiRustCallOptions(FfiConverterMqttError),
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
/**
|
|
1181
|
+
* Gracefully disconnect: sends a DISCONNECT packet, stops background
|
|
1182
|
+
* tasks, and closes the socket. Safe to call multiple times. Also
|
|
1183
|
+
* stops the [`ConnectOptions::auto_reconnect`] supervisor, if one is
|
|
1184
|
+
* running — this is a deliberate disconnect, not a connection loss to
|
|
1185
|
+
* recover from.
|
|
1186
|
+
*/
|
|
1187
|
+
async disconnect() {
|
|
1188
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1189
|
+
const ffiMethod =
|
|
1190
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1191
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_disconnect_generic_abi
|
|
1192
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_disconnect;
|
|
1193
|
+
const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_client_rust_future_complete_void(rustFuture, status);
|
|
1194
|
+
return rustCallAsync({
|
|
1195
|
+
rustFutureFunc: () => ffiMethod(loweredSelf),
|
|
1196
|
+
pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_client_rust_future_poll_void(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
|
|
1197
|
+
cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_cancel_void(rustFuture),
|
|
1198
|
+
completeFunc,
|
|
1199
|
+
freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_free_void(rustFuture),
|
|
1200
|
+
liftFunc: (_uniffiResult) => undefined,
|
|
1201
|
+
...uniffiRustCallOptions(FfiConverterMqttError),
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* Pull-style alternative to [`set_message_listener`](Self::set_message_listener)
|
|
1207
|
+
* for runtimes that can't receive callbacks from Rust threads (Dart,
|
|
1208
|
+
* Haskell): keep up to `capacity` incoming messages for
|
|
1209
|
+
* [`next_message`](Self::next_message). `0` turns the queue off. When it
|
|
1210
|
+
* fills up the oldest message is dropped. May be combined with a listener.
|
|
1211
|
+
*/
|
|
1212
|
+
enable_message_queue(capacity) {
|
|
1213
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1214
|
+
const ffiMethod =
|
|
1215
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1216
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_enable_message_queue_generic_abi
|
|
1217
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_enable_message_queue;
|
|
1218
|
+
const loweredCapacity = FfiConverterUInt32.lower(capacity);
|
|
1219
|
+
uniffiRustCaller.rustCall(
|
|
1220
|
+
(status) => ffiMethod(loweredSelf, loweredCapacity, status),
|
|
1221
|
+
uniffiRustCallOptions(),
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* `true` once [`connect`](Self::connect) has succeeded and the
|
|
1227
|
+
* connection has not since been lost or closed.
|
|
1228
|
+
*/
|
|
1229
|
+
is_connected() {
|
|
1230
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1231
|
+
const ffiMethod =
|
|
1232
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1233
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_is_connected_generic_abi
|
|
1234
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_is_connected;
|
|
1235
|
+
const uniffiResult = uniffiRustCaller.rustCall(
|
|
1236
|
+
(status) => ffiMethod(loweredSelf, status),
|
|
1237
|
+
uniffiRustCallOptions(),
|
|
1238
|
+
);
|
|
1239
|
+
return FfiConverterBool.lift(uniffiResult);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* Why the most recent connection was lost (`None` if it never was) —
|
|
1244
|
+
* the pull-style twin of `MqttMessageListener::on_disconnected`.
|
|
1245
|
+
*/
|
|
1246
|
+
last_disconnect_reason() {
|
|
1247
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1248
|
+
const ffiMethod =
|
|
1249
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1250
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_last_disconnect_reason_generic_abi
|
|
1251
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_last_disconnect_reason;
|
|
1252
|
+
const uniffiResult = uniffiRustCaller.rustCall(
|
|
1253
|
+
(status) => ffiMethod(loweredSelf, status),
|
|
1254
|
+
uniffiRustCallOptions(),
|
|
1255
|
+
);
|
|
1256
|
+
return uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterString), uniffiResult);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
/**
|
|
1260
|
+
* The next queued incoming message, waiting up to `timeout_ms`
|
|
1261
|
+
* milliseconds for one; `None` if none arrived. Requires
|
|
1262
|
+
* [`enable_message_queue`](Self::enable_message_queue).
|
|
1263
|
+
*/
|
|
1264
|
+
async next_message(timeout_ms) {
|
|
1265
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1266
|
+
const ffiMethod =
|
|
1267
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1268
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_next_message_generic_abi
|
|
1269
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_next_message;
|
|
1270
|
+
const loweredTimeoutMs = FfiConverterUInt32.lower(timeout_ms);
|
|
1271
|
+
const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_client_rust_future_complete_rust_buffer(rustFuture, status);
|
|
1272
|
+
return rustCallAsync({
|
|
1273
|
+
rustFutureFunc: () => ffiMethod(loweredSelf, loweredTimeoutMs),
|
|
1274
|
+
pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_client_rust_future_poll_rust_buffer(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
|
|
1275
|
+
cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_cancel_rust_buffer(rustFuture),
|
|
1276
|
+
completeFunc,
|
|
1277
|
+
freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_free_rust_buffer(rustFuture),
|
|
1278
|
+
liftFunc: (uniffiResult) => uniffiLiftFromRustBuffer(uniffiOptionalConverter(FfiConverterMqttMessage), uniffiResult),
|
|
1279
|
+
...uniffiRustCallOptions(),
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* Publish `payload` to `topic`. Resolves once the broker has
|
|
1285
|
+
* acknowledged the message (QoS 1: PUBACK; QoS 2: full four-part
|
|
1286
|
+
* handshake). Resolves immediately for QoS 0.
|
|
1287
|
+
*
|
|
1288
|
+
* For QoS 1/2, an unacked step is retried (with DUP=1) up to
|
|
1289
|
+
* `MAX_PUBLISH_RETRIES` (3) times before giving up with
|
|
1290
|
+
* [`MqttError::Timeout`] — the broker never resends on our behalf, so
|
|
1291
|
+
* enforcing "at least once"/"exactly once" delivery is the
|
|
1292
|
+
* publisher's job.
|
|
1293
|
+
*
|
|
1294
|
+
* A topic containing wildcards (`+`, `#`) or that is empty is
|
|
1295
|
+
* rejected locally with [`MqttError::Protocol`] (a broker would drop
|
|
1296
|
+
* the whole connection for it). An MQTT 5.0 broker that answers with a
|
|
1297
|
+
* failure reason code (e.g. "not authorized") surfaces as
|
|
1298
|
+
* [`MqttError::Session`] instead of being reported as success.
|
|
1299
|
+
*/
|
|
1300
|
+
async publish(topic, payload, qos, retain) {
|
|
1301
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1302
|
+
const ffiMethod =
|
|
1303
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1304
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_publish_generic_abi
|
|
1305
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_publish;
|
|
1306
|
+
const loweredTopic = uniffiLowerString(topic);
|
|
1307
|
+
const loweredPayload = uniffiLowerIntoRustBuffer(FfiConverterBytes, payload);
|
|
1308
|
+
const loweredQos = uniffiLowerIntoRustBuffer(FfiConverterQoS, qos);
|
|
1309
|
+
const loweredRetain = FfiConverterBool.lower(retain);
|
|
1310
|
+
const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_client_rust_future_complete_void(rustFuture, status);
|
|
1311
|
+
return rustCallAsync({
|
|
1312
|
+
rustFutureFunc: () => ffiMethod(loweredSelf, loweredTopic, loweredPayload, loweredQos, loweredRetain),
|
|
1313
|
+
pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_client_rust_future_poll_void(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
|
|
1314
|
+
cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_cancel_void(rustFuture),
|
|
1315
|
+
completeFunc,
|
|
1316
|
+
freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_free_void(rustFuture),
|
|
1317
|
+
liftFunc: (_uniffiResult) => undefined,
|
|
1318
|
+
...uniffiRustCallOptions(FfiConverterMqttError),
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Register the handler that answers the broker's authentication
|
|
1324
|
+
* challenges when [`ConnectOptions::auth_method`] is set (MQTT 5.0
|
|
1325
|
+
* enhanced authentication). Must be set before `connect()`.
|
|
1326
|
+
*/
|
|
1327
|
+
set_auth_handler(handler) {
|
|
1328
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1329
|
+
const ffiMethod =
|
|
1330
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1331
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_set_auth_handler_generic_abi
|
|
1332
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_set_auth_handler;
|
|
1333
|
+
const loweredHandler = FfiConverterMqttAuthHandler.lower(handler);
|
|
1334
|
+
uniffiRustCaller.rustCall(
|
|
1335
|
+
(status) => ffiMethod(loweredSelf, loweredHandler, status),
|
|
1336
|
+
uniffiRustCallOptions(),
|
|
1337
|
+
);
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
/**
|
|
1341
|
+
* Register (or replace) the listener that receives incoming messages
|
|
1342
|
+
* and disconnect notifications. Safe to call before or after connect.
|
|
1343
|
+
*/
|
|
1344
|
+
set_message_listener(listener) {
|
|
1345
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1346
|
+
const ffiMethod =
|
|
1347
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1348
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_set_message_listener_generic_abi
|
|
1349
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_set_message_listener;
|
|
1350
|
+
const loweredListener = FfiConverterMqttMessageListener.lower(listener);
|
|
1351
|
+
uniffiRustCaller.rustCall(
|
|
1352
|
+
(status) => ffiMethod(loweredSelf, loweredListener, status),
|
|
1353
|
+
uniffiRustCallOptions(),
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/**
|
|
1358
|
+
* Subscribe to `topic_filter` requesting at most `qos`. Returns the
|
|
1359
|
+
* reason/return code the broker granted.
|
|
1360
|
+
*
|
|
1361
|
+
* Recorded in this client's own subscription bookkeeping so
|
|
1362
|
+
* [`ConnectOptions::auto_reconnect`] can replay it after a reconnect
|
|
1363
|
+
* — the broker has no way to tell a resumed client what it was
|
|
1364
|
+
* subscribed to beyond what a persistent (`clean_start = false`)
|
|
1365
|
+
* session already covers.
|
|
1366
|
+
*/
|
|
1367
|
+
async subscribe(topic_filter, qos) {
|
|
1368
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1369
|
+
const ffiMethod =
|
|
1370
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1371
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_subscribe_generic_abi
|
|
1372
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_subscribe;
|
|
1373
|
+
const loweredTopicFilter = uniffiLowerString(topic_filter);
|
|
1374
|
+
const loweredQos = uniffiLowerIntoRustBuffer(FfiConverterQoS, qos);
|
|
1375
|
+
const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_client_rust_future_complete_rust_buffer(rustFuture, status);
|
|
1376
|
+
return rustCallAsync({
|
|
1377
|
+
rustFutureFunc: () => ffiMethod(loweredSelf, loweredTopicFilter, loweredQos),
|
|
1378
|
+
pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_client_rust_future_poll_rust_buffer(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
|
|
1379
|
+
cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_cancel_rust_buffer(rustFuture),
|
|
1380
|
+
completeFunc,
|
|
1381
|
+
freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_free_rust_buffer(rustFuture),
|
|
1382
|
+
liftFunc: (uniffiResult) => uniffiLiftFromRustBuffer(FfiConverterSubscribeResult, uniffiResult),
|
|
1383
|
+
...uniffiRustCallOptions(FfiConverterMqttError),
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Unsubscribe from `topic_filter`.
|
|
1389
|
+
*/
|
|
1390
|
+
async unsubscribe(topic_filter) {
|
|
1391
|
+
const loweredSelf = uniffiMqttClientObjectFactory.cloneHandle(this);
|
|
1392
|
+
const ffiMethod =
|
|
1393
|
+
uniffiMqttClientObjectFactory.usesGenericAbi(this)
|
|
1394
|
+
? ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_unsubscribe_generic_abi
|
|
1395
|
+
: ffiFunctions.uniffi_mqtt_client_fn_method_mqttclient_unsubscribe;
|
|
1396
|
+
const loweredTopicFilter = uniffiLowerString(topic_filter);
|
|
1397
|
+
const completeFunc = (rustFuture, status) => ffiFunctions.ffi_mqtt_client_rust_future_complete_void(rustFuture, status);
|
|
1398
|
+
return rustCallAsync({
|
|
1399
|
+
rustFutureFunc: () => ffiMethod(loweredSelf, loweredTopicFilter),
|
|
1400
|
+
pollFunc: (rustFuture, _continuationCallback, continuationHandle) => ffiFunctions.ffi_mqtt_client_rust_future_poll_void(rustFuture, uniffiGetRustFutureContinuationPointer(), continuationHandle),
|
|
1401
|
+
cancelFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_cancel_void(rustFuture),
|
|
1402
|
+
completeFunc,
|
|
1403
|
+
freeFunc: (rustFuture) => ffiFunctions.ffi_mqtt_client_rust_future_free_void(rustFuture),
|
|
1404
|
+
liftFunc: (_uniffiResult) => undefined,
|
|
1405
|
+
...uniffiRustCallOptions(FfiConverterMqttError),
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
const uniffiMqttClientObjectFactory = createObjectFactory({
|
|
1411
|
+
typeName: "MqttClient",
|
|
1412
|
+
createInstance: () => Object.create(MqttClient.prototype),
|
|
1413
|
+
cloneFreeUsesUniffiHandle: true,
|
|
1414
|
+
cloneHandleGeneric(handle) {
|
|
1415
|
+
return uniffiRustCaller.rustCall(
|
|
1416
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_clone_mqttclient_generic_abi(handle, status),
|
|
1417
|
+
uniffiRustCallOptions(),
|
|
1418
|
+
);
|
|
1419
|
+
},
|
|
1420
|
+
cloneHandleRawExternal(handle) {
|
|
1421
|
+
const rawExternalCloneHandle = uniffiGetCachedLibraryFunction(
|
|
1422
|
+
"uniffi_mqtt_client_fn_clone_mqttclient:raw-external",
|
|
1423
|
+
(bindings) => bindings.library.func(
|
|
1424
|
+
"uniffi_mqtt_client_fn_clone_mqttclient",
|
|
1425
|
+
bindings.ffiTypes.VoidPointer,
|
|
1426
|
+
[bindings.ffiTypes.VoidPointer, koffi.pointer(bindings.ffiTypes.RustCallStatus)],
|
|
1427
|
+
),
|
|
1428
|
+
);
|
|
1429
|
+
return uniffiRustCaller.rustCall(
|
|
1430
|
+
(status) => rawExternalCloneHandle(handle, status),
|
|
1431
|
+
uniffiRustCallOptions(),
|
|
1432
|
+
);
|
|
1433
|
+
},
|
|
1434
|
+
cloneHandle(handle) {
|
|
1435
|
+
return uniffiRustCaller.rustCall(
|
|
1436
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_clone_mqttclient(handle, status),
|
|
1437
|
+
uniffiRustCallOptions(),
|
|
1438
|
+
);
|
|
1439
|
+
},
|
|
1440
|
+
freeHandleGeneric(handle) {
|
|
1441
|
+
uniffiRustCaller.rustCall(
|
|
1442
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_free_mqttclient_generic_abi(handle, status),
|
|
1443
|
+
uniffiRustCallOptions(),
|
|
1444
|
+
);
|
|
1445
|
+
},
|
|
1446
|
+
freeHandleRawExternal(handle) {
|
|
1447
|
+
const rawExternalFreeHandle = uniffiGetCachedLibraryFunction(
|
|
1448
|
+
"uniffi_mqtt_client_fn_free_mqttclient:raw-external",
|
|
1449
|
+
(bindings) => bindings.library.func(
|
|
1450
|
+
"uniffi_mqtt_client_fn_free_mqttclient",
|
|
1451
|
+
"void",
|
|
1452
|
+
[bindings.ffiTypes.VoidPointer, koffi.pointer(bindings.ffiTypes.RustCallStatus)],
|
|
1453
|
+
),
|
|
1454
|
+
);
|
|
1455
|
+
uniffiRustCaller.rustCall(
|
|
1456
|
+
(status) => rawExternalFreeHandle(handle, status),
|
|
1457
|
+
uniffiRustCallOptions(),
|
|
1458
|
+
);
|
|
1459
|
+
},
|
|
1460
|
+
freeHandle(handle) {
|
|
1461
|
+
uniffiRustCaller.rustCall(
|
|
1462
|
+
(status) => ffiFunctions.uniffi_mqtt_client_fn_free_mqttclient(handle, status),
|
|
1463
|
+
uniffiRustCallOptions(),
|
|
1464
|
+
);
|
|
1465
|
+
},
|
|
1466
|
+
});
|
|
1467
|
+
const FfiConverterMqttClient = createObjectConverter(uniffiMqttClientObjectFactory);
|