firemq 0.1.0-aarch64-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,2075 @@
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
+
19
+ module FiremqClientFfi
20
+ def self.uniffi_in_range(i, type_name, min, max)
21
+ raise TypeError, "no implicit conversion of #{i} into Integer" unless i.respond_to?(:to_int)
22
+ i = i.to_int
23
+ raise RangeError, "#{type_name} requires #{min} <= value < #{max}" unless (min <= i && i < max)
24
+ i
25
+ end
26
+
27
+ def self.uniffi_utf8(v)
28
+ raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
29
+ v = v.to_str.encode(Encoding::UTF_8)
30
+ raise Encoding::InvalidByteSequenceError, "not a valid UTF-8 encoded string" unless v.valid_encoding?
31
+ v
32
+ end
33
+
34
+ def self.uniffi_bytes(v)
35
+ raise TypeError, "no implicit conversion of #{v} into String" unless v.respond_to?(:to_str)
36
+ v.to_str
37
+ end
38
+
39
+ # Callback return codes
40
+ UNIFFI_CALLBACK_SUCCESS = 0
41
+ UNIFFI_CALLBACK_ERROR = 1
42
+ UNIFFI_CALLBACK_UNEXPECTED_ERROR = 2
43
+
44
+ # Call a method on a callback interface object, catching and reporting errors
45
+ # to Rust via the call_status.
46
+ # If error_type is provided, known errors of that type are reported as UNIFFI_CALLBACK_ERROR;
47
+ # all other errors are reported as UNIFFI_CALLBACK_UNEXPECTED_ERROR.
48
+ def self.uniffi_trait_interface_call(call_status, make_call, write_return_value, error_type = nil, lower_error = nil)
49
+ begin
50
+ write_return_value.call make_call.call
51
+ rescue StandardError => e
52
+ buf = if !error_type.nil? && uniffi_is_error_type?(e, error_type)
53
+ call_status[:code] = UNIFFI_CALLBACK_ERROR
54
+ lower_error.call e
55
+ else
56
+ call_status[:code] = UNIFFI_CALLBACK_UNEXPECTED_ERROR
57
+ RustBuffer.alloc_from_string(e.inspect)
58
+ end
59
+
60
+ error_buf = call_status[:error_buf]
61
+ error_buf[:capacity] = buf[:capacity]
62
+ error_buf[:len] = buf[:len]
63
+ error_buf[:data] = buf[:data]
64
+ end
65
+ end
66
+
67
+ # Check if an exception is a variant of the given error type.
68
+ # Error types in Ruby are either modules (non-flat enums) or classes (flat enums),
69
+ # with variant classes as constant within them.
70
+ def self.uniffi_is_error_type?(e, error_type)
71
+ # Object-as-error: error_type is a class itself (e.g. MyError < StandardError)
72
+ if error_type.is_a?(Class) && e.is_a?(error_type)
73
+ return true
74
+ end
75
+
76
+ # Enum error: error_type is a module with class constants for each variant
77
+ error_type.constants.any? do |c|
78
+ klass = error_type.const_get c
79
+ klass.is_a?(Class) && e.is_a?(klass)
80
+ end
81
+ end
82
+ class RustBuffer < FFI::Struct
83
+ layout :capacity, :uint64,
84
+ :len, :uint64,
85
+ :data, :pointer
86
+
87
+ def self.alloc(size)
88
+ return ::FiremqClientFfi.rust_call(:ffi_firemq_client_ffi_rustbuffer_alloc, size)
89
+ end
90
+
91
+ def self.reserve(rbuf, additional)
92
+ return ::FiremqClientFfi.rust_call(:ffi_firemq_client_ffi_rustbuffer_reserve, rbuf, additional)
93
+ end
94
+
95
+ def free
96
+ ::FiremqClientFfi.rust_call(:ffi_firemq_client_ffi_rustbuffer_free, self)
97
+ end
98
+
99
+ def capacity
100
+ self[:capacity]
101
+ end
102
+
103
+ def len
104
+ self[:len]
105
+ end
106
+
107
+ def len=(value)
108
+ self[:len] = value
109
+ end
110
+
111
+ def data
112
+ self[:data]
113
+ end
114
+
115
+ def to_s
116
+ "RustBuffer(capacity=#{capacity}, len=#{len}, data=#{data.read_bytes len})"
117
+ end
118
+
119
+ # The allocated buffer will be automatically freed if an error occurs, ensuring that
120
+ # we don't accidentally leak it.
121
+ def self.allocWithBuilder
122
+ builder = RustBufferBuilder.new
123
+
124
+ begin
125
+ yield builder
126
+ rescue => e
127
+ builder.discard
128
+ raise e
129
+ end
130
+ end
131
+
132
+ # The RustBuffer will be freed once the context-manager exits, ensuring that we don't
133
+ # leak it even if an error occurs.
134
+ def consumeWithStream
135
+ stream = RustBufferStream.new self
136
+
137
+ yield stream
138
+
139
+ raise RuntimeError, 'junk data left in buffer after consuming' if stream.remaining != 0
140
+ ensure
141
+ free
142
+ end# The primitive String type.
143
+
144
+ def self.alloc_from_string(value)
145
+ RustBuffer.allocWithBuilder do |builder|
146
+ builder.write value.encode('utf-8')
147
+ return builder.finalize
148
+ end
149
+ end
150
+
151
+ def consume_into_string
152
+ consumeWithStream do |stream|
153
+ return stream.read(stream.remaining).force_encoding(Encoding::UTF_8)
154
+ end
155
+ end
156
+
157
+ # The primitive Bytes type.
158
+
159
+ def self.alloc_from_bytes(value)
160
+ RustBuffer.allocWithBuilder do |builder|
161
+ builder.write_bytes(value)
162
+ return builder.finalize
163
+ end
164
+ end
165
+
166
+ def consume_into_bytes
167
+ consumeWithStream do |stream|
168
+ return stream.read_bytes
169
+ end
170
+ end
171
+
172
+ # The Record type MessageProperties.
173
+
174
+ def self.check_lower_TypeMessageProperties(v)
175
+ RustBuffer.check_lower_Optionalstring(v.content_type)
176
+ RustBuffer.check_lower_Optionalstring(v.content_encoding)
177
+ RustBuffer.check_lower_Optionalstring(v.correlation_id)
178
+ RustBuffer.check_lower_Optionalstring(v.reply_to)
179
+ RustBuffer.check_lower_Optionalu64(v.expiration)
180
+ RustBuffer.check_lower_Optionalstring(v.message_id)
181
+ RustBuffer.check_lower_Optionalu64(v.timestamp)
182
+ RustBuffer.check_lower_Optionalstring(v.message_type)
183
+ RustBuffer.check_lower_Optionalstring(v.user_id)
184
+ RustBuffer.check_lower_Optionalstring(v.app_id)
185
+ RustBuffer.check_lower_Optionalu8(v.priority)
186
+ end
187
+
188
+ def self.alloc_from_TypeMessageProperties(v)
189
+ RustBuffer.allocWithBuilder do |builder|
190
+ builder.write_TypeMessageProperties(v)
191
+ return builder.finalize
192
+ end
193
+ end
194
+
195
+ def consume_into_TypeMessageProperties
196
+ consumeWithStream do |stream|
197
+ return stream.read_TypeMessageProperties
198
+ end
199
+ end
200
+
201
+ # The Record type PublishOptions.
202
+
203
+ def self.check_lower_TypePublishOptions(v)
204
+
205
+
206
+
207
+ RustBuffer.check_lower_TypeMessageProperties(v.properties)
208
+ RustBuffer.check_lower_Optionalstring(v.headers_json)
209
+ end
210
+
211
+ def self.alloc_from_TypePublishOptions(v)
212
+ RustBuffer.allocWithBuilder do |builder|
213
+ builder.write_TypePublishOptions(v)
214
+ return builder.finalize
215
+ end
216
+ end
217
+
218
+ def consume_into_TypePublishOptions
219
+ consumeWithStream do |stream|
220
+ return stream.read_TypePublishOptions
221
+ end
222
+ end
223
+
224
+ # The Record type QueueInfo.
225
+
226
+ def self.check_lower_TypeQueueInfo(v)
227
+
228
+
229
+
230
+ end
231
+
232
+ def self.alloc_from_TypeQueueInfo(v)
233
+ RustBuffer.allocWithBuilder do |builder|
234
+ builder.write_TypeQueueInfo(v)
235
+ return builder.finalize
236
+ end
237
+ end
238
+
239
+ def consume_into_TypeQueueInfo
240
+ consumeWithStream do |stream|
241
+ return stream.read_TypeQueueInfo
242
+ end
243
+ end
244
+
245
+ # Error enum - generate alloc_from for callback error serialization
246
+ def self.alloc_from_TypeFireMqError(v)
247
+ RustBuffer.allocWithBuilder do |builder|
248
+ builder.write_TypeFireMqError(v)
249
+ return builder.finalize
250
+ end
251
+ end
252
+
253
+ # Enum used as error - generate consume_into_ for use as a return value
254
+ def consume_into_TypeFireMqError
255
+ consumeWithStream do |stream|
256
+ return stream.read_TypeFireMqError
257
+ end
258
+ end
259
+
260
+
261
+ # The Optional<T> type for u8.
262
+
263
+ def self.check_lower_Optionalu8(v)
264
+ if !v.nil?
265
+
266
+ end
267
+ end
268
+
269
+ def self.alloc_from_Optionalu8(v)
270
+ RustBuffer.allocWithBuilder do |builder|
271
+ builder.write_Optionalu8(v)
272
+ return builder.finalize()
273
+ end
274
+ end
275
+
276
+ def consume_into_Optionalu8
277
+ consumeWithStream do |stream|
278
+ return stream.read_Optionalu8
279
+ end
280
+ end
281
+
282
+ # The Optional<T> type for u64.
283
+
284
+ def self.check_lower_Optionalu64(v)
285
+ if !v.nil?
286
+
287
+ end
288
+ end
289
+
290
+ def self.alloc_from_Optionalu64(v)
291
+ RustBuffer.allocWithBuilder do |builder|
292
+ builder.write_Optionalu64(v)
293
+ return builder.finalize()
294
+ end
295
+ end
296
+
297
+ def consume_into_Optionalu64
298
+ consumeWithStream do |stream|
299
+ return stream.read_Optionalu64
300
+ end
301
+ end
302
+
303
+ # The Optional<T> type for string.
304
+
305
+ def self.check_lower_Optionalstring(v)
306
+ if !v.nil?
307
+
308
+ end
309
+ end
310
+
311
+ def self.alloc_from_Optionalstring(v)
312
+ RustBuffer.allocWithBuilder do |builder|
313
+ builder.write_Optionalstring(v)
314
+ return builder.finalize()
315
+ end
316
+ end
317
+
318
+ def consume_into_Optionalstring
319
+ consumeWithStream do |stream|
320
+ return stream.read_Optionalstring
321
+ end
322
+ end
323
+
324
+ # The Optional<T> type for TypeDelivery.
325
+
326
+ def self.check_lower_OptionalTypeDelivery(v)
327
+ if !v.nil?
328
+ (Delivery.uniffi_check_lower v)
329
+ end
330
+ end
331
+
332
+ def self.alloc_from_OptionalTypeDelivery(v)
333
+ RustBuffer.allocWithBuilder do |builder|
334
+ builder.write_OptionalTypeDelivery(v)
335
+ return builder.finalize()
336
+ end
337
+ end
338
+
339
+ def consume_into_OptionalTypeDelivery
340
+ consumeWithStream do |stream|
341
+ return stream.read_OptionalTypeDelivery
342
+ end
343
+ end
344
+
345
+
346
+ end
347
+
348
+ module UniFFILib
349
+ class ForeignBytes < FFI::Struct
350
+ layout :len, :int32,
351
+ :data, :pointer
352
+
353
+ def len
354
+ self[:len]
355
+ end
356
+
357
+ def data
358
+ self[:data]
359
+ end
360
+
361
+ def to_s
362
+ "ForeignBytes(len=#{len}, data=#{data.read_bytes(len)})"
363
+ end
364
+ end
365
+ end
366
+
367
+ private_constant :UniFFILib
368
+
369
+ # Helper for structured reading of values from a RustBuffer.
370
+ class RustBufferStream
371
+
372
+ def initialize(rbuf)
373
+ @rbuf = rbuf
374
+ @offset = 0
375
+ end
376
+
377
+ def remaining
378
+ @rbuf.len - @offset
379
+ end
380
+
381
+ def read(size)
382
+ raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
383
+
384
+ data = @rbuf.data.get_bytes @offset, size
385
+
386
+ @offset += size
387
+
388
+ data
389
+ end
390
+
391
+ def read_u8
392
+ unpack_from 1, 'c'
393
+ end
394
+
395
+ def read_u16
396
+ unpack_from 2, 'S>'
397
+ end
398
+
399
+ def read_u32
400
+ unpack_from 4, 'L>'
401
+ end
402
+
403
+ def read_u64
404
+ unpack_from 8, 'Q>'
405
+ end
406
+
407
+ def read_bool
408
+ v = unpack_from 1, 'c'
409
+
410
+ return false if v == 0
411
+ return true if v == 1
412
+
413
+ raise InternalError, 'Unexpected byte for Boolean type'
414
+ end
415
+
416
+ def read_string
417
+ size = unpack_from 4, 'l>'
418
+
419
+ raise InternalError, 'Unexpected negative string length' if size.negative?
420
+
421
+ read(size).force_encoding(Encoding::UTF_8)
422
+ end
423
+
424
+ def read_bytes
425
+ size = unpack_from 4, 'l>'
426
+
427
+ raise InternalError, 'Unexpected negative byte string length' if size.negative?
428
+
429
+ read(size).force_encoding(Encoding::BINARY)
430
+ end
431
+
432
+ # The Object type Client.
433
+
434
+ def read_TypeClient
435
+ handle = unpack_from 8, 'Q>'
436
+ return Client.uniffi_lift(handle)
437
+ end
438
+
439
+ # The Object type Delivery.
440
+
441
+ def read_TypeDelivery
442
+ handle = unpack_from 8, 'Q>'
443
+ return Delivery.uniffi_lift(handle)
444
+ end
445
+
446
+ # The Object type Subscription.
447
+
448
+ def read_TypeSubscription
449
+ handle = unpack_from 8, 'Q>'
450
+ return Subscription.uniffi_lift(handle)
451
+ end
452
+
453
+ # The Record type MessageProperties.
454
+
455
+ def read_TypeMessageProperties
456
+ MessageProperties.new(
457
+ content_type: read_Optionalstring,
458
+ content_encoding: read_Optionalstring,
459
+ correlation_id: read_Optionalstring,
460
+ reply_to: read_Optionalstring,
461
+ expiration: read_Optionalu64,
462
+ message_id: read_Optionalstring,
463
+ timestamp: read_Optionalu64,
464
+ message_type: read_Optionalstring,
465
+ user_id: read_Optionalstring,
466
+ app_id: read_Optionalstring,
467
+ priority: read_Optionalu8
468
+ )
469
+ end
470
+
471
+ # The Record type PublishOptions.
472
+
473
+ def read_TypePublishOptions
474
+ PublishOptions.new(
475
+ persistent: read_bool,
476
+ mandatory: read_bool,
477
+ confirm: read_bool,
478
+ properties: read_TypeMessageProperties,
479
+ headers_json: read_Optionalstring
480
+ )
481
+ end
482
+
483
+ # The Record type QueueInfo.
484
+
485
+ def read_TypeQueueInfo
486
+ QueueInfo.new(
487
+ name: read_string,
488
+ messages: read_u64,
489
+ consumers: read_u32
490
+ )
491
+ end
492
+
493
+
494
+
495
+
496
+
497
+ # The Error type FireMqError
498
+
499
+ def read_TypeFireMqError
500
+ variant = unpack_from 4, 'l>'
501
+
502
+ if variant == 1
503
+ return FireMqError::Server.new(
504
+ code: read_u16(),
505
+ message: read_string()
506
+ )
507
+ end
508
+ if variant == 2
509
+ return FireMqError::Unroutable.new(
510
+ message: read_string()
511
+ )
512
+ end
513
+ if variant == 3
514
+ return FireMqError::Nacked.new(
515
+ code: read_u16(),
516
+ message: read_string()
517
+ )
518
+ end
519
+ if variant == 4
520
+ return FireMqError::Closed.new(
521
+ message: read_string()
522
+ )
523
+ end
524
+ if variant == 5
525
+ return FireMqError::Other.new(
526
+ message: read_string()
527
+ )
528
+ end
529
+
530
+ raise InternalError, 'Unexpected variant tag for TypeFireMqError'
531
+ end
532
+
533
+
534
+
535
+ # The Optional<T> type for u8.
536
+
537
+ def read_Optionalu8
538
+ flag = unpack_from 1, 'c'
539
+
540
+ if flag == 0
541
+ return nil
542
+ elsif flag == 1
543
+ return read_u8
544
+ else
545
+ raise InternalError, 'Unexpected flag byte for Optionalu8'
546
+ end
547
+ end
548
+
549
+
550
+ # The Optional<T> type for u64.
551
+
552
+ def read_Optionalu64
553
+ flag = unpack_from 1, 'c'
554
+
555
+ if flag == 0
556
+ return nil
557
+ elsif flag == 1
558
+ return read_u64
559
+ else
560
+ raise InternalError, 'Unexpected flag byte for Optionalu64'
561
+ end
562
+ end
563
+
564
+
565
+ # The Optional<T> type for string.
566
+
567
+ def read_Optionalstring
568
+ flag = unpack_from 1, 'c'
569
+
570
+ if flag == 0
571
+ return nil
572
+ elsif flag == 1
573
+ return read_string
574
+ else
575
+ raise InternalError, 'Unexpected flag byte for Optionalstring'
576
+ end
577
+ end
578
+
579
+
580
+ # The Optional<T> type for TypeDelivery.
581
+
582
+ def read_OptionalTypeDelivery
583
+ flag = unpack_from 1, 'c'
584
+
585
+ if flag == 0
586
+ return nil
587
+ elsif flag == 1
588
+ return read_TypeDelivery
589
+ else
590
+ raise InternalError, 'Unexpected flag byte for OptionalTypeDelivery'
591
+ end
592
+ end
593
+
594
+
595
+
596
+ def unpack_from(size, format)
597
+ raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
598
+
599
+ value = @rbuf.data.get_bytes(@offset, size).unpack format
600
+
601
+ @offset += size
602
+
603
+ # TODO: verify this
604
+ raise 'more than one element!!!' if value.size > 1
605
+
606
+ value[0]
607
+ end
608
+ end
609
+
610
+ private_constant :RustBufferStream
611
+
612
+ # Helper for structured writing of values into a RustBuffer.
613
+ class RustBufferBuilder
614
+ def initialize
615
+ @rust_buf = RustBuffer.alloc 16
616
+ @rust_buf.len = 0
617
+ end
618
+
619
+ def finalize
620
+ rbuf = @rust_buf
621
+
622
+ @rust_buf = nil
623
+
624
+ rbuf
625
+ end
626
+
627
+ def discard
628
+ return if @rust_buf.nil?
629
+
630
+ rbuf = finalize
631
+ rbuf.free
632
+ end
633
+
634
+ def write(value)
635
+ reserve(value.bytes.size) do
636
+ @rust_buf.data.put_array_of_char @rust_buf.len, value.bytes
637
+ end
638
+ end
639
+
640
+ def write_u8(v)
641
+ v = ::FiremqClientFfi::uniffi_in_range(v, "u8", 0, 2**8)
642
+ pack_into(1, 'c', v)
643
+ end
644
+
645
+ def write_u16(v)
646
+ v = ::FiremqClientFfi::uniffi_in_range(v, "u16", 0, 2**16)
647
+ pack_into(2, 'S>', v)
648
+ end
649
+
650
+ def write_u32(v)
651
+ v = ::FiremqClientFfi::uniffi_in_range(v, "u32", 0, 2**32)
652
+ pack_into(4, 'L>', v)
653
+ end
654
+
655
+ def write_u64(v)
656
+ v = ::FiremqClientFfi::uniffi_in_range(v, "u64", 0, 2**64)
657
+ pack_into(8, 'Q>', v)
658
+ end
659
+
660
+ def write_bool(v)
661
+ pack_into(1, 'c', v ? 1 : 0)
662
+ end
663
+
664
+ def write_string(v)
665
+ v = ::FiremqClientFfi::uniffi_utf8(v)
666
+ pack_into 4, 'l>', v.bytes.size
667
+ write v
668
+ end
669
+
670
+ def write_bytes(v)
671
+ v = ::FiremqClientFfi::uniffi_bytes(v)
672
+ pack_into 4, 'l>', v.bytes.size
673
+ write v
674
+ end
675
+
676
+ # The Object type Client.
677
+
678
+ def write_TypeClient(obj)
679
+ handle = Client.uniffi_lower obj
680
+ pack_into(8, 'Q>', handle)
681
+ end
682
+
683
+ # The Object type Delivery.
684
+
685
+ def write_TypeDelivery(obj)
686
+ handle = Delivery.uniffi_lower obj
687
+ pack_into(8, 'Q>', handle)
688
+ end
689
+
690
+ # The Object type Subscription.
691
+
692
+ def write_TypeSubscription(obj)
693
+ handle = Subscription.uniffi_lower obj
694
+ pack_into(8, 'Q>', handle)
695
+ end
696
+
697
+ # The Record type MessageProperties.
698
+
699
+ def write_TypeMessageProperties(v)
700
+ self.write_Optionalstring(v.content_type)
701
+ self.write_Optionalstring(v.content_encoding)
702
+ self.write_Optionalstring(v.correlation_id)
703
+ self.write_Optionalstring(v.reply_to)
704
+ self.write_Optionalu64(v.expiration)
705
+ self.write_Optionalstring(v.message_id)
706
+ self.write_Optionalu64(v.timestamp)
707
+ self.write_Optionalstring(v.message_type)
708
+ self.write_Optionalstring(v.user_id)
709
+ self.write_Optionalstring(v.app_id)
710
+ self.write_Optionalu8(v.priority)
711
+ end
712
+
713
+ # The Record type PublishOptions.
714
+
715
+ def write_TypePublishOptions(v)
716
+ self.write_bool(v.persistent)
717
+ self.write_bool(v.mandatory)
718
+ self.write_bool(v.confirm)
719
+ self.write_TypeMessageProperties(v.properties)
720
+ self.write_Optionalstring(v.headers_json)
721
+ end
722
+
723
+ # The Record type QueueInfo.
724
+
725
+ def write_TypeQueueInfo(v)
726
+ self.write_string(v.name)
727
+ self.write_u64(v.messages)
728
+ self.write_u32(v.consumers)
729
+ end
730
+
731
+ # The Error type FireMqError - write for callback error returns.
732
+
733
+ def write_TypeFireMqError(v)
734
+ if v.is_a?(FireMqError::Server)
735
+ pack_into 4, 'l>', 1
736
+ self.write_u16(v.code)
737
+ self.write_string(v.message)
738
+ return
739
+ end
740
+ if v.is_a?(FireMqError::Unroutable)
741
+ pack_into 4, 'l>', 2
742
+ self.write_string(v.message)
743
+ return
744
+ end
745
+ if v.is_a?(FireMqError::Nacked)
746
+ pack_into 4, 'l>', 3
747
+ self.write_u16(v.code)
748
+ self.write_string(v.message)
749
+ return
750
+ end
751
+ if v.is_a?(FireMqError::Closed)
752
+ pack_into 4, 'l>', 4
753
+ self.write_string(v.message)
754
+ return
755
+ end
756
+ if v.is_a?(FireMqError::Other)
757
+ pack_into 4, 'l>', 5
758
+ self.write_string(v.message)
759
+ return
760
+ end
761
+ end
762
+
763
+
764
+ # The Optional<T> type for u8.
765
+
766
+ def write_Optionalu8(v)
767
+ if v.nil?
768
+ pack_into(1, 'c', 0)
769
+ else
770
+ pack_into(1, 'c', 1)
771
+ self.write_u8(v)
772
+ end
773
+ end
774
+
775
+ # The Optional<T> type for u64.
776
+
777
+ def write_Optionalu64(v)
778
+ if v.nil?
779
+ pack_into(1, 'c', 0)
780
+ else
781
+ pack_into(1, 'c', 1)
782
+ self.write_u64(v)
783
+ end
784
+ end
785
+
786
+ # The Optional<T> type for string.
787
+
788
+ def write_Optionalstring(v)
789
+ if v.nil?
790
+ pack_into(1, 'c', 0)
791
+ else
792
+ pack_into(1, 'c', 1)
793
+ self.write_string(v)
794
+ end
795
+ end
796
+
797
+ # The Optional<T> type for TypeDelivery.
798
+
799
+ def write_OptionalTypeDelivery(v)
800
+ if v.nil?
801
+ pack_into(1, 'c', 0)
802
+ else
803
+ pack_into(1, 'c', 1)
804
+ self.write_TypeDelivery(v)
805
+ end
806
+ end
807
+
808
+
809
+
810
+ private
811
+
812
+ def reserve(num_bytes)
813
+ if @rust_buf.len + num_bytes > @rust_buf.capacity
814
+ @rust_buf = RustBuffer.reserve(@rust_buf, num_bytes)
815
+ end
816
+
817
+ yield
818
+
819
+ @rust_buf.len += num_bytes
820
+ end
821
+
822
+ def pack_into(size, format, value)
823
+ reserve(size) do
824
+ @rust_buf.data.put_array_of_char @rust_buf.len, [value].pack(format).bytes
825
+ end
826
+ end
827
+ end
828
+
829
+ private_constant :RustBufferBuilder
830
+
831
+ # Error definitions
832
+ class RustCallStatus < FFI::Struct
833
+ layout :code, :int8,
834
+ :error_buf, RustBuffer
835
+
836
+ def code
837
+ self[:code]
838
+ end
839
+
840
+ def error_buf
841
+ self[:error_buf]
842
+ end
843
+
844
+ def to_s
845
+ "RustCallStatus(code=#{self[:code]})"
846
+ end
847
+ end
848
+
849
+ # These match the values from the uniffi::rustcalls module
850
+ CALL_SUCCESS = 0
851
+ CALL_ERROR = 1
852
+ CALL_PANIC = 2
853
+
854
+
855
+ module FireMqError
856
+ class Server < StandardError
857
+ def initialize(code:, message:)
858
+
859
+ @code = code
860
+
861
+ @message = message
862
+
863
+ super()
864
+ end
865
+
866
+
867
+ attr_reader :code, :message
868
+
869
+
870
+ def to_s
871
+ "#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect})"
872
+
873
+ end
874
+ end
875
+ class Unroutable < StandardError
876
+ def initialize(message:)
877
+
878
+ @message = message
879
+
880
+ super()
881
+ end
882
+
883
+
884
+ attr_reader :message
885
+
886
+
887
+ def to_s
888
+ "#{self.class.name}(message=#{@message.inspect})"
889
+
890
+ end
891
+ end
892
+ class Nacked < StandardError
893
+ def initialize(code:, message:)
894
+
895
+ @code = code
896
+
897
+ @message = message
898
+
899
+ super()
900
+ end
901
+
902
+
903
+ attr_reader :code, :message
904
+
905
+
906
+ def to_s
907
+ "#{self.class.name}(code=#{@code.inspect}, message=#{@message.inspect})"
908
+
909
+ end
910
+ end
911
+ class Closed < StandardError
912
+ def initialize(message:)
913
+
914
+ @message = message
915
+
916
+ super()
917
+ end
918
+
919
+
920
+ attr_reader :message
921
+
922
+
923
+ def to_s
924
+ "#{self.class.name}(message=#{@message.inspect})"
925
+
926
+ end
927
+ end
928
+ class Other < StandardError
929
+ def initialize(message:)
930
+
931
+ @message = message
932
+
933
+ super()
934
+ end
935
+
936
+
937
+ attr_reader :message
938
+
939
+
940
+ def to_s
941
+ "#{self.class.name}(message=#{@message.inspect})"
942
+
943
+ end
944
+ end
945
+
946
+ end
947
+
948
+
949
+ # Map error modules to the RustBuffer method name that reads them
950
+ ERROR_MODULE_TO_READER_METHOD = {
951
+ FireMqError => :read_TypeFireMqError,
952
+ }
953
+
954
+ private_constant :ERROR_MODULE_TO_READER_METHOD, :CALL_SUCCESS, :CALL_ERROR, :CALL_PANIC,
955
+ :RustCallStatus
956
+
957
+ def self.consume_buffer_into_error(error_module, rust_buffer)
958
+ rust_buffer.consumeWithStream do |stream|
959
+ reader_method = ERROR_MODULE_TO_READER_METHOD[error_module] ||
960
+ ERROR_MODULE_TO_READER_METHOD[error_module.name&.split('::')&.last]
961
+ return stream.send(reader_method)
962
+ end
963
+ end
964
+
965
+ class InternalError < StandardError
966
+ end
967
+
968
+ def self.rust_call(fn_name, *args)
969
+ # Call a rust function
970
+ rust_call_with_error(nil, fn_name, *args)
971
+ end
972
+
973
+ def self.rust_call_with_error(error_module, fn_name, *args)
974
+ # Call a rust function and handle errors
975
+ #
976
+ # Use this when the rust function returns a Result<>. error_module must be the error_module that corresponds to that Result.
977
+
978
+
979
+ # Note: RustCallStatus.new zeroes out the struct, which is exactly what we
980
+ # want to pass to Rust (code=0, error_buf=RustBuffer(len=0, capacity=0,
981
+ # data=NULL))
982
+ status = RustCallStatus.new
983
+ args << status
984
+
985
+ result = UniFFILib.public_send(fn_name, *args)
986
+
987
+ case status.code
988
+ when CALL_SUCCESS
989
+ result
990
+ when CALL_ERROR
991
+ if error_module.nil?
992
+ status.error_buf.free
993
+ raise InternalError, "CALL_ERROR with no error_module set"
994
+ else
995
+ raise consume_buffer_into_error(error_module, status.error_buf)
996
+ end
997
+ when CALL_PANIC
998
+ # When the rust code sees a panic, it tries to construct a RustBuffer
999
+ # with the message. But if that code panics, then it just sends back
1000
+ # an empty buffer.
1001
+ if status.error_buf.len > 0
1002
+ raise InternalError, status.error_buf.consume_into_string
1003
+ else
1004
+ raise InternalError, "Rust panic"
1005
+ end
1006
+ else
1007
+ raise InternalError, "Unknown call status: #{status.code}"
1008
+ end
1009
+ end
1010
+
1011
+ private_class_method :consume_buffer_into_error
1012
+
1013
+ # This is how we find and load the dynamic library provided by the component.
1014
+ # For now we just look it up by name.
1015
+ module UniFFILib
1016
+ extend FFI::Library
1017
+
1018
+
1019
+ ffi_lib [ENV['FIREMQ_LIB'], File.expand_path(FFI.map_library_name('firemq_client_ffi'), __dir__), 'firemq_client_ffi'].compact
1020
+
1021
+
1022
+ # Define FFI callback types and structs (vtables, etc.)
1023
+
1024
+ callback :RustFutureContinuationCallback,
1025
+ [:uint64, :int8, ],
1026
+ :void
1027
+
1028
+ callback :ForeignFutureDroppedCallback,
1029
+ [:uint64, ],
1030
+ :void
1031
+
1032
+ callback :CallbackInterfaceFree,
1033
+ [:uint64, ],
1034
+ :void
1035
+
1036
+ callback :CallbackInterfaceClone,
1037
+ [:uint64, ],
1038
+ :uint64
1039
+
1040
+ class ForeignFutureDroppedCallbackStruct < FFI::Struct
1041
+ layout(
1042
+ :handle, :uint64,
1043
+ :free, :ForeignFutureDroppedCallback
1044
+ )
1045
+ end
1046
+
1047
+ class ForeignFutureResultU8 < FFI::Struct
1048
+ layout(
1049
+ :return_value, :uint8,
1050
+ :call_status, RustCallStatus
1051
+ )
1052
+ end
1053
+
1054
+ callback :ForeignFutureCompleteU8,
1055
+ [:uint64, ForeignFutureResultU8.by_value, ],
1056
+ :void
1057
+
1058
+ class ForeignFutureResultI8 < FFI::Struct
1059
+ layout(
1060
+ :return_value, :int8,
1061
+ :call_status, RustCallStatus
1062
+ )
1063
+ end
1064
+
1065
+ callback :ForeignFutureCompleteI8,
1066
+ [:uint64, ForeignFutureResultI8.by_value, ],
1067
+ :void
1068
+
1069
+ class ForeignFutureResultU16 < FFI::Struct
1070
+ layout(
1071
+ :return_value, :uint16,
1072
+ :call_status, RustCallStatus
1073
+ )
1074
+ end
1075
+
1076
+ callback :ForeignFutureCompleteU16,
1077
+ [:uint64, ForeignFutureResultU16.by_value, ],
1078
+ :void
1079
+
1080
+ class ForeignFutureResultI16 < FFI::Struct
1081
+ layout(
1082
+ :return_value, :int16,
1083
+ :call_status, RustCallStatus
1084
+ )
1085
+ end
1086
+
1087
+ callback :ForeignFutureCompleteI16,
1088
+ [:uint64, ForeignFutureResultI16.by_value, ],
1089
+ :void
1090
+
1091
+ class ForeignFutureResultU32 < FFI::Struct
1092
+ layout(
1093
+ :return_value, :uint32,
1094
+ :call_status, RustCallStatus
1095
+ )
1096
+ end
1097
+
1098
+ callback :ForeignFutureCompleteU32,
1099
+ [:uint64, ForeignFutureResultU32.by_value, ],
1100
+ :void
1101
+
1102
+ class ForeignFutureResultI32 < FFI::Struct
1103
+ layout(
1104
+ :return_value, :int32,
1105
+ :call_status, RustCallStatus
1106
+ )
1107
+ end
1108
+
1109
+ callback :ForeignFutureCompleteI32,
1110
+ [:uint64, ForeignFutureResultI32.by_value, ],
1111
+ :void
1112
+
1113
+ class ForeignFutureResultU64 < FFI::Struct
1114
+ layout(
1115
+ :return_value, :uint64,
1116
+ :call_status, RustCallStatus
1117
+ )
1118
+ end
1119
+
1120
+ callback :ForeignFutureCompleteU64,
1121
+ [:uint64, ForeignFutureResultU64.by_value, ],
1122
+ :void
1123
+
1124
+ class ForeignFutureResultI64 < FFI::Struct
1125
+ layout(
1126
+ :return_value, :int64,
1127
+ :call_status, RustCallStatus
1128
+ )
1129
+ end
1130
+
1131
+ callback :ForeignFutureCompleteI64,
1132
+ [:uint64, ForeignFutureResultI64.by_value, ],
1133
+ :void
1134
+
1135
+ class ForeignFutureResultF32 < FFI::Struct
1136
+ layout(
1137
+ :return_value, :float,
1138
+ :call_status, RustCallStatus
1139
+ )
1140
+ end
1141
+
1142
+ callback :ForeignFutureCompleteF32,
1143
+ [:uint64, ForeignFutureResultF32.by_value, ],
1144
+ :void
1145
+
1146
+ class ForeignFutureResultF64 < FFI::Struct
1147
+ layout(
1148
+ :return_value, :double,
1149
+ :call_status, RustCallStatus
1150
+ )
1151
+ end
1152
+
1153
+ callback :ForeignFutureCompleteF64,
1154
+ [:uint64, ForeignFutureResultF64.by_value, ],
1155
+ :void
1156
+
1157
+ class ForeignFutureResultRustBuffer < FFI::Struct
1158
+ layout(
1159
+ :return_value, RustBuffer.by_value,
1160
+ :call_status, RustCallStatus
1161
+ )
1162
+ end
1163
+
1164
+ callback :ForeignFutureCompleteRustBuffer,
1165
+ [:uint64, ForeignFutureResultRustBuffer.by_value, ],
1166
+ :void
1167
+
1168
+ class ForeignFutureResultVoid < FFI::Struct
1169
+ layout(
1170
+ :call_status, RustCallStatus
1171
+ )
1172
+ end
1173
+
1174
+ callback :ForeignFutureCompleteVoid,
1175
+ [:uint64, ForeignFutureResultVoid.by_value, ],
1176
+ :void
1177
+
1178
+ attach_function :uniffi_firemq_client_ffi_fn_clone_client,
1179
+ [:uint64, RustCallStatus.by_ref],
1180
+ :uint64
1181
+
1182
+ attach_function :uniffi_firemq_client_ffi_fn_free_client,
1183
+ [:uint64, RustCallStatus.by_ref],
1184
+ :void
1185
+
1186
+ attach_function :uniffi_firemq_client_ffi_fn_constructor_client_connect,
1187
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1188
+ :uint64
1189
+
1190
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_bind_exchange,
1191
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1192
+ :void
1193
+
1194
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_bind_queue,
1195
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1196
+ :void
1197
+
1198
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_close,
1199
+ [:uint64, RustCallStatus.by_ref],
1200
+ :void
1201
+
1202
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_declare_exchange,
1203
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, :int8, :int8, RustBuffer.by_value, RustCallStatus.by_ref],
1204
+ :void
1205
+
1206
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_declare_queue,
1207
+ [:uint64, RustBuffer.by_value, :int8, :int8, :int8, RustBuffer.by_value, RustCallStatus.by_ref],
1208
+ RustBuffer.by_value
1209
+
1210
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_delete_exchange,
1211
+ [:uint64, RustBuffer.by_value, :int8, RustCallStatus.by_ref],
1212
+ :void
1213
+
1214
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_delete_queue,
1215
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
1216
+ :uint64
1217
+
1218
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_get,
1219
+ [:uint64, RustBuffer.by_value, :int8, RustCallStatus.by_ref],
1220
+ RustBuffer.by_value
1221
+
1222
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_is_closed,
1223
+ [:uint64, RustCallStatus.by_ref],
1224
+ :int8
1225
+
1226
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_publish,
1227
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1228
+ :void
1229
+
1230
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_purge_queue,
1231
+ [:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
1232
+ :uint64
1233
+
1234
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_subscribe,
1235
+ [:uint64, RustBuffer.by_value, :uint32, :int8, RustCallStatus.by_ref],
1236
+ :uint64
1237
+
1238
+ attach_function :uniffi_firemq_client_ffi_fn_method_client_unbind_queue,
1239
+ [:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
1240
+ :void
1241
+
1242
+ attach_function :uniffi_firemq_client_ffi_fn_clone_delivery,
1243
+ [:uint64, RustCallStatus.by_ref],
1244
+ :uint64
1245
+
1246
+ attach_function :uniffi_firemq_client_ffi_fn_free_delivery,
1247
+ [:uint64, RustCallStatus.by_ref],
1248
+ :void
1249
+
1250
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_ack,
1251
+ [:uint64, RustCallStatus.by_ref],
1252
+ :void
1253
+
1254
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_body,
1255
+ [:uint64, RustCallStatus.by_ref],
1256
+ RustBuffer.by_value
1257
+
1258
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_delivery_tag,
1259
+ [:uint64, RustCallStatus.by_ref],
1260
+ :uint64
1261
+
1262
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_exchange,
1263
+ [:uint64, RustCallStatus.by_ref],
1264
+ RustBuffer.by_value
1265
+
1266
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_headers_json,
1267
+ [:uint64, RustCallStatus.by_ref],
1268
+ RustBuffer.by_value
1269
+
1270
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_nack,
1271
+ [:uint64, :int8, RustCallStatus.by_ref],
1272
+ :void
1273
+
1274
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_properties,
1275
+ [:uint64, RustCallStatus.by_ref],
1276
+ RustBuffer.by_value
1277
+
1278
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_redelivered,
1279
+ [:uint64, RustCallStatus.by_ref],
1280
+ :int8
1281
+
1282
+ attach_function :uniffi_firemq_client_ffi_fn_method_delivery_routing_key,
1283
+ [:uint64, RustCallStatus.by_ref],
1284
+ RustBuffer.by_value
1285
+
1286
+ attach_function :uniffi_firemq_client_ffi_fn_clone_subscription,
1287
+ [:uint64, RustCallStatus.by_ref],
1288
+ :uint64
1289
+
1290
+ attach_function :uniffi_firemq_client_ffi_fn_free_subscription,
1291
+ [:uint64, RustCallStatus.by_ref],
1292
+ :void
1293
+
1294
+ attach_function :uniffi_firemq_client_ffi_fn_method_subscription_cancel,
1295
+ [:uint64, RustCallStatus.by_ref],
1296
+ :void
1297
+
1298
+ attach_function :uniffi_firemq_client_ffi_fn_method_subscription_next,
1299
+ [:uint64, :uint64, RustCallStatus.by_ref],
1300
+ RustBuffer.by_value
1301
+
1302
+ attach_function :ffi_firemq_client_ffi_rustbuffer_alloc,
1303
+ [:uint64, RustCallStatus.by_ref],
1304
+ RustBuffer.by_value
1305
+
1306
+ attach_function :ffi_firemq_client_ffi_rustbuffer_from_bytes,
1307
+ [ForeignBytes, RustCallStatus.by_ref],
1308
+ RustBuffer.by_value
1309
+
1310
+ attach_function :ffi_firemq_client_ffi_rustbuffer_free,
1311
+ [RustBuffer.by_value, RustCallStatus.by_ref],
1312
+ :void
1313
+
1314
+ attach_function :ffi_firemq_client_ffi_rustbuffer_reserve,
1315
+ [RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
1316
+ RustBuffer.by_value
1317
+
1318
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_u8,
1319
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1320
+ :void
1321
+
1322
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_u8,
1323
+ [:uint64, ],
1324
+ :void
1325
+
1326
+ attach_function :ffi_firemq_client_ffi_rust_future_free_u8,
1327
+ [:uint64, ],
1328
+ :void
1329
+
1330
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_u8,
1331
+ [:uint64, RustCallStatus.by_ref],
1332
+ :uint8
1333
+
1334
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_i8,
1335
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1336
+ :void
1337
+
1338
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_i8,
1339
+ [:uint64, ],
1340
+ :void
1341
+
1342
+ attach_function :ffi_firemq_client_ffi_rust_future_free_i8,
1343
+ [:uint64, ],
1344
+ :void
1345
+
1346
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_i8,
1347
+ [:uint64, RustCallStatus.by_ref],
1348
+ :int8
1349
+
1350
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_u16,
1351
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1352
+ :void
1353
+
1354
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_u16,
1355
+ [:uint64, ],
1356
+ :void
1357
+
1358
+ attach_function :ffi_firemq_client_ffi_rust_future_free_u16,
1359
+ [:uint64, ],
1360
+ :void
1361
+
1362
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_u16,
1363
+ [:uint64, RustCallStatus.by_ref],
1364
+ :uint16
1365
+
1366
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_i16,
1367
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1368
+ :void
1369
+
1370
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_i16,
1371
+ [:uint64, ],
1372
+ :void
1373
+
1374
+ attach_function :ffi_firemq_client_ffi_rust_future_free_i16,
1375
+ [:uint64, ],
1376
+ :void
1377
+
1378
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_i16,
1379
+ [:uint64, RustCallStatus.by_ref],
1380
+ :int16
1381
+
1382
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_u32,
1383
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1384
+ :void
1385
+
1386
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_u32,
1387
+ [:uint64, ],
1388
+ :void
1389
+
1390
+ attach_function :ffi_firemq_client_ffi_rust_future_free_u32,
1391
+ [:uint64, ],
1392
+ :void
1393
+
1394
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_u32,
1395
+ [:uint64, RustCallStatus.by_ref],
1396
+ :uint32
1397
+
1398
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_i32,
1399
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1400
+ :void
1401
+
1402
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_i32,
1403
+ [:uint64, ],
1404
+ :void
1405
+
1406
+ attach_function :ffi_firemq_client_ffi_rust_future_free_i32,
1407
+ [:uint64, ],
1408
+ :void
1409
+
1410
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_i32,
1411
+ [:uint64, RustCallStatus.by_ref],
1412
+ :int32
1413
+
1414
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_u64,
1415
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1416
+ :void
1417
+
1418
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_u64,
1419
+ [:uint64, ],
1420
+ :void
1421
+
1422
+ attach_function :ffi_firemq_client_ffi_rust_future_free_u64,
1423
+ [:uint64, ],
1424
+ :void
1425
+
1426
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_u64,
1427
+ [:uint64, RustCallStatus.by_ref],
1428
+ :uint64
1429
+
1430
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_i64,
1431
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1432
+ :void
1433
+
1434
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_i64,
1435
+ [:uint64, ],
1436
+ :void
1437
+
1438
+ attach_function :ffi_firemq_client_ffi_rust_future_free_i64,
1439
+ [:uint64, ],
1440
+ :void
1441
+
1442
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_i64,
1443
+ [:uint64, RustCallStatus.by_ref],
1444
+ :int64
1445
+
1446
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_f32,
1447
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1448
+ :void
1449
+
1450
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_f32,
1451
+ [:uint64, ],
1452
+ :void
1453
+
1454
+ attach_function :ffi_firemq_client_ffi_rust_future_free_f32,
1455
+ [:uint64, ],
1456
+ :void
1457
+
1458
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_f32,
1459
+ [:uint64, RustCallStatus.by_ref],
1460
+ :float
1461
+
1462
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_f64,
1463
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1464
+ :void
1465
+
1466
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_f64,
1467
+ [:uint64, ],
1468
+ :void
1469
+
1470
+ attach_function :ffi_firemq_client_ffi_rust_future_free_f64,
1471
+ [:uint64, ],
1472
+ :void
1473
+
1474
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_f64,
1475
+ [:uint64, RustCallStatus.by_ref],
1476
+ :double
1477
+
1478
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_rust_buffer,
1479
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1480
+ :void
1481
+
1482
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_rust_buffer,
1483
+ [:uint64, ],
1484
+ :void
1485
+
1486
+ attach_function :ffi_firemq_client_ffi_rust_future_free_rust_buffer,
1487
+ [:uint64, ],
1488
+ :void
1489
+
1490
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_rust_buffer,
1491
+ [:uint64, RustCallStatus.by_ref],
1492
+ RustBuffer.by_value
1493
+
1494
+ attach_function :ffi_firemq_client_ffi_rust_future_poll_void,
1495
+ [:uint64, :RustFutureContinuationCallback, :uint64, ],
1496
+ :void
1497
+
1498
+ attach_function :ffi_firemq_client_ffi_rust_future_cancel_void,
1499
+ [:uint64, ],
1500
+ :void
1501
+
1502
+ attach_function :ffi_firemq_client_ffi_rust_future_free_void,
1503
+ [:uint64, ],
1504
+ :void
1505
+
1506
+ attach_function :ffi_firemq_client_ffi_rust_future_complete_void,
1507
+ [:uint64, RustCallStatus.by_ref],
1508
+ :void
1509
+
1510
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_bind_exchange,
1511
+ [],
1512
+ :uint16
1513
+
1514
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_bind_queue,
1515
+ [],
1516
+ :uint16
1517
+
1518
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_close,
1519
+ [],
1520
+ :uint16
1521
+
1522
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_declare_exchange,
1523
+ [],
1524
+ :uint16
1525
+
1526
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_declare_queue,
1527
+ [],
1528
+ :uint16
1529
+
1530
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_delete_exchange,
1531
+ [],
1532
+ :uint16
1533
+
1534
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_delete_queue,
1535
+ [],
1536
+ :uint16
1537
+
1538
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_get,
1539
+ [],
1540
+ :uint16
1541
+
1542
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_is_closed,
1543
+ [],
1544
+ :uint16
1545
+
1546
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_publish,
1547
+ [],
1548
+ :uint16
1549
+
1550
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_purge_queue,
1551
+ [],
1552
+ :uint16
1553
+
1554
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_subscribe,
1555
+ [],
1556
+ :uint16
1557
+
1558
+ attach_function :uniffi_firemq_client_ffi_checksum_method_client_unbind_queue,
1559
+ [],
1560
+ :uint16
1561
+
1562
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_ack,
1563
+ [],
1564
+ :uint16
1565
+
1566
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_body,
1567
+ [],
1568
+ :uint16
1569
+
1570
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_delivery_tag,
1571
+ [],
1572
+ :uint16
1573
+
1574
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_exchange,
1575
+ [],
1576
+ :uint16
1577
+
1578
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_headers_json,
1579
+ [],
1580
+ :uint16
1581
+
1582
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_nack,
1583
+ [],
1584
+ :uint16
1585
+
1586
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_properties,
1587
+ [],
1588
+ :uint16
1589
+
1590
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_redelivered,
1591
+ [],
1592
+ :uint16
1593
+
1594
+ attach_function :uniffi_firemq_client_ffi_checksum_method_delivery_routing_key,
1595
+ [],
1596
+ :uint16
1597
+
1598
+ attach_function :uniffi_firemq_client_ffi_checksum_method_subscription_cancel,
1599
+ [],
1600
+ :uint16
1601
+
1602
+ attach_function :uniffi_firemq_client_ffi_checksum_method_subscription_next,
1603
+ [],
1604
+ :uint16
1605
+
1606
+ attach_function :uniffi_firemq_client_ffi_checksum_constructor_client_connect,
1607
+ [],
1608
+ :uint16
1609
+
1610
+ attach_function :ffi_firemq_client_ffi_uniffi_contract_version,
1611
+ [],
1612
+ :uint32
1613
+
1614
+ end
1615
+
1616
+ # Custom type definitions.
1617
+
1618
+ # Public interface members begin here.
1619
+
1620
+
1621
+
1622
+ # Record type MessageProperties
1623
+ class MessageProperties
1624
+ attr_reader :content_type, :content_encoding, :correlation_id, :reply_to, :expiration, :message_id, :timestamp, :message_type, :user_id, :app_id, :priority
1625
+
1626
+ def initialize(content_type: nil, content_encoding: nil, correlation_id: nil, reply_to: nil, expiration: nil, message_id: nil, timestamp: nil, message_type: nil, user_id: nil, app_id: nil, priority: nil)
1627
+ @content_type = content_type
1628
+ @content_encoding = content_encoding
1629
+ @correlation_id = correlation_id
1630
+ @reply_to = reply_to
1631
+ @expiration = expiration
1632
+ @message_id = message_id
1633
+ @timestamp = timestamp
1634
+ @message_type = message_type
1635
+ @user_id = user_id
1636
+ @app_id = app_id
1637
+ @priority = priority
1638
+ end
1639
+
1640
+ def ==(other)
1641
+ if @content_type != other.content_type
1642
+ return false
1643
+ end
1644
+ if @content_encoding != other.content_encoding
1645
+ return false
1646
+ end
1647
+ if @correlation_id != other.correlation_id
1648
+ return false
1649
+ end
1650
+ if @reply_to != other.reply_to
1651
+ return false
1652
+ end
1653
+ if @expiration != other.expiration
1654
+ return false
1655
+ end
1656
+ if @message_id != other.message_id
1657
+ return false
1658
+ end
1659
+ if @timestamp != other.timestamp
1660
+ return false
1661
+ end
1662
+ if @message_type != other.message_type
1663
+ return false
1664
+ end
1665
+ if @user_id != other.user_id
1666
+ return false
1667
+ end
1668
+ if @app_id != other.app_id
1669
+ return false
1670
+ end
1671
+ if @priority != other.priority
1672
+ return false
1673
+ end
1674
+
1675
+ true
1676
+ end
1677
+
1678
+ end
1679
+
1680
+ # Record type PublishOptions
1681
+ class PublishOptions
1682
+ attr_reader :persistent, :mandatory, :confirm, :properties, :headers_json
1683
+
1684
+ def initialize(persistent: true, mandatory: false, confirm: true, properties: MessageProperties.new, headers_json: nil)
1685
+ @persistent = persistent
1686
+ @mandatory = mandatory
1687
+ @confirm = confirm
1688
+ @properties = properties
1689
+ @headers_json = headers_json
1690
+ end
1691
+
1692
+ def ==(other)
1693
+ if @persistent != other.persistent
1694
+ return false
1695
+ end
1696
+ if @mandatory != other.mandatory
1697
+ return false
1698
+ end
1699
+ if @confirm != other.confirm
1700
+ return false
1701
+ end
1702
+ if @properties != other.properties
1703
+ return false
1704
+ end
1705
+ if @headers_json != other.headers_json
1706
+ return false
1707
+ end
1708
+
1709
+ true
1710
+ end
1711
+
1712
+ end
1713
+
1714
+ # Record type QueueInfo
1715
+ class QueueInfo
1716
+ attr_reader :name, :messages, :consumers
1717
+
1718
+ def initialize(name:, messages:, consumers:)
1719
+ @name = name
1720
+ @messages = messages
1721
+ @consumers = consumers
1722
+ end
1723
+
1724
+ def ==(other)
1725
+ if @name != other.name
1726
+ return false
1727
+ end
1728
+ if @messages != other.messages
1729
+ return false
1730
+ end
1731
+ if @consumers != other.consumers
1732
+ return false
1733
+ end
1734
+
1735
+ true
1736
+ end
1737
+
1738
+ end
1739
+
1740
+
1741
+
1742
+
1743
+
1744
+ class Client
1745
+
1746
+ # A private helper for initializing instances of the class from a raw handle,
1747
+ # bypassing any initialization logic and ensuring they are GC'd properly.
1748
+ def self.uniffi_allocate(handle)
1749
+ inst = allocate
1750
+ inst.instance_variable_set :@handle, handle
1751
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
1752
+ return inst
1753
+ end
1754
+
1755
+ # A private helper for registering an object finalizer.
1756
+ # N.B. it's important that this does not capture a reference
1757
+ # to the actual instance, only its underlying handle.
1758
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
1759
+ Proc.new do |_id|
1760
+ ::FiremqClientFfi.rust_call(
1761
+ :uniffi_firemq_client_ffi_fn_free_client,
1762
+ handle
1763
+ )
1764
+ end
1765
+ end
1766
+ # A private helper for lowering instances into a raw handle.
1767
+ # This does an explicit typecheck, because accidentally lowering a different type of
1768
+ # object in a place where this type is expected, could lead to memory unsafety.
1769
+ def self.uniffi_check_lower(inst)
1770
+ if !inst.is_a? self
1771
+ raise TypeError.new "Expected a Client instance, got #{inst}"
1772
+ end
1773
+ end
1774
+
1775
+ def uniffi_clone_handle()
1776
+ return ::FiremqClientFfi.rust_call(
1777
+ :uniffi_firemq_client_ffi_fn_clone_client,
1778
+ @handle
1779
+ )
1780
+ end
1781
+
1782
+ def self.uniffi_lower(inst)
1783
+ return inst.uniffi_clone_handle()
1784
+ end
1785
+
1786
+ def self.uniffi_lift(handle)
1787
+ uniffi_allocate handle
1788
+ end
1789
+
1790
+
1791
+ def self.connect(url)
1792
+ url = ::FiremqClientFfi::uniffi_utf8(url)
1793
+
1794
+ # Call the (fallible) function before creating any half-baked object instances.
1795
+ # Lightly yucky way to bypass the usual "initialize" logic
1796
+ # and just create a new instance with the required handle.
1797
+ return uniffi_allocate(::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_constructor_client_connect,RustBuffer.alloc_from_string(url)))
1798
+ end
1799
+
1800
+
1801
+ def bind_exchange(destination, source, key)
1802
+ destination = ::FiremqClientFfi::uniffi_utf8(destination)
1803
+
1804
+ source = ::FiremqClientFfi::uniffi_utf8(source)
1805
+
1806
+ key = ::FiremqClientFfi::uniffi_utf8(key)
1807
+
1808
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_bind_exchange,uniffi_clone_handle(),RustBuffer.alloc_from_string(destination),RustBuffer.alloc_from_string(source),RustBuffer.alloc_from_string(key))
1809
+ end
1810
+
1811
+ def bind_queue(queue, exchange, key, args_json = nil)
1812
+ queue = ::FiremqClientFfi::uniffi_utf8(queue)
1813
+
1814
+ exchange = ::FiremqClientFfi::uniffi_utf8(exchange)
1815
+
1816
+ key = ::FiremqClientFfi::uniffi_utf8(key)
1817
+
1818
+ args_json = (args_json ? ::FiremqClientFfi::uniffi_utf8(args_json) : nil)
1819
+ RustBuffer.check_lower_Optionalstring(args_json)
1820
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_bind_queue,uniffi_clone_handle(),RustBuffer.alloc_from_string(queue),RustBuffer.alloc_from_string(exchange),RustBuffer.alloc_from_string(key),RustBuffer.alloc_from_Optionalstring(args_json))
1821
+ end
1822
+
1823
+ def close()
1824
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_close,uniffi_clone_handle(),)
1825
+ end
1826
+
1827
+ def declare_exchange(name, kind, durable = true, auto_delete = false, args_json = nil)
1828
+ name = ::FiremqClientFfi::uniffi_utf8(name)
1829
+
1830
+ kind = ::FiremqClientFfi::uniffi_utf8(kind)
1831
+
1832
+ durable = durable ? true : false
1833
+
1834
+ auto_delete = auto_delete ? true : false
1835
+
1836
+ args_json = (args_json ? ::FiremqClientFfi::uniffi_utf8(args_json) : nil)
1837
+ RustBuffer.check_lower_Optionalstring(args_json)
1838
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_declare_exchange,uniffi_clone_handle(),RustBuffer.alloc_from_string(name),RustBuffer.alloc_from_string(kind),(durable ? 1 : 0),(auto_delete ? 1 : 0),RustBuffer.alloc_from_Optionalstring(args_json))
1839
+ end
1840
+
1841
+ def declare_queue(name, durable = true, exclusive = false, auto_delete = false, args_json = nil)
1842
+ name = ::FiremqClientFfi::uniffi_utf8(name)
1843
+
1844
+ durable = durable ? true : false
1845
+
1846
+ exclusive = exclusive ? true : false
1847
+
1848
+ auto_delete = auto_delete ? true : false
1849
+
1850
+ args_json = (args_json ? ::FiremqClientFfi::uniffi_utf8(args_json) : nil)
1851
+ RustBuffer.check_lower_Optionalstring(args_json)
1852
+ result = ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_declare_queue,uniffi_clone_handle(),RustBuffer.alloc_from_string(name),(durable ? 1 : 0),(exclusive ? 1 : 0),(auto_delete ? 1 : 0),RustBuffer.alloc_from_Optionalstring(args_json))
1853
+ return result.consume_into_TypeQueueInfo
1854
+ end
1855
+ def delete_exchange(name, if_unused = false)
1856
+ name = ::FiremqClientFfi::uniffi_utf8(name)
1857
+
1858
+ if_unused = if_unused ? true : false
1859
+
1860
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_delete_exchange,uniffi_clone_handle(),RustBuffer.alloc_from_string(name),(if_unused ? 1 : 0))
1861
+ end
1862
+
1863
+ def delete_queue(name)
1864
+ name = ::FiremqClientFfi::uniffi_utf8(name)
1865
+
1866
+ result = ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_delete_queue,uniffi_clone_handle(),RustBuffer.alloc_from_string(name))
1867
+ return result.to_i
1868
+ end
1869
+ def get(queue, no_ack = false)
1870
+ queue = ::FiremqClientFfi::uniffi_utf8(queue)
1871
+
1872
+ no_ack = no_ack ? true : false
1873
+
1874
+ result = ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_get,uniffi_clone_handle(),RustBuffer.alloc_from_string(queue),(no_ack ? 1 : 0))
1875
+ return result.consume_into_OptionalTypeDelivery
1876
+ end
1877
+ def is_closed()
1878
+ result = ::FiremqClientFfi.rust_call(:uniffi_firemq_client_ffi_fn_method_client_is_closed,uniffi_clone_handle(),)
1879
+ return 1 == result
1880
+ end
1881
+ def publish(exchange, key, body, options = PublishOptions.new)
1882
+ exchange = ::FiremqClientFfi::uniffi_utf8(exchange)
1883
+
1884
+ key = ::FiremqClientFfi::uniffi_utf8(key)
1885
+
1886
+ body = ::FiremqClientFfi::uniffi_bytes(body)
1887
+
1888
+ options = options
1889
+ RustBuffer.check_lower_TypePublishOptions(options)
1890
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_publish,uniffi_clone_handle(),RustBuffer.alloc_from_string(exchange),RustBuffer.alloc_from_string(key),RustBuffer.alloc_from_bytes(body),RustBuffer.alloc_from_TypePublishOptions(options))
1891
+ end
1892
+
1893
+ def purge_queue(name)
1894
+ name = ::FiremqClientFfi::uniffi_utf8(name)
1895
+
1896
+ result = ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_purge_queue,uniffi_clone_handle(),RustBuffer.alloc_from_string(name))
1897
+ return result.to_i
1898
+ end
1899
+ def subscribe(queue, prefetch = 100, no_ack = false)
1900
+ queue = ::FiremqClientFfi::uniffi_utf8(queue)
1901
+
1902
+ prefetch = ::FiremqClientFfi::uniffi_in_range(prefetch, "u32", 0, 2**32)
1903
+
1904
+ no_ack = no_ack ? true : false
1905
+
1906
+ result = ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_subscribe,uniffi_clone_handle(),RustBuffer.alloc_from_string(queue),prefetch,(no_ack ? 1 : 0))
1907
+ return Subscription.uniffi_lift(result)
1908
+ end
1909
+ def unbind_queue(queue, exchange, key)
1910
+ queue = ::FiremqClientFfi::uniffi_utf8(queue)
1911
+
1912
+ exchange = ::FiremqClientFfi::uniffi_utf8(exchange)
1913
+
1914
+ key = ::FiremqClientFfi::uniffi_utf8(key)
1915
+
1916
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_client_unbind_queue,uniffi_clone_handle(),RustBuffer.alloc_from_string(queue),RustBuffer.alloc_from_string(exchange),RustBuffer.alloc_from_string(key))
1917
+ end
1918
+
1919
+
1920
+ end
1921
+
1922
+ class Delivery
1923
+
1924
+ # A private helper for initializing instances of the class from a raw handle,
1925
+ # bypassing any initialization logic and ensuring they are GC'd properly.
1926
+ def self.uniffi_allocate(handle)
1927
+ inst = allocate
1928
+ inst.instance_variable_set :@handle, handle
1929
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
1930
+ return inst
1931
+ end
1932
+
1933
+ # A private helper for registering an object finalizer.
1934
+ # N.B. it's important that this does not capture a reference
1935
+ # to the actual instance, only its underlying handle.
1936
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
1937
+ Proc.new do |_id|
1938
+ ::FiremqClientFfi.rust_call(
1939
+ :uniffi_firemq_client_ffi_fn_free_delivery,
1940
+ handle
1941
+ )
1942
+ end
1943
+ end
1944
+ # A private helper for lowering instances into a raw handle.
1945
+ # This does an explicit typecheck, because accidentally lowering a different type of
1946
+ # object in a place where this type is expected, could lead to memory unsafety.
1947
+ def self.uniffi_check_lower(inst)
1948
+ if !inst.is_a? self
1949
+ raise TypeError.new "Expected a Delivery instance, got #{inst}"
1950
+ end
1951
+ end
1952
+
1953
+ def uniffi_clone_handle()
1954
+ return ::FiremqClientFfi.rust_call(
1955
+ :uniffi_firemq_client_ffi_fn_clone_delivery,
1956
+ @handle
1957
+ )
1958
+ end
1959
+
1960
+ def self.uniffi_lower(inst)
1961
+ return inst.uniffi_clone_handle()
1962
+ end
1963
+
1964
+ def self.uniffi_lift(handle)
1965
+ uniffi_allocate handle
1966
+ end
1967
+
1968
+
1969
+
1970
+ def ack()
1971
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_delivery_ack,uniffi_clone_handle(),)
1972
+ end
1973
+
1974
+ def body()
1975
+ result = ::FiremqClientFfi.rust_call(:uniffi_firemq_client_ffi_fn_method_delivery_body,uniffi_clone_handle(),)
1976
+ return result.consume_into_bytes
1977
+ end
1978
+ def delivery_tag()
1979
+ result = ::FiremqClientFfi.rust_call(:uniffi_firemq_client_ffi_fn_method_delivery_delivery_tag,uniffi_clone_handle(),)
1980
+ return result.to_i
1981
+ end
1982
+ def exchange()
1983
+ result = ::FiremqClientFfi.rust_call(:uniffi_firemq_client_ffi_fn_method_delivery_exchange,uniffi_clone_handle(),)
1984
+ return result.consume_into_string
1985
+ end
1986
+ def headers_json()
1987
+ result = ::FiremqClientFfi.rust_call(:uniffi_firemq_client_ffi_fn_method_delivery_headers_json,uniffi_clone_handle(),)
1988
+ return result.consume_into_string
1989
+ end
1990
+ def nack(requeue)
1991
+ requeue = requeue ? true : false
1992
+
1993
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_delivery_nack,uniffi_clone_handle(),(requeue ? 1 : 0))
1994
+ end
1995
+
1996
+ def properties()
1997
+ result = ::FiremqClientFfi.rust_call(:uniffi_firemq_client_ffi_fn_method_delivery_properties,uniffi_clone_handle(),)
1998
+ return result.consume_into_TypeMessageProperties
1999
+ end
2000
+ def redelivered()
2001
+ result = ::FiremqClientFfi.rust_call(:uniffi_firemq_client_ffi_fn_method_delivery_redelivered,uniffi_clone_handle(),)
2002
+ return 1 == result
2003
+ end
2004
+ def routing_key()
2005
+ result = ::FiremqClientFfi.rust_call(:uniffi_firemq_client_ffi_fn_method_delivery_routing_key,uniffi_clone_handle(),)
2006
+ return result.consume_into_string
2007
+ end
2008
+
2009
+ end
2010
+
2011
+ class Subscription
2012
+
2013
+ # A private helper for initializing instances of the class from a raw handle,
2014
+ # bypassing any initialization logic and ensuring they are GC'd properly.
2015
+ def self.uniffi_allocate(handle)
2016
+ inst = allocate
2017
+ inst.instance_variable_set :@handle, handle
2018
+ ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
2019
+ return inst
2020
+ end
2021
+
2022
+ # A private helper for registering an object finalizer.
2023
+ # N.B. it's important that this does not capture a reference
2024
+ # to the actual instance, only its underlying handle.
2025
+ def self.uniffi_define_finalizer_by_handle(handle, object_id)
2026
+ Proc.new do |_id|
2027
+ ::FiremqClientFfi.rust_call(
2028
+ :uniffi_firemq_client_ffi_fn_free_subscription,
2029
+ handle
2030
+ )
2031
+ end
2032
+ end
2033
+ # A private helper for lowering instances into a raw handle.
2034
+ # This does an explicit typecheck, because accidentally lowering a different type of
2035
+ # object in a place where this type is expected, could lead to memory unsafety.
2036
+ def self.uniffi_check_lower(inst)
2037
+ if !inst.is_a? self
2038
+ raise TypeError.new "Expected a Subscription instance, got #{inst}"
2039
+ end
2040
+ end
2041
+
2042
+ def uniffi_clone_handle()
2043
+ return ::FiremqClientFfi.rust_call(
2044
+ :uniffi_firemq_client_ffi_fn_clone_subscription,
2045
+ @handle
2046
+ )
2047
+ end
2048
+
2049
+ def self.uniffi_lower(inst)
2050
+ return inst.uniffi_clone_handle()
2051
+ end
2052
+
2053
+ def self.uniffi_lift(handle)
2054
+ uniffi_allocate handle
2055
+ end
2056
+
2057
+
2058
+
2059
+ def cancel()
2060
+ ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_subscription_cancel,uniffi_clone_handle(),)
2061
+ end
2062
+
2063
+ def next(timeout_ms)
2064
+ timeout_ms = ::FiremqClientFfi::uniffi_in_range(timeout_ms, "u64", 0, 2**64)
2065
+
2066
+ result = ::FiremqClientFfi.rust_call_with_error(FireMqError,:uniffi_firemq_client_ffi_fn_method_subscription_next,uniffi_clone_handle(),timeout_ms)
2067
+ return result.consume_into_OptionalTypeDelivery
2068
+ end
2069
+
2070
+ end
2071
+
2072
+
2073
+
2074
+ end
2075
+