stem-mqtt-client 0.6.1-x86_64-linux

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,2659 @@
1
+ # This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+ # Trust me, you don't want to mess with it!
3
+
4
+ # Common helper code.
5
+ #
6
+ # Ideally this would live in a separate .rb file where it can be unittested etc
7
+ # in isolation, and perhaps even published as a re-useable package.
8
+ #
9
+ # However, it's important that the details of how this helper code works (e.g. the
10
+ # way that different builtin types are passed across the FFI) exactly match what's
11
+ # expected by the rust code on the other side of the interface. In practice right
12
+ # now that means coming from the exact some version of `uniffi` that was used to
13
+ # compile the rust component. The easiest way to ensure this is to bundle the Ruby
14
+ # helpers directly inline like we're doing here.
15
+
16
+ require 'ffi'
17
+ require 'set'
18
+ require 'monitor'
19
+
20
+ module MqttClient
21
+ def self.uniffi_in_range(i, type_name, min, max)
22
+ raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
23
+ i = i.to_int
24
+ raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
25
+ i
26
+ end
27
+
28
+ def self.uniffi_utf8(v)
29
+ raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
30
+ v = v.to_str.encode(Encoding::UTF_8)
31
+ raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
32
+ v
33
+ end
34
+
35
+ def self.uniffi_bytes(v)
36
+ raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
37
+ v.to_str
38
+ end
39
+
40
+ # Callback return codes
41
+ UNIFFI_CALLBACK_SUCCESS = 0
42
+ UNIFFI_CALLBACK_ERROR = 1
43
+ UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2
44
+
45
+ # Call a method on a callback interface object, catching and reporting errors
46
+ # to Rust via the call_status.
47
+ # If error_type is provided, known errors of that type are reported as UNIFFI_CALLBACK_ERROR;
48
+ # all other errors are reported as UNIFFI_CALLBACK_UNEXPECTED_ERROR.
49
+ def self.uniffi_trait_interface_call(call_status, make_call, write_return_value, error_type = nil, lower_error = nil)
50
+ begin
51
+ write_return_value.call make_call.call
52
+ rescue StandardError => e
53
+ buf = if !error_type.nil? && uniffi_is_error_type?(e, error_type)
54
+ call_status[:code] = UNIFFI_CALLBACK_ERROR
55
+ lower_error.call e
56
+ else
57
+ call_status[:code] = UNIFFI_CALLBACK_UNEXPECTED_ERROR
58
+ RustBuffer.alloc_from_string(e.inspect)
59
+ end
60
+
61
+ error_buf = call_status[:error_buf]
62
+ error_buf[:capacity] = buf[:capacity]
63
+ error_buf[:len] = buf[:len]
64
+ error_buf[:data] = buf[:data]
65
+ end
66
+ end
67
+
68
+ # Check if an exception is a variant of the given error type.
69
+ # Error types in Ruby are either modules (non-flat enums) or classes (flat enums),
70
+ # with variant classes as constant within them.
71
+ def self.uniffi_is_error_type?(e, error_type)
72
+ # Object-as-error: error_type is a class itself (e.g. MyError < StandardError)
73
+ if error_type.is_a?(Class) && e.is_a?(error_type)
74
+ return true
75
+ end
76
+
77
+ # Enum error: error_type is a module with class constants for each variant
78
+ error_type.constants.any? do |c|
79
+ klass = error_type.const_get c
80
+ klass.is_a?(Class) && e.is_a?(klass)
81
+ end
82
+ end
83
+ # A handle map for converting Ruby objects to/from integer handles.
84
+ #
85
+ # When passing callback interface or trait interface objects to Ruby, we store
86
+ # the Ruby object in this map and pass the integer handle to Rust. When Rust
87
+ # calls back, we look up the Ruby object by its handle.
88
+ #
89
+ # Ruby-created handles are always odd (staring at 1, incrementing by 2).
90
+ # Rust-created handles are always even. This convention lets us distinguish
91
+ # the source in lift/lower without extra metadata.
92
+
93
+
94
+ class UniffiHandleMap
95
+ def initialize
96
+ @lock = Monitor.new
97
+ @map = {}
98
+ @counter = 1 # Start at 1 (odd), increment by 2
99
+ end
100
+
101
+ def insert(obj)
102
+ @lock.synchronize do
103
+ handle = @counter
104
+ @counter += 2
105
+ @map[handle] = obj
106
+ handle
107
+ end
108
+ end
109
+
110
+ def get(handle)
111
+ @lock.synchronize do
112
+ obj = @map[handle]
113
+ raise InternalError, "UniffiHandleMap.get: invalid handle #{handle}" if obj.nil?
114
+ obj
115
+ end
116
+ end
117
+
118
+ def clone_handle(handle)
119
+ @lock.synchronize do
120
+ obj = @map[handle]
121
+ raise InternalError, "UniffiHandleMap.clone_handle: invalid handle #{handle}" if obj.nil?
122
+ new_handle = @counter
123
+ @counter += 2
124
+ @map[new_handle] = obj
125
+ new_handle
126
+ end
127
+ end
128
+
129
+ def remove(handle)
130
+ @lock.synchronize do
131
+ obj = @map.delete(handle)
132
+ raise InternalError, "UniffiHandleMap.remove: invalid handle #{handle}" if obj.nil?
133
+ obj
134
+ end
135
+ end
136
+
137
+ # Used for testing/debugging purposes
138
+ def size
139
+ @lock.synchronize { @map.size }
140
+ end
141
+ end
142
+
143
+ private_constant :UniffiHandleMap
144
+ class RustBuffer < FFI::Struct
145
+ layout :capacity, :uint64,
146
+ :len, :uint64,
147
+ :data, :pointer
148
+
149
+ def self.alloc(size)
150
+ return ::MqttClient.rust_call(:ffi_mqtt_client_rustbuffer_alloc, size)
151
+ end
152
+
153
+ def self.reserve(rbuf, additional)
154
+ return ::MqttClient.rust_call(:ffi_mqtt_client_rustbuffer_reserve, rbuf, additional)
155
+ end
156
+
157
+ def free
158
+ ::MqttClient.rust_call(:ffi_mqtt_client_rustbuffer_free, self)
159
+ end
160
+
161
+ def capacity
162
+ self[:capacity]
163
+ end
164
+
165
+ def len
166
+ self[:len]
167
+ end
168
+
169
+ def len=(value)
170
+ self[:len] = value
171
+ end
172
+
173
+ def data
174
+ self[:data]
175
+ end
176
+
177
+ def to_s
178
+ "RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})"
179
+ end
180
+
181
+ # The allocated buffer will be automatically freed if an error occurs, ensuring that
182
+ # we don't accidentally leak it.
183
+ def self.allocWithBuilder
184
+ builder = RustBufferBuilder.new
185
+
186
+ begin
187
+ yield builder
188
+ rescue => e
189
+ builder.discard
190
+ raise e
191
+ end
192
+ end
193
+
194
+ # The RustBuffer will be freed once the context-manager exits, ensuring that we don't
195
+ # leak it even if an error occurs.
196
+ def consumeWithStream
197
+ stream = RustBufferStream.new self
198
+
199
+ yield stream
200
+
201
+ raise RuntimeError, 'junk data left in buffer after consuming' if stream.remaining != 0
202
+ ensure
203
+ free
204
+ end# The primitive String type.
205
+
206
+ def self.alloc_from_string(value)
207
+ RustBuffer.allocWithBuilder do |builder|
208
+ builder.write value.encode('utf-8')
209
+ return builder.finalize
210
+ end
211
+ end
212
+
213
+ def consume_into_string
214
+ consumeWithStream do |stream|
215
+ return stream.read(stream.remaining).force_encoding(Encoding::UTF_8)
216
+ end
217
+ end
218
+
219
+ # The primitive Bytes type.
220
+
221
+ def self.alloc_from_bytes(value)
222
+ RustBuffer.allocWithBuilder do |builder|
223
+ builder.write_bytes(value)
224
+ return builder.finalize
225
+ end
226
+ end
227
+
228
+ def consume_into_bytes
229
+ consumeWithStream do |stream|
230
+ return stream.read_bytes
231
+ end
232
+ end
233
+
234
+ # The Record type ConnectOptions.
235
+
236
+ def self.check_lower_TypeConnectOptions(v)
237
+
238
+
239
+
240
+ RustBuffer.check_lower_TypeMqttVersion(v.version)
241
+
242
+
243
+ RustBuffer.check_lower_Optionalstring(v.username)
244
+ RustBuffer.check_lower_Optionalbytes(v.password)
245
+ RustBuffer.check_lower_OptionalTypeWillOptions(v.will)
246
+
247
+
248
+
249
+
250
+
251
+ RustBuffer.check_lower_OptionalTypeTlsOptions(v.tls)
252
+
253
+ RustBuffer.check_lower_Optionalstring(v.auth_method)
254
+ RustBuffer.check_lower_Optionalbytes(v.auth_data)
255
+ end
256
+
257
+ def self.alloc_from_TypeConnectOptions(v)
258
+ RustBuffer.allocWithBuilder do |builder|
259
+ builder.write_TypeConnectOptions(v)
260
+ return builder.finalize
261
+ end
262
+ end
263
+
264
+ def consume_into_TypeConnectOptions
265
+ consumeWithStream do |stream|
266
+ return stream.read_TypeConnectOptions
267
+ end
268
+ end
269
+
270
+ # The Record type ConnectResult.
271
+
272
+ def self.check_lower_TypeConnectResult(v)
273
+
274
+
275
+ end
276
+
277
+ def self.alloc_from_TypeConnectResult(v)
278
+ RustBuffer.allocWithBuilder do |builder|
279
+ builder.write_TypeConnectResult(v)
280
+ return builder.finalize
281
+ end
282
+ end
283
+
284
+ def consume_into_TypeConnectResult
285
+ consumeWithStream do |stream|
286
+ return stream.read_TypeConnectResult
287
+ end
288
+ end
289
+
290
+ # The Record type MqttMessage.
291
+
292
+ def self.check_lower_TypeMqttMessage(v)
293
+
294
+
295
+ RustBuffer.check_lower_TypeQoS(v.qos)
296
+
297
+ end
298
+
299
+ def self.alloc_from_TypeMqttMessage(v)
300
+ RustBuffer.allocWithBuilder do |builder|
301
+ builder.write_TypeMqttMessage(v)
302
+ return builder.finalize
303
+ end
304
+ end
305
+
306
+ def consume_into_TypeMqttMessage
307
+ consumeWithStream do |stream|
308
+ return stream.read_TypeMqttMessage
309
+ end
310
+ end
311
+
312
+ # The Record type SubscribeResult.
313
+
314
+ def self.check_lower_TypeSubscribeResult(v)
315
+
316
+ end
317
+
318
+ def self.alloc_from_TypeSubscribeResult(v)
319
+ RustBuffer.allocWithBuilder do |builder|
320
+ builder.write_TypeSubscribeResult(v)
321
+ return builder.finalize
322
+ end
323
+ end
324
+
325
+ def consume_into_TypeSubscribeResult
326
+ consumeWithStream do |stream|
327
+ return stream.read_TypeSubscribeResult
328
+ end
329
+ end
330
+
331
+ # The Record type TlsOptions.
332
+
333
+ def self.check_lower_TypeTlsOptions(v)
334
+ RustBuffer.check_lower_Optionalbytes(v.ca_cert_pem)
335
+ RustBuffer.check_lower_Optionalbytes(v.client_cert_pem)
336
+ RustBuffer.check_lower_Optionalbytes(v.client_key_pem)
337
+
338
+ end
339
+
340
+ def self.alloc_from_TypeTlsOptions(v)
341
+ RustBuffer.allocWithBuilder do |builder|
342
+ builder.write_TypeTlsOptions(v)
343
+ return builder.finalize
344
+ end
345
+ end
346
+
347
+ def consume_into_TypeTlsOptions
348
+ consumeWithStream do |stream|
349
+ return stream.read_TypeTlsOptions
350
+ end
351
+ end
352
+
353
+ # The Record type WillOptions.
354
+
355
+ def self.check_lower_TypeWillOptions(v)
356
+
357
+
358
+ RustBuffer.check_lower_TypeQoS(v.qos)
359
+
360
+ end
361
+
362
+ def self.alloc_from_TypeWillOptions(v)
363
+ RustBuffer.allocWithBuilder do |builder|
364
+ builder.write_TypeWillOptions(v)
365
+ return builder.finalize
366
+ end
367
+ end
368
+
369
+ def consume_into_TypeWillOptions
370
+ consumeWithStream do |stream|
371
+ return stream.read_TypeWillOptions
372
+ end
373
+ end
374
+
375
+ # Error enum - generate alloc_from for callback error serialization
376
+ def self.alloc_from_TypeMqttError(v)
377
+ RustBuffer.allocWithBuilder do |builder|
378
+ builder.write_TypeMqttError(v)
379
+ return builder.finalize
380
+ end
381
+ end
382
+
383
+ # Enum used as error - generate consume_into_ for use as a return value
384
+ def consume_into_TypeMqttError
385
+ consumeWithStream do |stream|
386
+ return stream.read_TypeMqttError
387
+ end
388
+ end
389
+
390
+
391
+ # The Enum type MqttVersion.
392
+
393
+ def self.check_lower_TypeMqttVersion(v)
394
+ end
395
+
396
+ def self.alloc_from_TypeMqttVersion(v)
397
+ RustBuffer.allocWithBuilder do |builder|
398
+ builder.write_TypeMqttVersion(v)
399
+ return builder.finalize
400
+ end
401
+ end
402
+
403
+ def consume_into_TypeMqttVersion
404
+ consumeWithStream do |stream|
405
+ return stream.read_TypeMqttVersion
406
+ end
407
+ end
408
+
409
+
410
+ # The Enum type QoS.
411
+
412
+ def self.check_lower_TypeQoS(v)
413
+ end
414
+
415
+ def self.alloc_from_TypeQoS(v)
416
+ RustBuffer.allocWithBuilder do |builder|
417
+ builder.write_TypeQoS(v)
418
+ return builder.finalize
419
+ end
420
+ end
421
+
422
+ def consume_into_TypeQoS
423
+ consumeWithStream do |stream|
424
+ return stream.read_TypeQoS
425
+ end
426
+ end
427
+
428
+
429
+ # The Optional<T> type for string.
430
+
431
+ def self.check_lower_Optionalstring(v)
432
+ if !v.nil?
433
+
434
+ end
435
+ end
436
+
437
+ def self.alloc_from_Optionalstring(v)
438
+ RustBuffer.allocWithBuilder do |builder|
439
+ builder.write_Optionalstring(v)
440
+ return builder.finalize()
441
+ end
442
+ end
443
+
444
+ def consume_into_Optionalstring
445
+ consumeWithStream do |stream|
446
+ return stream.read_Optionalstring
447
+ end
448
+ end
449
+
450
+ # The Optional<T> type for bytes.
451
+
452
+ def self.check_lower_Optionalbytes(v)
453
+ if !v.nil?
454
+
455
+ end
456
+ end
457
+
458
+ def self.alloc_from_Optionalbytes(v)
459
+ RustBuffer.allocWithBuilder do |builder|
460
+ builder.write_Optionalbytes(v)
461
+ return builder.finalize()
462
+ end
463
+ end
464
+
465
+ def consume_into_Optionalbytes
466
+ consumeWithStream do |stream|
467
+ return stream.read_Optionalbytes
468
+ end
469
+ end
470
+
471
+ # The Optional<T> type for TypeMqttMessage.
472
+
473
+ def self.check_lower_OptionalTypeMqttMessage(v)
474
+ if !v.nil?
475
+ RustBuffer.check_lower_TypeMqttMessage(v)
476
+ end
477
+ end
478
+
479
+ def self.alloc_from_OptionalTypeMqttMessage(v)
480
+ RustBuffer.allocWithBuilder do |builder|
481
+ builder.write_OptionalTypeMqttMessage(v)
482
+ return builder.finalize()
483
+ end
484
+ end
485
+
486
+ def consume_into_OptionalTypeMqttMessage
487
+ consumeWithStream do |stream|
488
+ return stream.read_OptionalTypeMqttMessage
489
+ end
490
+ end
491
+
492
+ # The Optional<T> type for TypeTlsOptions.
493
+
494
+ def self.check_lower_OptionalTypeTlsOptions(v)
495
+ if !v.nil?
496
+ RustBuffer.check_lower_TypeTlsOptions(v)
497
+ end
498
+ end
499
+
500
+ def self.alloc_from_OptionalTypeTlsOptions(v)
501
+ RustBuffer.allocWithBuilder do |builder|
502
+ builder.write_OptionalTypeTlsOptions(v)
503
+ return builder.finalize()
504
+ end
505
+ end
506
+
507
+ def consume_into_OptionalTypeTlsOptions
508
+ consumeWithStream do |stream|
509
+ return stream.read_OptionalTypeTlsOptions
510
+ end
511
+ end
512
+
513
+ # The Optional<T> type for TypeWillOptions.
514
+
515
+ def self.check_lower_OptionalTypeWillOptions(v)
516
+ if !v.nil?
517
+ RustBuffer.check_lower_TypeWillOptions(v)
518
+ end
519
+ end
520
+
521
+ def self.alloc_from_OptionalTypeWillOptions(v)
522
+ RustBuffer.allocWithBuilder do |builder|
523
+ builder.write_OptionalTypeWillOptions(v)
524
+ return builder.finalize()
525
+ end
526
+ end
527
+
528
+ def consume_into_OptionalTypeWillOptions
529
+ consumeWithStream do |stream|
530
+ return stream.read_OptionalTypeWillOptions
531
+ end
532
+ end
533
+
534
+
535
+ end
536
+
537
+ module UniFFILib
538
+ class ForeignBytes < FFI::Struct
539
+ layout :len, :int32,
540
+ :data, :pointer
541
+
542
+ def len
543
+ self[:len]
544
+ end
545
+
546
+ def data
547
+ self[:data]
548
+ end
549
+
550
+ def to_s
551
+ "ForeignBytes(len=#{len}, data=#{data.read_bytes(len)})"
552
+ end
553
+ end
554
+ end
555
+
556
+ private_constant :UniFFILib
557
+
558
+ # Helper for structured reading of values from a RustBuffer.
559
+ class RustBufferStream
560
+
561
+ def initialize(rbuf)
562
+ @rbuf = rbuf
563
+ @offset = 0
564
+ end
565
+
566
+ def remaining
567
+ @rbuf.len - @offset
568
+ end
569
+
570
+ def read(size)
571
+ raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
572
+
573
+ data = @rbuf.data.get_bytes @offset, size
574
+
575
+ @offset += size
576
+
577
+ data
578
+ end
579
+
580
+ def read_u8
581
+ unpack_from 1, 'c'
582
+ end
583
+
584
+ def read_u16
585
+ unpack_from 2, 'S>'
586
+ end
587
+
588
+ def read_u32
589
+ unpack_from 4, 'L>'
590
+ end
591
+
592
+ def read_bool
593
+ v = unpack_from 1, 'c'
594
+
595
+ return false if v == 0
596
+ return true if v == 1
597
+
598
+ raise InternalError, 'Unexpected byte for Boolean type'
599
+ end
600
+
601
+ def read_string
602
+ size = unpack_from 4, 'l>'
603
+
604
+ raise InternalError, 'Unexpected negative string length' if size.negative?
605
+
606
+ read(size).force_encoding(Encoding::UTF_8)
607
+ end
608
+
609
+ def read_bytes
610
+ size = unpack_from 4, 'l>'
611
+
612
+ raise InternalError, 'Unexpected negative byte string length' if size.negative?
613
+
614
+ read(size).force_encoding(Encoding::BINARY)
615
+ end
616
+
617
+ # The Object type MqttAuthHandler.
618
+
619
+ def read_TypeMqttAuthHandler
620
+ handle = unpack_from 8, 'Q>'
621
+ return MqttAuthHandler.uniffi_lift(handle)
622
+ end
623
+
624
+ # The Object type MqttClient.
625
+
626
+ def read_TypeMqttClient
627
+ handle = unpack_from 8, 'Q>'
628
+ return MqttClient.uniffi_lift(handle)
629
+ end
630
+
631
+ # The Object type MqttMessageListener.
632
+
633
+ def read_TypeMqttMessageListener
634
+ handle = unpack_from 8, 'Q>'
635
+ return MqttMessageListener.uniffi_lift(handle)
636
+ end
637
+
638
+ # The Record type ConnectOptions.
639
+
640
+ def read_TypeConnectOptions
641
+ ConnectOptions.new(
642
+ host: read_string,
643
+ port: read_u16,
644
+ client_id: read_string,
645
+ version: read_TypeMqttVersion,
646
+ clean_start: read_bool,
647
+ keep_alive_secs: read_u16,
648
+ username: read_Optionalstring,
649
+ password: read_Optionalbytes,
650
+ will: read_OptionalTypeWillOptions,
651
+ connect_timeout_secs: read_u32,
652
+ operation_timeout_secs: read_u32,
653
+ auto_reconnect: read_bool,
654
+ reconnect_backoff_secs: read_u32,
655
+ reconnect_max_backoff_secs: read_u32,
656
+ tls: read_OptionalTypeTlsOptions,
657
+ max_packet_size: read_u32,
658
+ auth_method: read_Optionalstring,
659
+ auth_data: read_Optionalbytes
660
+ )
661
+ end
662
+
663
+ # The Record type ConnectResult.
664
+
665
+ def read_TypeConnectResult
666
+ ConnectResult.new(
667
+ session_present: read_bool,
668
+ reason_code: read_u8
669
+ )
670
+ end
671
+
672
+ # The Record type MqttMessage.
673
+
674
+ def read_TypeMqttMessage
675
+ MqttMessage.new(
676
+ topic: read_string,
677
+ payload: read_bytes,
678
+ qos: read_TypeQoS,
679
+ retain: read_bool
680
+ )
681
+ end
682
+
683
+ # The Record type SubscribeResult.
684
+
685
+ def read_TypeSubscribeResult
686
+ SubscribeResult.new(
687
+ reason_code: read_u8
688
+ )
689
+ end
690
+
691
+ # The Record type TlsOptions.
692
+
693
+ def read_TypeTlsOptions
694
+ TlsOptions.new(
695
+ ca_cert_pem: read_Optionalbytes,
696
+ client_cert_pem: read_Optionalbytes,
697
+ client_key_pem: read_Optionalbytes,
698
+ insecure_skip_certificate_verification: read_bool
699
+ )
700
+ end
701
+
702
+ # The Record type WillOptions.
703
+
704
+ def read_TypeWillOptions
705
+ WillOptions.new(
706
+ topic: read_string,
707
+ payload: read_bytes,
708
+ qos: read_TypeQoS,
709
+ retain: read_bool
710
+ )
711
+ end
712
+
713
+
714
+
715
+
716
+
717
+ # The Error type MqttError
718
+
719
+ def read_TypeMqttError
720
+ variant = unpack_from 4, 'l>'
721
+
722
+ if variant == 1
723
+ return MqttError::MalformedPacket.new(
724
+ read_string()
725
+ )
726
+ end
727
+ if variant == 2
728
+ return MqttError::Protocol.new(
729
+ read_string()
730
+ )
731
+ end
732
+ if variant == 3
733
+ return MqttError::Io.new(
734
+ read_string()
735
+ )
736
+ end
737
+ if variant == 4
738
+ return MqttError::ConnectionRefused.new(
739
+ read_string()
740
+ )
741
+ end
742
+ if variant == 5
743
+ return MqttError::NotConnected.new(
744
+ read_string()
745
+ )
746
+ end
747
+ if variant == 6
748
+ return MqttError::PacketTooLarge.new(
749
+ read_string()
750
+ )
751
+ end
752
+ if variant == 7
753
+ return MqttError::AlreadyConnected.new(
754
+ read_string()
755
+ )
756
+ end
757
+ if variant == 8
758
+ return MqttError::Timeout.new(
759
+ read_string()
760
+ )
761
+ end
762
+ if variant == 9
763
+ return MqttError::Session.new(
764
+ read_string()
765
+ )
766
+ end
767
+
768
+ raise InternalError, 'Unexpected variant tag for TypeMqttError'
769
+ end
770
+
771
+
772
+
773
+
774
+ # The Enum type MqttVersion.
775
+
776
+ def read_TypeMqttVersion
777
+ variant = unpack_from 4, 'l>'
778
+
779
+ if variant == 1
780
+ return MqttVersion::V311
781
+ end
782
+ if variant == 2
783
+ return MqttVersion::V5
784
+ end
785
+
786
+ raise InternalError, 'Unexpected variant tag for TypeMqttVersion'
787
+ end
788
+
789
+
790
+
791
+
792
+
793
+ # The Enum type QoS.
794
+
795
+ def read_TypeQoS
796
+ variant = unpack_from 4, 'l>'
797
+
798
+ if variant == 1
799
+ return QoS::AT_MOST_ONCE
800
+ end
801
+ if variant == 2
802
+ return QoS::AT_LEAST_ONCE
803
+ end
804
+ if variant == 3
805
+ return QoS::EXACTLY_ONCE
806
+ end
807
+
808
+ raise InternalError, 'Unexpected variant tag for TypeQoS'
809
+ end
810
+
811
+
812
+
813
+
814
+ # The Optional<T> type for string.
815
+
816
+ def read_Optionalstring
817
+ flag = unpack_from 1, 'c'
818
+
819
+ if flag == 0
820
+ return nil
821
+ elsif flag == 1
822
+ return read_string
823
+ else
824
+ raise InternalError, 'Unexpected flag byte for Optionalstring'
825
+ end
826
+ end
827
+
828
+
829
+ # The Optional<T> type for bytes.
830
+
831
+ def read_Optionalbytes
832
+ flag = unpack_from 1, 'c'
833
+
834
+ if flag == 0
835
+ return nil
836
+ elsif flag == 1
837
+ return read_bytes
838
+ else
839
+ raise InternalError, 'Unexpected flag byte for Optionalbytes'
840
+ end
841
+ end
842
+
843
+
844
+ # The Optional<T> type for TypeMqttMessage.
845
+
846
+ def read_OptionalTypeMqttMessage
847
+ flag = unpack_from 1, 'c'
848
+
849
+ if flag == 0
850
+ return nil
851
+ elsif flag == 1
852
+ return read_TypeMqttMessage
853
+ else
854
+ raise InternalError, 'Unexpected flag byte for OptionalTypeMqttMessage'
855
+ end
856
+ end
857
+
858
+
859
+ # The Optional<T> type for TypeTlsOptions.
860
+
861
+ def read_OptionalTypeTlsOptions
862
+ flag = unpack_from 1, 'c'
863
+
864
+ if flag == 0
865
+ return nil
866
+ elsif flag == 1
867
+ return read_TypeTlsOptions
868
+ else
869
+ raise InternalError, 'Unexpected flag byte for OptionalTypeTlsOptions'
870
+ end
871
+ end
872
+
873
+
874
+ # The Optional<T> type for TypeWillOptions.
875
+
876
+ def read_OptionalTypeWillOptions
877
+ flag = unpack_from 1, 'c'
878
+
879
+ if flag == 0
880
+ return nil
881
+ elsif flag == 1
882
+ return read_TypeWillOptions
883
+ else
884
+ raise InternalError, 'Unexpected flag byte for OptionalTypeWillOptions'
885
+ end
886
+ end
887
+
888
+
889
+
890
+ def unpack_from(size, format)
891
+ raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
892
+
893
+ value = @rbuf.data.get_bytes(@offset, size).unpack format
894
+
895
+ @offset += size
896
+
897
+ # TODO: verify this
898
+ raise 'more than one element!!!' if value.size > 1
899
+
900
+ value[0]
901
+ end
902
+ end
903
+
904
+ private_constant :RustBufferStream
905
+
906
+ # Helper for structured writing of values into a RustBuffer.
907
+ class RustBufferBuilder
908
+ def initialize
909
+ @rust_buf = RustBuffer.alloc 16
910
+ @rust_buf.len = 0
911
+ end
912
+
913
+ def finalize
914
+ rbuf = @rust_buf
915
+
916
+ @rust_buf = nil
917
+
918
+ rbuf
919
+ end
920
+
921
+ def discard
922
+ return if @rust_buf.nil?
923
+
924
+ rbuf = finalize
925
+ rbuf.free
926
+ end
927
+
928
+ def write(value)
929
+ reserve(value.bytes.size) do
930
+ @rust_buf.data.put_array_of_char @rust_buf.len, value.bytes
931
+ end
932
+ end
933
+
934
+ def write_u8(v)
935
+ v = ::MqttClient::uniffi_in_range(v, "u8", 0, 2**8)
936
+ pack_into(1, 'c', v)
937
+ end
938
+
939
+ def write_u16(v)
940
+ v = ::MqttClient::uniffi_in_range(v, "u16", 0, 2**16)
941
+ pack_into(2, 'S>', v)
942
+ end
943
+
944
+ def write_u32(v)
945
+ v = ::MqttClient::uniffi_in_range(v, "u32", 0, 2**32)
946
+ pack_into(4, 'L>', v)
947
+ end
948
+
949
+ def write_bool(v)
950
+ pack_into(1, 'c', v ? 1 : 0)
951
+ end
952
+
953
+ def write_string(v)
954
+ v = ::MqttClient::uniffi_utf8(v)
955
+ pack_into 4, 'l>', v.bytes.size
956
+ write v
957
+ end
958
+
959
+ def write_bytes(v)
960
+ v = ::MqttClient::uniffi_bytes(v)
961
+ pack_into 4, 'l>', v.bytes.size
962
+ write v
963
+ end
964
+
965
+ # The Object type MqttAuthHandler.
966
+
967
+ def write_TypeMqttAuthHandler(obj)
968
+ handle = MqttAuthHandler.uniffi_lower obj
969
+ pack_into(8, 'Q>', handle)
970
+ end
971
+
972
+ # The Object type MqttClient.
973
+
974
+ def write_TypeMqttClient(obj)
975
+ handle = MqttClient.uniffi_lower obj
976
+ pack_into(8, 'Q>', handle)
977
+ end
978
+
979
+ # The Object type MqttMessageListener.
980
+
981
+ def write_TypeMqttMessageListener(obj)
982
+ handle = MqttMessageListener.uniffi_lower obj
983
+ pack_into(8, 'Q>', handle)
984
+ end
985
+
986
+ # The Record type ConnectOptions.
987
+
988
+ def write_TypeConnectOptions(v)
989
+ self.write_string(v.host)
990
+ self.write_u16(v.port)
991
+ self.write_string(v.client_id)
992
+ self.write_TypeMqttVersion(v.version)
993
+ self.write_bool(v.clean_start)
994
+ self.write_u16(v.keep_alive_secs)
995
+ self.write_Optionalstring(v.username)
996
+ self.write_Optionalbytes(v.password)
997
+ self.write_OptionalTypeWillOptions(v.will)
998
+ self.write_u32(v.connect_timeout_secs)
999
+ self.write_u32(v.operation_timeout_secs)
1000
+ self.write_bool(v.auto_reconnect)
1001
+ self.write_u32(v.reconnect_backoff_secs)
1002
+ self.write_u32(v.reconnect_max_backoff_secs)
1003
+ self.write_OptionalTypeTlsOptions(v.tls)
1004
+ self.write_u32(v.max_packet_size)
1005
+ self.write_Optionalstring(v.auth_method)
1006
+ self.write_Optionalbytes(v.auth_data)
1007
+ end
1008
+
1009
+ # The Record type ConnectResult.
1010
+
1011
+ def write_TypeConnectResult(v)
1012
+ self.write_bool(v.session_present)
1013
+ self.write_u8(v.reason_code)
1014
+ end
1015
+
1016
+ # The Record type MqttMessage.
1017
+
1018
+ def write_TypeMqttMessage(v)
1019
+ self.write_string(v.topic)
1020
+ self.write_bytes(v.payload)
1021
+ self.write_TypeQoS(v.qos)
1022
+ self.write_bool(v.retain)
1023
+ end
1024
+
1025
+ # The Record type SubscribeResult.
1026
+
1027
+ def write_TypeSubscribeResult(v)
1028
+ self.write_u8(v.reason_code)
1029
+ end
1030
+
1031
+ # The Record type TlsOptions.
1032
+
1033
+ def write_TypeTlsOptions(v)
1034
+ self.write_Optionalbytes(v.ca_cert_pem)
1035
+ self.write_Optionalbytes(v.client_cert_pem)
1036
+ self.write_Optionalbytes(v.client_key_pem)
1037
+ self.write_bool(v.insecure_skip_certificate_verification)
1038
+ end
1039
+
1040
+ # The Record type WillOptions.
1041
+
1042
+ def write_TypeWillOptions(v)
1043
+ self.write_string(v.topic)
1044
+ self.write_bytes(v.payload)
1045
+ self.write_TypeQoS(v.qos)
1046
+ self.write_bool(v.retain)
1047
+ end
1048
+
1049
+ # The Error type MqttError - write for callback error returns.
1050
+
1051
+ def write_TypeMqttError(v)
1052
+ if v.is_a?(MqttError::MalformedPacket)
1053
+ pack_into 4, 'l>', 1
1054
+ return
1055
+ end
1056
+ if v.is_a?(MqttError::Protocol)
1057
+ pack_into 4, 'l>', 2
1058
+ return
1059
+ end
1060
+ if v.is_a?(MqttError::Io)
1061
+ pack_into 4, 'l>', 3
1062
+ return
1063
+ end
1064
+ if v.is_a?(MqttError::ConnectionRefused)
1065
+ pack_into 4, 'l>', 4
1066
+ return
1067
+ end
1068
+ if v.is_a?(MqttError::NotConnected)
1069
+ pack_into 4, 'l>', 5
1070
+ return
1071
+ end
1072
+ if v.is_a?(MqttError::PacketTooLarge)
1073
+ pack_into 4, 'l>', 6
1074
+ return
1075
+ end
1076
+ if v.is_a?(MqttError::AlreadyConnected)
1077
+ pack_into 4, 'l>', 7
1078
+ return
1079
+ end
1080
+ if v.is_a?(MqttError::Timeout)
1081
+ pack_into 4, 'l>', 8
1082
+ return
1083
+ end
1084
+ if v.is_a?(MqttError::Session)
1085
+ pack_into 4, 'l>', 9
1086
+ return
1087
+ end
1088
+ end
1089
+
1090
+
1091
+ # The Enum type MqttVersion.
1092
+
1093
+ def write_TypeMqttVersion(v)
1094
+ if v == MqttVersion::V311
1095
+ pack_into(4, 'l>', 1)
1096
+ end
1097
+ if v == MqttVersion::V5
1098
+ pack_into(4, 'l>', 2)
1099
+ end
1100
+ end
1101
+
1102
+
1103
+ # The Enum type QoS.
1104
+
1105
+ def write_TypeQoS(v)
1106
+ if v == QoS::AT_MOST_ONCE
1107
+ pack_into(4, 'l>', 1)
1108
+ end
1109
+ if v == QoS::AT_LEAST_ONCE
1110
+ pack_into(4, 'l>', 2)
1111
+ end
1112
+ if v == QoS::EXACTLY_ONCE
1113
+ pack_into(4, 'l>', 3)
1114
+ end
1115
+ end
1116
+
1117
+
1118
+ # The Optional<T> type for string.
1119
+
1120
+ def write_Optionalstring(v)
1121
+ if v.nil?
1122
+ pack_into(1, 'c', 0)
1123
+ else
1124
+ pack_into(1, 'c', 1)
1125
+ self.write_string(v)
1126
+ end
1127
+ end
1128
+
1129
+ # The Optional<T> type for bytes.
1130
+
1131
+ def write_Optionalbytes(v)
1132
+ if v.nil?
1133
+ pack_into(1, 'c', 0)
1134
+ else
1135
+ pack_into(1, 'c', 1)
1136
+ self.write_bytes(v)
1137
+ end
1138
+ end
1139
+
1140
+ # The Optional<T> type for TypeMqttMessage.
1141
+
1142
+ def write_OptionalTypeMqttMessage(v)
1143
+ if v.nil?
1144
+ pack_into(1, 'c', 0)
1145
+ else
1146
+ pack_into(1, 'c', 1)
1147
+ self.write_TypeMqttMessage(v)
1148
+ end
1149
+ end
1150
+
1151
+ # The Optional<T> type for TypeTlsOptions.
1152
+
1153
+ def write_OptionalTypeTlsOptions(v)
1154
+ if v.nil?
1155
+ pack_into(1, 'c', 0)
1156
+ else
1157
+ pack_into(1, 'c', 1)
1158
+ self.write_TypeTlsOptions(v)
1159
+ end
1160
+ end
1161
+
1162
+ # The Optional<T> type for TypeWillOptions.
1163
+
1164
+ def write_OptionalTypeWillOptions(v)
1165
+ if v.nil?
1166
+ pack_into(1, 'c', 0)
1167
+ else
1168
+ pack_into(1, 'c', 1)
1169
+ self.write_TypeWillOptions(v)
1170
+ end
1171
+ end
1172
+
1173
+
1174
+
1175
+ private
1176
+
1177
+ def reserve(num_bytes)
1178
+ if @rust_buf.len + num_bytes > @rust_buf.capacity
1179
+ @rust_buf = RustBuffer.reserve(@rust_buf, num_bytes)
1180
+ end
1181
+
1182
+ yield
1183
+
1184
+ @rust_buf.len += num_bytes
1185
+ end
1186
+
1187
+ def pack_into(size, format, value)
1188
+ reserve(size) do
1189
+ @rust_buf.data.put_array_of_char @rust_buf.len, [value].pack(format).bytes
1190
+ end
1191
+ end
1192
+ end
1193
+
1194
+ private_constant :RustBufferBuilder
1195
+
1196
+ # Error definitions
1197
+ class RustCallStatus < FFI::Struct
1198
+ layout :code, :int8,
1199
+ :error_buf, RustBuffer
1200
+
1201
+ def code
1202
+ self[:code]
1203
+ end
1204
+
1205
+ def error_buf
1206
+ self[:error_buf]
1207
+ end
1208
+
1209
+ def to_s
1210
+ "RustCallStatus(code=#{self[:code]})"
1211
+ end
1212
+ end
1213
+
1214
+ # These match the values from the uniffi::rustcalls module
1215
+ CALL_SUCCESS = 0
1216
+ CALL_ERROR = 1
1217
+ CALL_PANIC = 2
1218
+
1219
+
1220
+ class MqttError
1221
+ MalformedPacket = Class.new StandardError
1222
+ Protocol = Class.new StandardError
1223
+ Io = Class.new StandardError
1224
+ ConnectionRefused = Class.new StandardError
1225
+ NotConnected = Class.new StandardError
1226
+ PacketTooLarge = Class.new StandardError
1227
+ AlreadyConnected = Class.new StandardError
1228
+ Timeout = Class.new StandardError
1229
+ Session = Class.new StandardError
1230
+
1231
+ end
1232
+
1233
+
1234
+
1235
+
1236
+ # Map error modules to the RustBuffer method name that reads them
1237
+ ERROR_MODULE_TO_READER_METHOD = {
1238
+ MqttError => :read_TypeMqttError,
1239
+ }
1240
+
1241
+ private_constant :ERROR_MODULE_TO_READER_METHOD, :CALL_SUCCESS, :CALL_ERROR, :CALL_PANIC,
1242
+ :RustCallStatus
1243
+
1244
+ def self.consume_buffer_into_error(error_module, rust_buffer)
1245
+ rust_buffer.consumeWithStream do |stream|
1246
+ reader_method = ERROR_MODULE_TO_READER_METHOD[error_module] ||
1247
+ ERROR_MODULE_TO_READER_METHOD[error_module.name&.split('::')&.last]
1248
+ return stream.send(reader_method)
1249
+ end
1250
+ end
1251
+
1252
+ class InternalError < StandardError
1253
+ end
1254
+
1255
+ def self.rust_call(fn_name, *args)
1256
+ # Call a rust function
1257
+ rust_call_with_error(nil, fn_name, *args)
1258
+ end
1259
+
1260
+ def self.rust_call_with_error(error_module, fn_name, *args)
1261
+ # Call a rust function and handle errors
1262
+ #
1263
+ # Use this when the rust function returns a Result<>. error_module must be the error_module that corresponds to that Result.
1264
+
1265
+
1266
+ # Note: RustCallStatus.new zeroes out the struct, which is exactly what we
1267
+ # want to pass to Rust (code=0, error_buf=RustBuffer(len=0, capacity=0,
1268
+ # data=NULL))
1269
+ status = RustCallStatus.new
1270
+ args << status
1271
+
1272
+ result = UniFFILib.public_send(fn_name, *args)
1273
+
1274
+ case status.code
1275
+ when CALL_SUCCESS
1276
+ result
1277
+ when CALL_ERROR
1278
+ if error_module.nil?
1279
+ status.error_buf.free
1280
+ raise InternalError, "CALL_ERROR with no error_module set"
1281
+ else
1282
+ raise consume_buffer_into_error(error_module, status.error_buf)
1283
+ end
1284
+ when CALL_PANIC
1285
+ # When the rust code sees a panic, it tries to construct a RustBuffer
1286
+ # with the message. But if that code panics, then it just sends back
1287
+ # an empty buffer.
1288
+ if status.error_buf.len > 0
1289
+ raise InternalError, status.error_buf.consume_into_string
1290
+ else
1291
+ raise InternalError, "Rust panic"
1292
+ end
1293
+ else
1294
+ raise InternalError, "Unknown call status: #{status.code}"
1295
+ end
1296
+ end
1297
+
1298
+ private_class_method :consume_buffer_into_error
1299
+
1300
+ # This is how we find and load the dynamic library provided by the component.
1301
+ # For now we just look it up by name.
1302
+ module UniFFILib
1303
+ extend FFI::Library
1304
+
1305
+
1306
+ ffi_lib File.expand_path("native/#{FFI.map_library_name('mqtt_client')}", __dir__)
1307
+
1308
+
1309
+ # Define FFI callback types and structs (vtables, etc.)
1310
+
1311
+ callback :RustFutureContinuationCallback,
1312
+ [:uint64, :int8, ],
1313
+ :void
1314
+
1315
+ callback :ForeignFutureDroppedCallback,
1316
+ [:uint64, ],
1317
+ :void
1318
+
1319
+ callback :CallbackInterfaceFree,
1320
+ [:uint64, ],
1321
+ :void
1322
+
1323
+ callback :CallbackInterfaceClone,
1324
+ [:uint64, ],
1325
+ :uint64
1326
+
1327
+ class ForeignFutureDroppedCallbackStruct < FFI::Struct
1328
+ layout(
1329
+ :handle, :uint64,
1330
+ :free, :ForeignFutureDroppedCallback
1331
+ )
1332
+ end
1333
+
1334
+ class ForeignFutureResultU8 < FFI::Struct
1335
+ layout(
1336
+ :return_value, :uint8,
1337
+ :call_status, RustCallStatus
1338
+ )
1339
+ end
1340
+
1341
+ callback :ForeignFutureCompleteU8,
1342
+ [:uint64, ForeignFutureResultU8.by_value, ],
1343
+ :void
1344
+
1345
+ class ForeignFutureResultI8 < FFI::Struct
1346
+ layout(
1347
+ :return_value, :int8,
1348
+ :call_status, RustCallStatus
1349
+ )
1350
+ end
1351
+
1352
+ callback :ForeignFutureCompleteI8,
1353
+ [:uint64, ForeignFutureResultI8.by_value, ],
1354
+ :void
1355
+
1356
+ class ForeignFutureResultU16 < FFI::Struct
1357
+ layout(
1358
+ :return_value, :uint16,
1359
+ :call_status, RustCallStatus
1360
+ )
1361
+ end
1362
+
1363
+ callback :ForeignFutureCompleteU16,
1364
+ [:uint64, ForeignFutureResultU16.by_value, ],
1365
+ :void
1366
+
1367
+ class ForeignFutureResultI16 < FFI::Struct
1368
+ layout(
1369
+ :return_value, :int16,
1370
+ :call_status, RustCallStatus
1371
+ )
1372
+ end
1373
+
1374
+ callback :ForeignFutureCompleteI16,
1375
+ [:uint64, ForeignFutureResultI16.by_value, ],
1376
+ :void
1377
+
1378
+ class ForeignFutureResultU32 < FFI::Struct
1379
+ layout(
1380
+ :return_value, :uint32,
1381
+ :call_status, RustCallStatus
1382
+ )
1383
+ end
1384
+
1385
+ callback :ForeignFutureCompleteU32,
1386
+ [:uint64, ForeignFutureResultU32.by_value, ],
1387
+ :void
1388
+
1389
+ class ForeignFutureResultI32 < FFI::Struct
1390
+ layout(
1391
+ :return_value, :int32,
1392
+ :call_status, RustCallStatus
1393
+ )
1394
+ end
1395
+
1396
+ callback :ForeignFutureCompleteI32,
1397
+ [:uint64, ForeignFutureResultI32.by_value, ],
1398
+ :void
1399
+
1400
+ class ForeignFutureResultU64 < FFI::Struct
1401
+ layout(
1402
+ :return_value, :uint64,
1403
+ :call_status, RustCallStatus
1404
+ )
1405
+ end
1406
+
1407
+ callback :ForeignFutureCompleteU64,
1408
+ [:uint64, ForeignFutureResultU64.by_value, ],
1409
+ :void
1410
+
1411
+ class ForeignFutureResultI64 < FFI::Struct
1412
+ layout(
1413
+ :return_value, :int64,
1414
+ :call_status, RustCallStatus
1415
+ )
1416
+ end
1417
+
1418
+ callback :ForeignFutureCompleteI64,
1419
+ [:uint64, ForeignFutureResultI64.by_value, ],
1420
+ :void
1421
+
1422
+ class ForeignFutureResultF32 < FFI::Struct
1423
+ layout(
1424
+ :return_value, :float,
1425
+ :call_status, RustCallStatus
1426
+ )
1427
+ end
1428
+
1429
+ callback :ForeignFutureCompleteF32,
1430
+ [:uint64, ForeignFutureResultF32.by_value, ],
1431
+ :void
1432
+
1433
+ class ForeignFutureResultF64 < FFI::Struct
1434
+ layout(
1435
+ :return_value, :double,
1436
+ :call_status, RustCallStatus
1437
+ )
1438
+ end
1439
+
1440
+ callback :ForeignFutureCompleteF64,
1441
+ [:uint64, ForeignFutureResultF64.by_value, ],
1442
+ :void
1443
+
1444
+ class ForeignFutureResultRustBuffer < FFI::Struct
1445
+ layout(
1446
+ :return_value, RustBuffer.by_value,
1447
+ :call_status, RustCallStatus
1448
+ )
1449
+ end
1450
+
1451
+ callback :ForeignFutureCompleteRustBuffer,
1452
+ [:uint64, ForeignFutureResultRustBuffer.by_value, ],
1453
+ :void
1454
+
1455
+ class ForeignFutureResultVoid < FFI::Struct
1456
+ layout(
1457
+ :call_status, RustCallStatus
1458
+ )
1459
+ end
1460
+
1461
+ callback :ForeignFutureCompleteVoid,
1462
+ [:uint64, ForeignFutureResultVoid.by_value, ],
1463
+ :void
1464
+
1465
+ callback :CallbackInterfaceMqttAuthHandlerMethod0,
1466
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
1467
+ :void
1468
+
1469
+ callback :CallbackInterfaceMqttMessageListenerMethod0,
1470
+ [:uint64, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
1471
+ :void
1472
+
1473
+ callback :CallbackInterfaceMqttMessageListenerMethod1,
1474
+ [:uint64, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
1475
+ :void
1476
+
1477
+ class VTableCallbackInterfaceMqttAuthHandler < FFI::Struct
1478
+ layout(
1479
+ :uniffi_free, :CallbackInterfaceFree,
1480
+ :uniffi_clone, :CallbackInterfaceClone,
1481
+ :respond, :CallbackInterfaceMqttAuthHandlerMethod0
1482
+ )
1483
+ end
1484
+
1485
+ class VTableCallbackInterfaceMqttMessageListener < FFI::Struct
1486
+ layout(
1487
+ :uniffi_free, :CallbackInterfaceFree,
1488
+ :uniffi_clone, :CallbackInterfaceClone,
1489
+ :on_message, :CallbackInterfaceMqttMessageListenerMethod0,
1490
+ :on_disconnected, :CallbackInterfaceMqttMessageListenerMethod1
1491
+ )
1492
+ end
1493
+
1494
+ attach_function :uniffi_mqtt_client_fn_clone_mqttclient,
1495
+ [:uint64, RustCallStatus.by_ref],
1496
+ :uint64
1497
+
1498
+ attach_function :uniffi_mqtt_client_fn_free_mqttclient,
1499
+ [:uint64, RustCallStatus.by_ref],
1500
+ :void
1501
+
1502
+ attach_function :uniffi_mqtt_client_fn_constructor_mqttclient_new,
1503
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1504
+ :uint64
1505
+
1506
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_connect,
1507
+ [:uint64, ],
1508
+ :uint64
1509
+
1510
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_disconnect,
1511
+ [:uint64, ],
1512
+ :uint64
1513
+
1514
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_enable_message_queue,
1515
+ [:uint64, :uint32, RustCallStatus.by_ref],
1516
+ :void
1517
+
1518
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_is_connected,
1519
+ [:uint64, RustCallStatus.by_ref],
1520
+ :int8
1521
+
1522
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_last_disconnect_reason,
1523
+ [:uint64, RustCallStatus.by_ref],
1524
+ RustBuffer.by_value
1525
+
1526
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_next_message,
1527
+ [:uint64, :uint32, ],
1528
+ :uint64
1529
+
1530
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_publish,
1531
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :int8, ],
1532
+ :uint64
1533
+
1534
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_set_auth_handler,
1535
+ [:uint64, :uint64, RustCallStatus.by_ref],
1536
+ :void
1537
+
1538
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_set_message_listener,
1539
+ [:uint64, :uint64, RustCallStatus.by_ref],
1540
+ :void
1541
+
1542
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_subscribe,
1543
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, ],
1544
+ :uint64
1545
+
1546
+ attach_function :uniffi_mqtt_client_fn_method_mqttclient_unsubscribe,
1547
+ [:uint64, RustBuffer.by_value, ],
1548
+ :uint64
1549
+
1550
+ attach_function :uniffi_mqtt_client_fn_clone_mqttauthhandler,
1551
+ [:uint64, RustCallStatus.by_ref],
1552
+ :uint64
1553
+
1554
+ attach_function :uniffi_mqtt_client_fn_free_mqttauthhandler,
1555
+ [:uint64, RustCallStatus.by_ref],
1556
+ :void
1557
+
1558
+ attach_function :uniffi_mqtt_client_fn_init_callback_vtable_mqttauthhandler,
1559
+ [VTableCallbackInterfaceMqttAuthHandler.by_ref, ],
1560
+ :void
1561
+
1562
+ attach_function :uniffi_mqtt_client_fn_method_mqttauthhandler_respond,
1563
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1564
+ RustBuffer.by_value
1565
+
1566
+ attach_function :uniffi_mqtt_client_fn_clone_mqttmessagelistener,
1567
+ [:uint64, RustCallStatus.by_ref],
1568
+ :uint64
1569
+
1570
+ attach_function :uniffi_mqtt_client_fn_free_mqttmessagelistener,
1571
+ [:uint64, RustCallStatus.by_ref],
1572
+ :void
1573
+
1574
+ attach_function :uniffi_mqtt_client_fn_init_callback_vtable_mqttmessagelistener,
1575
+ [VTableCallbackInterfaceMqttMessageListener.by_ref, ],
1576
+ :void
1577
+
1578
+ attach_function :uniffi_mqtt_client_fn_method_mqttmessagelistener_on_message,
1579
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
1580
+ :void
1581
+
1582
+ attach_function :uniffi_mqtt_client_fn_method_mqttmessagelistener_on_disconnected,
1583
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
1584
+ :void
1585
+
1586
+ attach_function :ffi_mqtt_client_rustbuffer_alloc,
1587
+ [:uint64, RustCallStatus.by_ref],
1588
+ RustBuffer.by_value
1589
+
1590
+ attach_function :ffi_mqtt_client_rustbuffer_from_bytes,
1591
+ [ForeignBytes, RustCallStatus.by_ref],
1592
+ RustBuffer.by_value
1593
+
1594
+ attach_function :ffi_mqtt_client_rustbuffer_free,
1595
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1596
+ :void
1597
+
1598
+ attach_function :ffi_mqtt_client_rustbuffer_reserve,
1599
+ [RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
1600
+ RustBuffer.by_value
1601
+
1602
+ attach_function :ffi_mqtt_client_rust_future_poll_u8,
1603
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1604
+ :void
1605
+
1606
+ attach_function :ffi_mqtt_client_rust_future_cancel_u8,
1607
+ [:uint64, ],
1608
+ :void
1609
+
1610
+ attach_function :ffi_mqtt_client_rust_future_free_u8,
1611
+ [:uint64, ],
1612
+ :void
1613
+
1614
+ attach_function :ffi_mqtt_client_rust_future_complete_u8,
1615
+ [:uint64, RustCallStatus.by_ref],
1616
+ :uint8
1617
+
1618
+ attach_function :ffi_mqtt_client_rust_future_poll_i8,
1619
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1620
+ :void
1621
+
1622
+ attach_function :ffi_mqtt_client_rust_future_cancel_i8,
1623
+ [:uint64, ],
1624
+ :void
1625
+
1626
+ attach_function :ffi_mqtt_client_rust_future_free_i8,
1627
+ [:uint64, ],
1628
+ :void
1629
+
1630
+ attach_function :ffi_mqtt_client_rust_future_complete_i8,
1631
+ [:uint64, RustCallStatus.by_ref],
1632
+ :int8
1633
+
1634
+ attach_function :ffi_mqtt_client_rust_future_poll_u16,
1635
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1636
+ :void
1637
+
1638
+ attach_function :ffi_mqtt_client_rust_future_cancel_u16,
1639
+ [:uint64, ],
1640
+ :void
1641
+
1642
+ attach_function :ffi_mqtt_client_rust_future_free_u16,
1643
+ [:uint64, ],
1644
+ :void
1645
+
1646
+ attach_function :ffi_mqtt_client_rust_future_complete_u16,
1647
+ [:uint64, RustCallStatus.by_ref],
1648
+ :uint16
1649
+
1650
+ attach_function :ffi_mqtt_client_rust_future_poll_i16,
1651
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1652
+ :void
1653
+
1654
+ attach_function :ffi_mqtt_client_rust_future_cancel_i16,
1655
+ [:uint64, ],
1656
+ :void
1657
+
1658
+ attach_function :ffi_mqtt_client_rust_future_free_i16,
1659
+ [:uint64, ],
1660
+ :void
1661
+
1662
+ attach_function :ffi_mqtt_client_rust_future_complete_i16,
1663
+ [:uint64, RustCallStatus.by_ref],
1664
+ :int16
1665
+
1666
+ attach_function :ffi_mqtt_client_rust_future_poll_u32,
1667
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1668
+ :void
1669
+
1670
+ attach_function :ffi_mqtt_client_rust_future_cancel_u32,
1671
+ [:uint64, ],
1672
+ :void
1673
+
1674
+ attach_function :ffi_mqtt_client_rust_future_free_u32,
1675
+ [:uint64, ],
1676
+ :void
1677
+
1678
+ attach_function :ffi_mqtt_client_rust_future_complete_u32,
1679
+ [:uint64, RustCallStatus.by_ref],
1680
+ :uint32
1681
+
1682
+ attach_function :ffi_mqtt_client_rust_future_poll_i32,
1683
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1684
+ :void
1685
+
1686
+ attach_function :ffi_mqtt_client_rust_future_cancel_i32,
1687
+ [:uint64, ],
1688
+ :void
1689
+
1690
+ attach_function :ffi_mqtt_client_rust_future_free_i32,
1691
+ [:uint64, ],
1692
+ :void
1693
+
1694
+ attach_function :ffi_mqtt_client_rust_future_complete_i32,
1695
+ [:uint64, RustCallStatus.by_ref],
1696
+ :int32
1697
+
1698
+ attach_function :ffi_mqtt_client_rust_future_poll_u64,
1699
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1700
+ :void
1701
+
1702
+ attach_function :ffi_mqtt_client_rust_future_cancel_u64,
1703
+ [:uint64, ],
1704
+ :void
1705
+
1706
+ attach_function :ffi_mqtt_client_rust_future_free_u64,
1707
+ [:uint64, ],
1708
+ :void
1709
+
1710
+ attach_function :ffi_mqtt_client_rust_future_complete_u64,
1711
+ [:uint64, RustCallStatus.by_ref],
1712
+ :uint64
1713
+
1714
+ attach_function :ffi_mqtt_client_rust_future_poll_i64,
1715
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1716
+ :void
1717
+
1718
+ attach_function :ffi_mqtt_client_rust_future_cancel_i64,
1719
+ [:uint64, ],
1720
+ :void
1721
+
1722
+ attach_function :ffi_mqtt_client_rust_future_free_i64,
1723
+ [:uint64, ],
1724
+ :void
1725
+
1726
+ attach_function :ffi_mqtt_client_rust_future_complete_i64,
1727
+ [:uint64, RustCallStatus.by_ref],
1728
+ :int64
1729
+
1730
+ attach_function :ffi_mqtt_client_rust_future_poll_f32,
1731
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1732
+ :void
1733
+
1734
+ attach_function :ffi_mqtt_client_rust_future_cancel_f32,
1735
+ [:uint64, ],
1736
+ :void
1737
+
1738
+ attach_function :ffi_mqtt_client_rust_future_free_f32,
1739
+ [:uint64, ],
1740
+ :void
1741
+
1742
+ attach_function :ffi_mqtt_client_rust_future_complete_f32,
1743
+ [:uint64, RustCallStatus.by_ref],
1744
+ :float
1745
+
1746
+ attach_function :ffi_mqtt_client_rust_future_poll_f64,
1747
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1748
+ :void
1749
+
1750
+ attach_function :ffi_mqtt_client_rust_future_cancel_f64,
1751
+ [:uint64, ],
1752
+ :void
1753
+
1754
+ attach_function :ffi_mqtt_client_rust_future_free_f64,
1755
+ [:uint64, ],
1756
+ :void
1757
+
1758
+ attach_function :ffi_mqtt_client_rust_future_complete_f64,
1759
+ [:uint64, RustCallStatus.by_ref],
1760
+ :double
1761
+
1762
+ attach_function :ffi_mqtt_client_rust_future_poll_rust_buffer,
1763
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1764
+ :void
1765
+
1766
+ attach_function :ffi_mqtt_client_rust_future_cancel_rust_buffer,
1767
+ [:uint64, ],
1768
+ :void
1769
+
1770
+ attach_function :ffi_mqtt_client_rust_future_free_rust_buffer,
1771
+ [:uint64, ],
1772
+ :void
1773
+
1774
+ attach_function :ffi_mqtt_client_rust_future_complete_rust_buffer,
1775
+ [:uint64, RustCallStatus.by_ref],
1776
+ RustBuffer.by_value
1777
+
1778
+ attach_function :ffi_mqtt_client_rust_future_poll_void,
1779
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1780
+ :void
1781
+
1782
+ attach_function :ffi_mqtt_client_rust_future_cancel_void,
1783
+ [:uint64, ],
1784
+ :void
1785
+
1786
+ attach_function :ffi_mqtt_client_rust_future_free_void,
1787
+ [:uint64, ],
1788
+ :void
1789
+
1790
+ attach_function :ffi_mqtt_client_rust_future_complete_void,
1791
+ [:uint64, RustCallStatus.by_ref],
1792
+ :void
1793
+
1794
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_connect,
1795
+ [],
1796
+ :uint16
1797
+
1798
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_disconnect,
1799
+ [],
1800
+ :uint16
1801
+
1802
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_enable_message_queue,
1803
+ [],
1804
+ :uint16
1805
+
1806
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_is_connected,
1807
+ [],
1808
+ :uint16
1809
+
1810
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_last_disconnect_reason,
1811
+ [],
1812
+ :uint16
1813
+
1814
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_next_message,
1815
+ [],
1816
+ :uint16
1817
+
1818
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_publish,
1819
+ [],
1820
+ :uint16
1821
+
1822
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_set_auth_handler,
1823
+ [],
1824
+ :uint16
1825
+
1826
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_set_message_listener,
1827
+ [],
1828
+ :uint16
1829
+
1830
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_subscribe,
1831
+ [],
1832
+ :uint16
1833
+
1834
+ attach_function :uniffi_mqtt_client_checksum_method_mqttclient_unsubscribe,
1835
+ [],
1836
+ :uint16
1837
+
1838
+ attach_function :uniffi_mqtt_client_checksum_method_mqttauthhandler_respond,
1839
+ [],
1840
+ :uint16
1841
+
1842
+ attach_function :uniffi_mqtt_client_checksum_method_mqttmessagelistener_on_message,
1843
+ [],
1844
+ :uint16
1845
+
1846
+ attach_function :uniffi_mqtt_client_checksum_method_mqttmessagelistener_on_disconnected,
1847
+ [],
1848
+ :uint16
1849
+
1850
+ attach_function :uniffi_mqtt_client_checksum_constructor_mqttclient_new,
1851
+ [],
1852
+ :uint16
1853
+
1854
+ attach_function :ffi_mqtt_client_uniffi_contract_version,
1855
+ [],
1856
+ :uint32
1857
+
1858
+ end
1859
+ # RustFuture poll codes
1860
+ UNIFFI_RUST_FUTURE_POLL_READY = 0
1861
+ UNIFFI_RUST_FUTURE_POLL_WAKE = 1
1862
+
1863
+ # Handle map for storing write-end IO objects used by the continuation callbacks.
1864
+ UNIFFI_ASYNC_HANDLE_MAP = UniffiHandleMap.new
1865
+
1866
+ # Continuation callback for async functions.
1867
+ # Called by Rust when the future is ready to make progress.
1868
+ # Writes the poll code to the pipe so the waiting thread/fiber can continue.
1869
+ #
1870
+ # Exceptions must never escape this Proc.
1871
+ # Rust invokes it directly via FFI, so any unhandled Ruby exception would be caught
1872
+ # by Ruby-FFI, which swallows it (prints a warning) and returns a garbage value to Rust.
1873
+ # The poll code Rust receives would be invalid, causing the Ruby polling loop to
1874
+ # never see POLL_READY and block forever.
1875
+ UNIFFI_CONTINUATION_CALLBACK = Proc.new do |data, poll_code|
1876
+ begin
1877
+ wr = UNIFFI_ASYNC_HANDLE_MAP.get data
1878
+
1879
+ # This can only be blocking if pipe if full. Rust will never try to call continuation
1880
+ # callback more than once (so will not fill it up), hence this call should never block.
1881
+ wr.putc poll_code
1882
+ rescue Exception
1883
+ # Swallow exception. A leak or a hang is better than a hard VM segfault.
1884
+ end
1885
+ end
1886
+
1887
+ # Poll a Rust future to completion.
1888
+ #
1889
+ # This works both with and without a Fiber::Scheduler:
1890
+ # - Without scheduler: wait_readable blocks with a timeout, releasing the GVL
1891
+ # so the callback can fire from foreign threads (works around MRI limitation
1892
+ # where rb_thread_call_with_gvl cannot wake up threads in indefinite sleep).
1893
+ # - With scheduler: wait_readable hooks into io_wait, yielding the fiber.
1894
+ #
1895
+ # cancel_fn is called in the ensure block when exception interrupts an in-flight poll.
1896
+ # This guarantees Rust fires the continuation callback so the handle-map entry is released
1897
+ # and the pipe is drained before we free the future.
1898
+ def self.uniffi_rust_call_async(rust_future, poll_fn, cancel_fn, complete_fn, free_fn, lift_func, error_ffi_converter)
1899
+ rd = wr = nil
1900
+ handle = nil
1901
+ poll_in_flight = false
1902
+
1903
+ begin
1904
+ rd, wr = IO.pipe
1905
+ wr.sync = true # avoid buffering and delayed read for rd.wait_readable
1906
+ handle = UNIFFI_ASYNC_HANDLE_MAP.insert wr
1907
+
1908
+ loop do
1909
+ poll_in_flight = true
1910
+ UniFFILib.public_send(poll_fn, rust_future, UNIFFI_CONTINUATION_CALLBACK, handle)
1911
+
1912
+ # Blocks until the continuation callback writes to the pipe.
1913
+ # Releases the GVL so the callback can fire from foreign threads.
1914
+ # With a Fiber::Scheduler, this hooks into io_wait for non-blocking concurrency.
1915
+ rd.wait_readable
1916
+ poll_code = rd.getbyte
1917
+ poll_in_flight = false
1918
+
1919
+ break if poll_code == UNIFFI_RUST_FUTURE_POLL_READY
1920
+ end
1921
+
1922
+ result = if error_ffi_converter.nil?
1923
+ ::MqttClient.rust_call(complete_fn, rust_future)
1924
+ else
1925
+ ::MqttClient.rust_call_with_error(error_ffi_converter, complete_fn, rust_future)
1926
+ end
1927
+
1928
+ lift_func.call(result)
1929
+ ensure
1930
+ # Defer any further Thread#raise / Timeout during cleanup so all steps execute
1931
+ # automatically. Without this, a second raise during wait_readable(0.5) would skip
1932
+ # handle-map removal, pipe close, and free_fn - leaking FDs and Rust memory.
1933
+ Thread.handle_interrupt(Exception => :never) do
1934
+ if poll_in_flight
1935
+ # An exception interrupted an in-flight poll. Cancel and drain the byte
1936
+ # the continuation callback will write so we don't leak the pipe.
1937
+ UniFFILib.public_send(cancel_fn, rust_future)
1938
+ # rd.wait_readable may time out and return nil if the poll was never actually sent
1939
+ # (raise landed between poll_in_flight=true and the FFI call).
1940
+ if rd.wait_readable(0.5)
1941
+ rd.getbyte
1942
+ end
1943
+ end
1944
+
1945
+ # Remove handle first so any late-firing callback's `get` raises (swallowed by rescue).
1946
+ UNIFFI_ASYNC_HANDLE_MAP.remove(handle) rescue nil if handle
1947
+ rd&.close rescue nil
1948
+ wr&.close rescue nil
1949
+ UniFFILib.public_send(free_fn, rust_future)
1950
+ end
1951
+ end
1952
+ end
1953
+ # Base class for callback interface FfiConverters.
1954
+ # Stores Ruby callback objects in a handle map, and converts to/from integer handles.
1955
+
1956
+ class CallbackInterfaceFfiConverter
1957
+ attr_reader :handle_map
1958
+
1959
+ def initialize
1960
+ @handle_map = UniffiHandleMap.new
1961
+ end
1962
+
1963
+ def lift(handle)
1964
+ @handle_map.get handle
1965
+ end
1966
+
1967
+ def lower(cb)
1968
+ @handle_map.insert cb
1969
+ end
1970
+ end
1971
+
1972
+ private_constant :CallbackInterfaceFfiConverter
1973
+
1974
+ # Custom type definitions.
1975
+
1976
+ # Public interface members begin here.
1977
+
1978
+
1979
+
1980
+
1981
+
1982
+
1983
+ class MqttVersion
1984
+ V311 = 0
1985
+ V5 = 1
1986
+
1987
+ end
1988
+
1989
+
1990
+
1991
+
1992
+
1993
+
1994
+ class QoS
1995
+ AT_MOST_ONCE = 0
1996
+ AT_LEAST_ONCE = 1
1997
+ EXACTLY_ONCE = 2
1998
+
1999
+ end
2000
+
2001
+
2002
+
2003
+ # Record type ConnectOptions
2004
+ class ConnectOptions
2005
+ attr_reader :host, :port, :client_id, :version, :clean_start, :keep_alive_secs, :username, :password, :will, :connect_timeout_secs, :operation_timeout_secs, :auto_reconnect, :reconnect_backoff_secs, :reconnect_max_backoff_secs, :tls, :max_packet_size, :auth_method, :auth_data
2006
+
2007
+ def initialize(host:, port:, client_id:, version:, clean_start:, keep_alive_secs:, username:, password:, will:, connect_timeout_secs:, operation_timeout_secs:, auto_reconnect:, reconnect_backoff_secs:, reconnect_max_backoff_secs:, tls:, max_packet_size: 0, auth_method: nil, auth_data: nil)
2008
+ @host = host
2009
+ @port = port
2010
+ @client_id = client_id
2011
+ @version = version
2012
+ @clean_start = clean_start
2013
+ @keep_alive_secs = keep_alive_secs
2014
+ @username = username
2015
+ @password = password
2016
+ @will = will
2017
+ @connect_timeout_secs = connect_timeout_secs
2018
+ @operation_timeout_secs = operation_timeout_secs
2019
+ @auto_reconnect = auto_reconnect
2020
+ @reconnect_backoff_secs = reconnect_backoff_secs
2021
+ @reconnect_max_backoff_secs = reconnect_max_backoff_secs
2022
+ @tls = tls
2023
+ @max_packet_size = max_packet_size
2024
+ @auth_method = auth_method
2025
+ @auth_data = auth_data
2026
+ end
2027
+
2028
+ def ==(other)
2029
+ if @host != other.host
2030
+ return false
2031
+ end
2032
+ if @port != other.port
2033
+ return false
2034
+ end
2035
+ if @client_id != other.client_id
2036
+ return false
2037
+ end
2038
+ if @version != other.version
2039
+ return false
2040
+ end
2041
+ if @clean_start != other.clean_start
2042
+ return false
2043
+ end
2044
+ if @keep_alive_secs != other.keep_alive_secs
2045
+ return false
2046
+ end
2047
+ if @username != other.username
2048
+ return false
2049
+ end
2050
+ if @password != other.password
2051
+ return false
2052
+ end
2053
+ if @will != other.will
2054
+ return false
2055
+ end
2056
+ if @connect_timeout_secs != other.connect_timeout_secs
2057
+ return false
2058
+ end
2059
+ if @operation_timeout_secs != other.operation_timeout_secs
2060
+ return false
2061
+ end
2062
+ if @auto_reconnect != other.auto_reconnect
2063
+ return false
2064
+ end
2065
+ if @reconnect_backoff_secs != other.reconnect_backoff_secs
2066
+ return false
2067
+ end
2068
+ if @reconnect_max_backoff_secs != other.reconnect_max_backoff_secs
2069
+ return false
2070
+ end
2071
+ if @tls != other.tls
2072
+ return false
2073
+ end
2074
+ if @max_packet_size != other.max_packet_size
2075
+ return false
2076
+ end
2077
+ if @auth_method != other.auth_method
2078
+ return false
2079
+ end
2080
+ if @auth_data != other.auth_data
2081
+ return false
2082
+ end
2083
+
2084
+ true
2085
+ end
2086
+
2087
+ end
2088
+
2089
+ # Record type ConnectResult
2090
+ class ConnectResult
2091
+ attr_reader :session_present, :reason_code
2092
+
2093
+ def initialize(session_present:, reason_code:)
2094
+ @session_present = session_present
2095
+ @reason_code = reason_code
2096
+ end
2097
+
2098
+ def ==(other)
2099
+ if @session_present != other.session_present
2100
+ return false
2101
+ end
2102
+ if @reason_code != other.reason_code
2103
+ return false
2104
+ end
2105
+
2106
+ true
2107
+ end
2108
+
2109
+ end
2110
+
2111
+ # Record type MqttMessage
2112
+ class MqttMessage
2113
+ attr_reader :topic, :payload, :qos, :retain
2114
+
2115
+ def initialize(topic:, payload:, qos:, retain:)
2116
+ @topic = topic
2117
+ @payload = payload
2118
+ @qos = qos
2119
+ @retain = retain
2120
+ end
2121
+
2122
+ def ==(other)
2123
+ if @topic != other.topic
2124
+ return false
2125
+ end
2126
+ if @payload != other.payload
2127
+ return false
2128
+ end
2129
+ if @qos != other.qos
2130
+ return false
2131
+ end
2132
+ if @retain != other.retain
2133
+ return false
2134
+ end
2135
+
2136
+ true
2137
+ end
2138
+
2139
+ end
2140
+
2141
+ # Record type SubscribeResult
2142
+ class SubscribeResult
2143
+ attr_reader :reason_code
2144
+
2145
+ def initialize(reason_code:)
2146
+ @reason_code = reason_code
2147
+ end
2148
+
2149
+ def ==(other)
2150
+ if @reason_code != other.reason_code
2151
+ return false
2152
+ end
2153
+
2154
+ true
2155
+ end
2156
+
2157
+ end
2158
+
2159
+ # Record type TlsOptions
2160
+ class TlsOptions
2161
+ attr_reader :ca_cert_pem, :client_cert_pem, :client_key_pem, :insecure_skip_certificate_verification
2162
+
2163
+ def initialize(ca_cert_pem:, client_cert_pem:, client_key_pem:, insecure_skip_certificate_verification:)
2164
+ @ca_cert_pem = ca_cert_pem
2165
+ @client_cert_pem = client_cert_pem
2166
+ @client_key_pem = client_key_pem
2167
+ @insecure_skip_certificate_verification = insecure_skip_certificate_verification
2168
+ end
2169
+
2170
+ def ==(other)
2171
+ if @ca_cert_pem != other.ca_cert_pem
2172
+ return false
2173
+ end
2174
+ if @client_cert_pem != other.client_cert_pem
2175
+ return false
2176
+ end
2177
+ if @client_key_pem != other.client_key_pem
2178
+ return false
2179
+ end
2180
+ if @insecure_skip_certificate_verification != other.insecure_skip_certificate_verification
2181
+ return false
2182
+ end
2183
+
2184
+ true
2185
+ end
2186
+
2187
+ end
2188
+
2189
+ # Record type WillOptions
2190
+ class WillOptions
2191
+ attr_reader :topic, :payload, :qos, :retain
2192
+
2193
+ def initialize(topic:, payload:, qos:, retain:)
2194
+ @topic = topic
2195
+ @payload = payload
2196
+ @qos = qos
2197
+ @retain = retain
2198
+ end
2199
+
2200
+ def ==(other)
2201
+ if @topic != other.topic
2202
+ return false
2203
+ end
2204
+ if @payload != other.payload
2205
+ return false
2206
+ end
2207
+ if @qos != other.qos
2208
+ return false
2209
+ end
2210
+ if @retain != other.retain
2211
+ return false
2212
+ end
2213
+
2214
+ true
2215
+ end
2216
+
2217
+ end
2218
+
2219
+
2220
+
2221
+
2222
+
2223
+ class MqttClient
2224
+
2225
+ # A private helper for initializing instances of the class from a raw handle,
2226
+ # bypassing any initialization logic and ensuring they are GC'd properly.
2227
+ def self.uniffi_allocate(handle)
2228
+ inst = allocate
2229
+ inst.instance_variable_set :@handle, handle
2230
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
2231
+ return inst
2232
+ end
2233
+
2234
+ # A private helper for registering an object finalizer.
2235
+ # N.B. it's important that this does not capture a reference
2236
+ # to the actual instance, only its underlying handle.
2237
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
2238
+ Proc.new do |_id|
2239
+ ::MqttClient.rust_call(
2240
+ :uniffi_mqtt_client_fn_free_mqttclient,
2241
+ handle
2242
+ )
2243
+ end
2244
+ end
2245
+ # A private helper for lowering instances into a raw handle.
2246
+ # This does an explicit typecheck, because accidentally lowering a different type of
2247
+ # object in a place where this type is expected, could lead to memory unsafety.
2248
+ def self.uniffi_check_lower(inst)
2249
+ if !inst.is_a? self
2250
+ raise TypeError.new "Expected a MqttClient instance, got #{inst}"
2251
+ end
2252
+ end
2253
+
2254
+ def uniffi_clone_handle()
2255
+ return ::MqttClient.rust_call(
2256
+ :uniffi_mqtt_client_fn_clone_mqttclient,
2257
+ @handle
2258
+ )
2259
+ end
2260
+
2261
+ def self.uniffi_lower(inst)
2262
+ return inst.uniffi_clone_handle()
2263
+ end
2264
+
2265
+ def self.uniffi_lift(handle)
2266
+ uniffi_allocate handle
2267
+ end
2268
+ def initialize(options)
2269
+ options = options
2270
+ RustBuffer.check_lower_TypeConnectOptions(options)
2271
+ handle = ::MqttClient.rust_call(:uniffi_mqtt_client_fn_constructor_mqttclient_new,RustBuffer.alloc_from_TypeConnectOptions(options))
2272
+ @handle = handle
2273
+ ObjectSpace.define_finalizer(self, self.class.uniffi_define_finalizer_by_handle(handle, self.object_id))
2274
+ end
2275
+
2276
+
2277
+
2278
+
2279
+ def connect()
2280
+ ::MqttClient.uniffi_rust_call_async(
2281
+ UniFFILib.uniffi_mqtt_client_fn_method_mqttclient_connect(uniffi_clone_handle(),),
2282
+ :ffi_mqtt_client_rust_future_poll_rust_buffer,
2283
+ :ffi_mqtt_client_rust_future_cancel_rust_buffer,
2284
+ :ffi_mqtt_client_rust_future_complete_rust_buffer,
2285
+ :ffi_mqtt_client_rust_future_free_rust_buffer,
2286
+ Proc.new { |v| v.consume_into_TypeConnectResult },
2287
+ MqttError
2288
+ )
2289
+ end
2290
+
2291
+ def disconnect()
2292
+ ::MqttClient.uniffi_rust_call_async(
2293
+ UniFFILib.uniffi_mqtt_client_fn_method_mqttclient_disconnect(uniffi_clone_handle(),),
2294
+ :ffi_mqtt_client_rust_future_poll_void,
2295
+ :ffi_mqtt_client_rust_future_cancel_void,
2296
+ :ffi_mqtt_client_rust_future_complete_void,
2297
+ :ffi_mqtt_client_rust_future_free_void,
2298
+ Proc.new { |v| nil },
2299
+ MqttError
2300
+ )
2301
+ end
2302
+ def enable_message_queue(capacity)
2303
+ capacity = ::MqttClient::uniffi_in_range(capacity, "u32", 0, 2**32)
2304
+
2305
+ ::MqttClient.rust_call(:uniffi_mqtt_client_fn_method_mqttclient_enable_message_queue,uniffi_clone_handle(),capacity)
2306
+ end
2307
+
2308
+ def is_connected()
2309
+ result = ::MqttClient.rust_call(:uniffi_mqtt_client_fn_method_mqttclient_is_connected,uniffi_clone_handle(),)
2310
+ return 1 == result
2311
+ end
2312
+ def last_disconnect_reason()
2313
+ result = ::MqttClient.rust_call(:uniffi_mqtt_client_fn_method_mqttclient_last_disconnect_reason,uniffi_clone_handle(),)
2314
+ return result.consume_into_Optionalstring
2315
+ end
2316
+
2317
+ def next_message(timeout_ms)
2318
+ timeout_ms = ::MqttClient::uniffi_in_range(timeout_ms, "u32", 0, 2**32)
2319
+
2320
+ ::MqttClient.uniffi_rust_call_async(
2321
+ UniFFILib.uniffi_mqtt_client_fn_method_mqttclient_next_message(uniffi_clone_handle(),timeout_ms),
2322
+ :ffi_mqtt_client_rust_future_poll_rust_buffer,
2323
+ :ffi_mqtt_client_rust_future_cancel_rust_buffer,
2324
+ :ffi_mqtt_client_rust_future_complete_rust_buffer,
2325
+ :ffi_mqtt_client_rust_future_free_rust_buffer,
2326
+ Proc.new { |v| v.consume_into_OptionalTypeMqttMessage },
2327
+ nil
2328
+ )
2329
+ end
2330
+
2331
+ def publish(topic, payload, qos, retain)
2332
+ topic = ::MqttClient::uniffi_utf8(topic)
2333
+
2334
+ payload = ::MqttClient::uniffi_bytes(payload)
2335
+
2336
+ qos = qos
2337
+ RustBuffer.check_lower_TypeQoS(qos)
2338
+ retain = retain ? true : false
2339
+
2340
+ ::MqttClient.uniffi_rust_call_async(
2341
+ UniFFILib.uniffi_mqtt_client_fn_method_mqttclient_publish(uniffi_clone_handle(),RustBuffer.alloc_from_string(topic),RustBuffer.alloc_from_bytes(payload),RustBuffer.alloc_from_TypeQoS(qos),(retain ? 1 : 0)),
2342
+ :ffi_mqtt_client_rust_future_poll_void,
2343
+ :ffi_mqtt_client_rust_future_cancel_void,
2344
+ :ffi_mqtt_client_rust_future_complete_void,
2345
+ :ffi_mqtt_client_rust_future_free_void,
2346
+ Proc.new { |v| nil },
2347
+ MqttError
2348
+ )
2349
+ end
2350
+ def set_auth_handler(handler)
2351
+ handler = handler
2352
+ (MqttAuthHandler.uniffi_check_lower handler)
2353
+ ::MqttClient.rust_call(:uniffi_mqtt_client_fn_method_mqttclient_set_auth_handler,uniffi_clone_handle(),(MqttAuthHandler.uniffi_lower handler))
2354
+ end
2355
+
2356
+ def set_message_listener(listener)
2357
+ listener = listener
2358
+ (MqttMessageListener.uniffi_check_lower listener)
2359
+ ::MqttClient.rust_call(:uniffi_mqtt_client_fn_method_mqttclient_set_message_listener,uniffi_clone_handle(),(MqttMessageListener.uniffi_lower listener))
2360
+ end
2361
+
2362
+
2363
+ def subscribe(topic_filter, qos)
2364
+ topic_filter = ::MqttClient::uniffi_utf8(topic_filter)
2365
+
2366
+ qos = qos
2367
+ RustBuffer.check_lower_TypeQoS(qos)
2368
+ ::MqttClient.uniffi_rust_call_async(
2369
+ UniFFILib.uniffi_mqtt_client_fn_method_mqttclient_subscribe(uniffi_clone_handle(),RustBuffer.alloc_from_string(topic_filter),RustBuffer.alloc_from_TypeQoS(qos)),
2370
+ :ffi_mqtt_client_rust_future_poll_rust_buffer,
2371
+ :ffi_mqtt_client_rust_future_cancel_rust_buffer,
2372
+ :ffi_mqtt_client_rust_future_complete_rust_buffer,
2373
+ :ffi_mqtt_client_rust_future_free_rust_buffer,
2374
+ Proc.new { |v| v.consume_into_TypeSubscribeResult },
2375
+ MqttError
2376
+ )
2377
+ end
2378
+
2379
+ def unsubscribe(topic_filter)
2380
+ topic_filter = ::MqttClient::uniffi_utf8(topic_filter)
2381
+
2382
+ ::MqttClient.uniffi_rust_call_async(
2383
+ UniFFILib.uniffi_mqtt_client_fn_method_mqttclient_unsubscribe(uniffi_clone_handle(),RustBuffer.alloc_from_string(topic_filter)),
2384
+ :ffi_mqtt_client_rust_future_poll_void,
2385
+ :ffi_mqtt_client_rust_future_cancel_void,
2386
+ :ffi_mqtt_client_rust_future_complete_void,
2387
+ :ffi_mqtt_client_rust_future_free_void,
2388
+ Proc.new { |v| nil },
2389
+ MqttError
2390
+ )
2391
+ end
2392
+
2393
+ end
2394
+
2395
+ class MqttAuthHandler
2396
+
2397
+ # A private helper for initializing instances of the class from a raw handle,
2398
+ # bypassing any initialization logic and ensuring they are GC'd properly.
2399
+ def self.uniffi_allocate(handle)
2400
+ inst = allocate
2401
+ inst.instance_variable_set :@handle, handle
2402
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
2403
+ return inst
2404
+ end
2405
+
2406
+ # A private helper for registering an object finalizer.
2407
+ # N.B. it's important that this does not capture a reference
2408
+ # to the actual instance, only its underlying handle.
2409
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
2410
+ Proc.new do |_id|
2411
+ ::MqttClient.rust_call(
2412
+ :uniffi_mqtt_client_fn_free_mqttauthhandler,
2413
+ handle
2414
+ )
2415
+ end
2416
+ end
2417
+ # HandleMap for trait interface: stores Ruby-native objects keyed by odd handles.
2418
+ @uniffi_handle_map = UniffiHandleMap.new
2419
+
2420
+ class << self
2421
+ attr_reader :uniffi_handle_map
2422
+ end
2423
+
2424
+ # For trait interfaces: check that the object is either a Rust-backed instance or
2425
+ # responds to the required interface methods.
2426
+ def self.uniffi_check_lower(inst)
2427
+ if !inst.respond_to?(:respond)
2428
+ raise TypeError.new "Expected a MqttAuthHandler instance or an object implementing the interface, got #{inst}"
2429
+ end
2430
+ end
2431
+
2432
+ def uniffi_clone_handle
2433
+ return ::MqttClient.rust_call(
2434
+ :uniffi_mqtt_client_fn_clone_mqttauthhandler,
2435
+ @handle
2436
+ )
2437
+ end
2438
+
2439
+ # For trait interfaces: lowering distinguishes between Rust-backed and Ruby-native instances.
2440
+ def self.uniffi_lower(inst)
2441
+ if inst.is_a?(self) && inst.instance_variable_defined?(:@handle)
2442
+ inst.uniffi_clone_handle()
2443
+ else
2444
+ @uniffi_handle_map.insert(inst)
2445
+ end
2446
+ end
2447
+
2448
+ # For trait interfaces: lifting distinguishes even handles (Rust) from odd handles (Ruby).
2449
+ def self.uniffi_lift(handle)
2450
+ if (handle & 1) == 0
2451
+ uniffi_allocate handle
2452
+ else
2453
+ @uniffi_handle_map.remove handle
2454
+ end
2455
+ end
2456
+
2457
+
2458
+
2459
+ def respond(method, challenge)
2460
+ method = ::MqttClient::uniffi_utf8(method)
2461
+
2462
+ challenge = ::MqttClient::uniffi_bytes(challenge)
2463
+
2464
+ result = ::MqttClient.rust_call(:uniffi_mqtt_client_fn_method_mqttauthhandler_respond,uniffi_clone_handle(),RustBuffer.alloc_from_string(method),RustBuffer.alloc_from_bytes(challenge))
2465
+ return result.consume_into_Optionalbytes
2466
+ end
2467
+
2468
+ end
2469
+
2470
+
2471
+ # Trait interface vtable implementation for MqttAuthHandler.
2472
+ module UniffiCallbackInterfaceMqttAuthHandler
2473
+ # Callback method for respond
2474
+ RESPOND_CALLBACK = Proc.new do |uniffi_handle, method, challenge, uniffi_out_return, uniffi_call_status|
2475
+ uniffi_obj = MqttAuthHandler.uniffi_handle_map.get(uniffi_handle)
2476
+ make_call = Proc.new do
2477
+ uniffi_obj.respond(
2478
+ method.consume_into_string,
2479
+ challenge.consume_into_bytes
2480
+ )
2481
+ end
2482
+ write_return_value = Proc.new do |v|
2483
+ lowered = RustBuffer.alloc_from_Optionalbytes(v)
2484
+ # Write a RustBuffer struct into the out pointer
2485
+ out_buf = RustBuffer.new uniffi_out_return
2486
+ out_buf[:capacity] = lowered[:capacity]
2487
+ out_buf[:len] = lowered[:len]
2488
+ out_buf[:data] = lowered[:data]
2489
+ end
2490
+ ::MqttClient.uniffi_trait_interface_call(
2491
+ uniffi_call_status,
2492
+ make_call,
2493
+ write_return_value,
2494
+ )
2495
+ end
2496
+
2497
+ # Free callback: removes the handle from the map.
2498
+ UNIFFI_FREE_CALLBACK = Proc.new do |uniffi_handle|
2499
+ MqttAuthHandler.uniffi_handle_map.remove uniffi_handle
2500
+ end
2501
+
2502
+ # Clone callback: clones the handle in the map.
2503
+ UNIFFI_CLONE_CALLBACK = Proc.new do |uniffi_handle|
2504
+ MqttAuthHandler.uniffi_handle_map.clone_handle(uniffi_handle)
2505
+ end
2506
+
2507
+ # Create the VTable struct instance.
2508
+ UNIFFI_VTABLE = UniFFILib::VTableCallbackInterfaceMqttAuthHandler.new
2509
+ UNIFFI_VTABLE[:uniffi_free] = UNIFFI_FREE_CALLBACK
2510
+ UNIFFI_VTABLE[:uniffi_clone] = UNIFFI_CLONE_CALLBACK
2511
+ UNIFFI_VTABLE[:respond] = RESPOND_CALLBACK
2512
+
2513
+ # Register the VTable with Rust.
2514
+ UniFFILib.uniffi_mqtt_client_fn_init_callback_vtable_mqttauthhandler(UNIFFI_VTABLE)
2515
+ end
2516
+
2517
+ class MqttMessageListener
2518
+
2519
+ # A private helper for initializing instances of the class from a raw handle,
2520
+ # bypassing any initialization logic and ensuring they are GC'd properly.
2521
+ def self.uniffi_allocate(handle)
2522
+ inst = allocate
2523
+ inst.instance_variable_set :@handle, handle
2524
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
2525
+ return inst
2526
+ end
2527
+
2528
+ # A private helper for registering an object finalizer.
2529
+ # N.B. it's important that this does not capture a reference
2530
+ # to the actual instance, only its underlying handle.
2531
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
2532
+ Proc.new do |_id|
2533
+ ::MqttClient.rust_call(
2534
+ :uniffi_mqtt_client_fn_free_mqttmessagelistener,
2535
+ handle
2536
+ )
2537
+ end
2538
+ end
2539
+ # HandleMap for trait interface: stores Ruby-native objects keyed by odd handles.
2540
+ @uniffi_handle_map = UniffiHandleMap.new
2541
+
2542
+ class << self
2543
+ attr_reader :uniffi_handle_map
2544
+ end
2545
+
2546
+ # For trait interfaces: check that the object is either a Rust-backed instance or
2547
+ # responds to the required interface methods.
2548
+ def self.uniffi_check_lower(inst)
2549
+ if !inst.respond_to?(:on_message)
2550
+ raise TypeError.new "Expected a MqttMessageListener instance or an object implementing the interface, got #{inst}"
2551
+ end
2552
+ if !inst.respond_to?(:on_disconnected)
2553
+ raise TypeError.new "Expected a MqttMessageListener instance or an object implementing the interface, got #{inst}"
2554
+ end
2555
+ end
2556
+
2557
+ def uniffi_clone_handle
2558
+ return ::MqttClient.rust_call(
2559
+ :uniffi_mqtt_client_fn_clone_mqttmessagelistener,
2560
+ @handle
2561
+ )
2562
+ end
2563
+
2564
+ # For trait interfaces: lowering distinguishes between Rust-backed and Ruby-native instances.
2565
+ def self.uniffi_lower(inst)
2566
+ if inst.is_a?(self) && inst.instance_variable_defined?(:@handle)
2567
+ inst.uniffi_clone_handle()
2568
+ else
2569
+ @uniffi_handle_map.insert(inst)
2570
+ end
2571
+ end
2572
+
2573
+ # For trait interfaces: lifting distinguishes even handles (Rust) from odd handles (Ruby).
2574
+ def self.uniffi_lift(handle)
2575
+ if (handle & 1) == 0
2576
+ uniffi_allocate handle
2577
+ else
2578
+ @uniffi_handle_map.remove handle
2579
+ end
2580
+ end
2581
+
2582
+
2583
+
2584
+ def on_message(message)
2585
+ message = message
2586
+ RustBuffer.check_lower_TypeMqttMessage(message)
2587
+ ::MqttClient.rust_call(:uniffi_mqtt_client_fn_method_mqttmessagelistener_on_message,uniffi_clone_handle(),RustBuffer.alloc_from_TypeMqttMessage(message))
2588
+ end
2589
+
2590
+ def on_disconnected(reason)
2591
+ reason = ::MqttClient::uniffi_utf8(reason)
2592
+
2593
+ ::MqttClient.rust_call(:uniffi_mqtt_client_fn_method_mqttmessagelistener_on_disconnected,uniffi_clone_handle(),RustBuffer.alloc_from_string(reason))
2594
+ end
2595
+
2596
+
2597
+ end
2598
+
2599
+
2600
+ # Trait interface vtable implementation for MqttMessageListener.
2601
+ module UniffiCallbackInterfaceMqttMessageListener
2602
+ # Callback method for on_message
2603
+ ON_MESSAGE_CALLBACK = Proc.new do |uniffi_handle, message, uniffi_out_return, uniffi_call_status|
2604
+ uniffi_obj = MqttMessageListener.uniffi_handle_map.get(uniffi_handle)
2605
+ make_call = Proc.new do
2606
+ uniffi_obj.on_message(
2607
+ message.consume_into_TypeMqttMessage
2608
+ )
2609
+ end
2610
+ # No return value, so do nothing
2611
+ write_return_value = Proc.new { |_v| }
2612
+ ::MqttClient.uniffi_trait_interface_call(
2613
+ uniffi_call_status,
2614
+ make_call,
2615
+ write_return_value,
2616
+ )
2617
+ end
2618
+ # Callback method for on_disconnected
2619
+ ON_DISCONNECTED_CALLBACK = Proc.new do |uniffi_handle, reason, uniffi_out_return, uniffi_call_status|
2620
+ uniffi_obj = MqttMessageListener.uniffi_handle_map.get(uniffi_handle)
2621
+ make_call = Proc.new do
2622
+ uniffi_obj.on_disconnected(
2623
+ reason.consume_into_string
2624
+ )
2625
+ end
2626
+ # No return value, so do nothing
2627
+ write_return_value = Proc.new { |_v| }
2628
+ ::MqttClient.uniffi_trait_interface_call(
2629
+ uniffi_call_status,
2630
+ make_call,
2631
+ write_return_value,
2632
+ )
2633
+ end
2634
+
2635
+ # Free callback: removes the handle from the map.
2636
+ UNIFFI_FREE_CALLBACK = Proc.new do |uniffi_handle|
2637
+ MqttMessageListener.uniffi_handle_map.remove uniffi_handle
2638
+ end
2639
+
2640
+ # Clone callback: clones the handle in the map.
2641
+ UNIFFI_CLONE_CALLBACK = Proc.new do |uniffi_handle|
2642
+ MqttMessageListener.uniffi_handle_map.clone_handle(uniffi_handle)
2643
+ end
2644
+
2645
+ # Create the VTable struct instance.
2646
+ UNIFFI_VTABLE = UniFFILib::VTableCallbackInterfaceMqttMessageListener.new
2647
+ UNIFFI_VTABLE[:uniffi_free] = UNIFFI_FREE_CALLBACK
2648
+ UNIFFI_VTABLE[:uniffi_clone] = UNIFFI_CLONE_CALLBACK
2649
+ UNIFFI_VTABLE[:on_message] = ON_MESSAGE_CALLBACK
2650
+ UNIFFI_VTABLE[:on_disconnected] = ON_DISCONNECTED_CALLBACK
2651
+
2652
+ # Register the VTable with Rust.
2653
+ UniFFILib.uniffi_mqtt_client_fn_init_callback_vtable_mqttmessagelistener(UNIFFI_VTABLE)
2654
+ end
2655
+
2656
+
2657
+
2658
+ end
2659
+