stem-mqtt-broker 0.6.1-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.
- checksums.yaml +7 -0
- data/lib/stem_mqtt_broker/mqtt_broker.rb +2956 -0
- data/lib/stem_mqtt_broker/native/libmqtt_broker.so +0 -0
- data/lib/stem_mqtt_broker.rb +1 -0
- metadata +56 -0
|
@@ -0,0 +1,2956 @@
|
|
|
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 MqttBroker
|
|
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 ::MqttBroker.rust_call(:ffi_mqtt_broker_rustbuffer_alloc, size)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def self.reserve(rbuf, additional)
|
|
154
|
+
return ::MqttBroker.rust_call(:ffi_mqtt_broker_rustbuffer_reserve, rbuf, additional)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def free
|
|
158
|
+
::MqttBroker.rust_call(:ffi_mqtt_broker_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 AuthRequest.
|
|
235
|
+
|
|
236
|
+
def self.check_lower_TypeAuthRequest(v)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
RustBuffer.check_lower_Optionalstring(v.username)
|
|
240
|
+
RustBuffer.check_lower_Optionalbytes(v.password)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def self.alloc_from_TypeAuthRequest(v)
|
|
244
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
245
|
+
builder.write_TypeAuthRequest(v)
|
|
246
|
+
return builder.finalize
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def consume_into_TypeAuthRequest
|
|
251
|
+
consumeWithStream do |stream|
|
|
252
|
+
return stream.read_TypeAuthRequest
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# The Record type BrokerTlsConfig.
|
|
257
|
+
|
|
258
|
+
def self.check_lower_TypeBrokerTlsConfig(v)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
RustBuffer.check_lower_Optionalbytes(v.client_ca_pem)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def self.alloc_from_TypeBrokerTlsConfig(v)
|
|
266
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
267
|
+
builder.write_TypeBrokerTlsConfig(v)
|
|
268
|
+
return builder.finalize
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def consume_into_TypeBrokerTlsConfig
|
|
273
|
+
consumeWithStream do |stream|
|
|
274
|
+
return stream.read_TypeBrokerTlsConfig
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
# The Record type EnhancedAuthStep.
|
|
279
|
+
|
|
280
|
+
def self.check_lower_TypeEnhancedAuthStep(v)
|
|
281
|
+
RustBuffer.check_lower_TypeEnhancedAuthOutcome(v.outcome)
|
|
282
|
+
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
def self.alloc_from_TypeEnhancedAuthStep(v)
|
|
286
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
287
|
+
builder.write_TypeEnhancedAuthStep(v)
|
|
288
|
+
return builder.finalize
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def consume_into_TypeEnhancedAuthStep
|
|
293
|
+
consumeWithStream do |stream|
|
|
294
|
+
return stream.read_TypeEnhancedAuthStep
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
# The Record type MqttBrokerConfig.
|
|
299
|
+
|
|
300
|
+
def self.check_lower_TypeMqttBrokerConfig(v)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
RustBuffer.check_lower_Optionalu16(v.ws_port)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
RustBuffer.check_lower_TypeQoS(v.max_qos)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
RustBuffer.check_lower_OptionalTypeBrokerTlsConfig(v.tls)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
def self.alloc_from_TypeMqttBrokerConfig(v)
|
|
317
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
318
|
+
builder.write_TypeMqttBrokerConfig(v)
|
|
319
|
+
return builder.finalize
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def consume_into_TypeMqttBrokerConfig
|
|
324
|
+
consumeWithStream do |stream|
|
|
325
|
+
return stream.read_TypeMqttBrokerConfig
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
# The Enum type BrokerEvent.
|
|
330
|
+
|
|
331
|
+
def self.check_lower_TypeBrokerEvent(v)
|
|
332
|
+
if v.client_connected?
|
|
333
|
+
|
|
334
|
+
return
|
|
335
|
+
end
|
|
336
|
+
if v.client_disconnected?
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
return
|
|
340
|
+
end
|
|
341
|
+
if v.message_published?
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
RustBuffer.check_lower_TypeQoS(v.qos)
|
|
345
|
+
return
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def self.alloc_from_TypeBrokerEvent(v)
|
|
350
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
351
|
+
builder.write_TypeBrokerEvent(v)
|
|
352
|
+
return builder.finalize
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
def consume_into_TypeBrokerEvent
|
|
357
|
+
consumeWithStream do |stream|
|
|
358
|
+
return stream.read_TypeBrokerEvent
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
# The Enum type EnhancedAuthOutcome.
|
|
364
|
+
|
|
365
|
+
def self.check_lower_TypeEnhancedAuthOutcome(v)
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def self.alloc_from_TypeEnhancedAuthOutcome(v)
|
|
369
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
370
|
+
builder.write_TypeEnhancedAuthOutcome(v)
|
|
371
|
+
return builder.finalize
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
def consume_into_TypeEnhancedAuthOutcome
|
|
376
|
+
consumeWithStream do |stream|
|
|
377
|
+
return stream.read_TypeEnhancedAuthOutcome
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
# Error enum - generate alloc_from for callback error serialization
|
|
383
|
+
def self.alloc_from_TypeMqttBrokerError(v)
|
|
384
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
385
|
+
builder.write_TypeMqttBrokerError(v)
|
|
386
|
+
return builder.finalize
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
# Enum used as error - generate consume_into_ for use as a return value
|
|
391
|
+
def consume_into_TypeMqttBrokerError
|
|
392
|
+
consumeWithStream do |stream|
|
|
393
|
+
return stream.read_TypeMqttBrokerError
|
|
394
|
+
end
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
# The Enum type QoS.
|
|
399
|
+
|
|
400
|
+
def self.check_lower_TypeQoS(v)
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def self.alloc_from_TypeQoS(v)
|
|
404
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
405
|
+
builder.write_TypeQoS(v)
|
|
406
|
+
return builder.finalize
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def consume_into_TypeQoS
|
|
411
|
+
consumeWithStream do |stream|
|
|
412
|
+
return stream.read_TypeQoS
|
|
413
|
+
end
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
# The Optional<T> type for u16.
|
|
418
|
+
|
|
419
|
+
def self.check_lower_Optionalu16(v)
|
|
420
|
+
if !v.nil?
|
|
421
|
+
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
def self.alloc_from_Optionalu16(v)
|
|
426
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
427
|
+
builder.write_Optionalu16(v)
|
|
428
|
+
return builder.finalize()
|
|
429
|
+
end
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
def consume_into_Optionalu16
|
|
433
|
+
consumeWithStream do |stream|
|
|
434
|
+
return stream.read_Optionalu16
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
# The Optional<T> type for string.
|
|
439
|
+
|
|
440
|
+
def self.check_lower_Optionalstring(v)
|
|
441
|
+
if !v.nil?
|
|
442
|
+
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
def self.alloc_from_Optionalstring(v)
|
|
447
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
448
|
+
builder.write_Optionalstring(v)
|
|
449
|
+
return builder.finalize()
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
def consume_into_Optionalstring
|
|
454
|
+
consumeWithStream do |stream|
|
|
455
|
+
return stream.read_Optionalstring
|
|
456
|
+
end
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
# The Optional<T> type for bytes.
|
|
460
|
+
|
|
461
|
+
def self.check_lower_Optionalbytes(v)
|
|
462
|
+
if !v.nil?
|
|
463
|
+
|
|
464
|
+
end
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
def self.alloc_from_Optionalbytes(v)
|
|
468
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
469
|
+
builder.write_Optionalbytes(v)
|
|
470
|
+
return builder.finalize()
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
def consume_into_Optionalbytes
|
|
475
|
+
consumeWithStream do |stream|
|
|
476
|
+
return stream.read_Optionalbytes
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
# The Optional<T> type for TypeAuthRequest.
|
|
481
|
+
|
|
482
|
+
def self.check_lower_OptionalTypeAuthRequest(v)
|
|
483
|
+
if !v.nil?
|
|
484
|
+
RustBuffer.check_lower_TypeAuthRequest(v)
|
|
485
|
+
end
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
def self.alloc_from_OptionalTypeAuthRequest(v)
|
|
489
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
490
|
+
builder.write_OptionalTypeAuthRequest(v)
|
|
491
|
+
return builder.finalize()
|
|
492
|
+
end
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
def consume_into_OptionalTypeAuthRequest
|
|
496
|
+
consumeWithStream do |stream|
|
|
497
|
+
return stream.read_OptionalTypeAuthRequest
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
# The Optional<T> type for TypeBrokerTlsConfig.
|
|
502
|
+
|
|
503
|
+
def self.check_lower_OptionalTypeBrokerTlsConfig(v)
|
|
504
|
+
if !v.nil?
|
|
505
|
+
RustBuffer.check_lower_TypeBrokerTlsConfig(v)
|
|
506
|
+
end
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
def self.alloc_from_OptionalTypeBrokerTlsConfig(v)
|
|
510
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
511
|
+
builder.write_OptionalTypeBrokerTlsConfig(v)
|
|
512
|
+
return builder.finalize()
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
def consume_into_OptionalTypeBrokerTlsConfig
|
|
517
|
+
consumeWithStream do |stream|
|
|
518
|
+
return stream.read_OptionalTypeBrokerTlsConfig
|
|
519
|
+
end
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
# The Optional<T> type for TypeBrokerEvent.
|
|
523
|
+
|
|
524
|
+
def self.check_lower_OptionalTypeBrokerEvent(v)
|
|
525
|
+
if !v.nil?
|
|
526
|
+
RustBuffer.check_lower_TypeBrokerEvent(v)
|
|
527
|
+
end
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
def self.alloc_from_OptionalTypeBrokerEvent(v)
|
|
531
|
+
RustBuffer.allocWithBuilder do |builder|
|
|
532
|
+
builder.write_OptionalTypeBrokerEvent(v)
|
|
533
|
+
return builder.finalize()
|
|
534
|
+
end
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
def consume_into_OptionalTypeBrokerEvent
|
|
538
|
+
consumeWithStream do |stream|
|
|
539
|
+
return stream.read_OptionalTypeBrokerEvent
|
|
540
|
+
end
|
|
541
|
+
end
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
module UniFFILib
|
|
547
|
+
class ForeignBytes < FFI::Struct
|
|
548
|
+
layout :len, :int32,
|
|
549
|
+
:data, :pointer
|
|
550
|
+
|
|
551
|
+
def len
|
|
552
|
+
self[:len]
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
def data
|
|
556
|
+
self[:data]
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
def to_s
|
|
560
|
+
"ForeignBytes(len=#{len}, data=#{data.read_bytes(len)})"
|
|
561
|
+
end
|
|
562
|
+
end
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
private_constant :UniFFILib
|
|
566
|
+
|
|
567
|
+
# Helper for structured reading of values from a RustBuffer.
|
|
568
|
+
class RustBufferStream
|
|
569
|
+
|
|
570
|
+
def initialize(rbuf)
|
|
571
|
+
@rbuf = rbuf
|
|
572
|
+
@offset = 0
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
def remaining
|
|
576
|
+
@rbuf.len - @offset
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
def read(size)
|
|
580
|
+
raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
|
|
581
|
+
|
|
582
|
+
data = @rbuf.data.get_bytes @offset, size
|
|
583
|
+
|
|
584
|
+
@offset += size
|
|
585
|
+
|
|
586
|
+
data
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
def read_u16
|
|
590
|
+
unpack_from 2, 'S>'
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
def read_u32
|
|
594
|
+
unpack_from 4, 'L>'
|
|
595
|
+
end
|
|
596
|
+
|
|
597
|
+
def read_u64
|
|
598
|
+
unpack_from 8, 'Q>'
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
def read_bool
|
|
602
|
+
v = unpack_from 1, 'c'
|
|
603
|
+
|
|
604
|
+
return false if v == 0
|
|
605
|
+
return true if v == 1
|
|
606
|
+
|
|
607
|
+
raise InternalError, 'Unexpected byte for Boolean type'
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
def read_string
|
|
611
|
+
size = unpack_from 4, 'l>'
|
|
612
|
+
|
|
613
|
+
raise InternalError, 'Unexpected negative string length' if size.negative?
|
|
614
|
+
|
|
615
|
+
read(size).force_encoding(Encoding::UTF_8)
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
def read_bytes
|
|
619
|
+
size = unpack_from 4, 'l>'
|
|
620
|
+
|
|
621
|
+
raise InternalError, 'Unexpected negative byte string length' if size.negative?
|
|
622
|
+
|
|
623
|
+
read(size).force_encoding(Encoding::BINARY)
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
# The Object type MqttAuthProvider.
|
|
627
|
+
|
|
628
|
+
def read_TypeMqttAuthProvider
|
|
629
|
+
handle = unpack_from 8, 'Q>'
|
|
630
|
+
return MqttAuthProvider.uniffi_lift(handle)
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
# The Object type MqttBroker.
|
|
634
|
+
|
|
635
|
+
def read_TypeMqttBroker
|
|
636
|
+
handle = unpack_from 8, 'Q>'
|
|
637
|
+
return MqttBroker.uniffi_lift(handle)
|
|
638
|
+
end
|
|
639
|
+
|
|
640
|
+
# The Object type MqttBrokerEventListener.
|
|
641
|
+
|
|
642
|
+
def read_TypeMqttBrokerEventListener
|
|
643
|
+
handle = unpack_from 8, 'Q>'
|
|
644
|
+
return MqttBrokerEventListener.uniffi_lift(handle)
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
# The Object type MqttEnhancedAuthProvider.
|
|
648
|
+
|
|
649
|
+
def read_TypeMqttEnhancedAuthProvider
|
|
650
|
+
handle = unpack_from 8, 'Q>'
|
|
651
|
+
return MqttEnhancedAuthProvider.uniffi_lift(handle)
|
|
652
|
+
end
|
|
653
|
+
|
|
654
|
+
# The Record type AuthRequest.
|
|
655
|
+
|
|
656
|
+
def read_TypeAuthRequest
|
|
657
|
+
AuthRequest.new(
|
|
658
|
+
id: read_u64,
|
|
659
|
+
client_id: read_string,
|
|
660
|
+
username: read_Optionalstring,
|
|
661
|
+
password: read_Optionalbytes
|
|
662
|
+
)
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
# The Record type BrokerTlsConfig.
|
|
666
|
+
|
|
667
|
+
def read_TypeBrokerTlsConfig
|
|
668
|
+
BrokerTlsConfig.new(
|
|
669
|
+
port: read_u16,
|
|
670
|
+
cert_pem: read_bytes,
|
|
671
|
+
key_pem: read_bytes,
|
|
672
|
+
client_ca_pem: read_Optionalbytes
|
|
673
|
+
)
|
|
674
|
+
end
|
|
675
|
+
|
|
676
|
+
# The Record type EnhancedAuthStep.
|
|
677
|
+
|
|
678
|
+
def read_TypeEnhancedAuthStep
|
|
679
|
+
EnhancedAuthStep.new(
|
|
680
|
+
outcome: read_TypeEnhancedAuthOutcome,
|
|
681
|
+
data: read_bytes
|
|
682
|
+
)
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
# The Record type MqttBrokerConfig.
|
|
686
|
+
|
|
687
|
+
def read_TypeMqttBrokerConfig
|
|
688
|
+
MqttBrokerConfig.new(
|
|
689
|
+
bind_address: read_string,
|
|
690
|
+
port: read_u16,
|
|
691
|
+
ws_port: read_Optionalu16,
|
|
692
|
+
allow_anonymous: read_bool,
|
|
693
|
+
max_clients: read_u32,
|
|
694
|
+
max_qos: read_TypeQoS,
|
|
695
|
+
max_retained_messages: read_u32,
|
|
696
|
+
max_queued_per_client: read_u32,
|
|
697
|
+
redelivery_interval_secs: read_u32,
|
|
698
|
+
tls: read_OptionalTypeBrokerTlsConfig,
|
|
699
|
+
max_packet_size: read_u32,
|
|
700
|
+
max_outbound_queue: read_u32,
|
|
701
|
+
session_expiry_secs: read_u32
|
|
702
|
+
)
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
# The Enum type BrokerEvent.
|
|
708
|
+
|
|
709
|
+
def read_TypeBrokerEvent
|
|
710
|
+
variant = unpack_from 4, 'l>'
|
|
711
|
+
|
|
712
|
+
if variant == 1
|
|
713
|
+
return BrokerEvent::CLIENT_CONNECTED.new(
|
|
714
|
+
client_id: self.read_string()
|
|
715
|
+
)
|
|
716
|
+
end
|
|
717
|
+
if variant == 2
|
|
718
|
+
return BrokerEvent::CLIENT_DISCONNECTED.new(
|
|
719
|
+
client_id: self.read_string(),
|
|
720
|
+
reason: self.read_string()
|
|
721
|
+
)
|
|
722
|
+
end
|
|
723
|
+
if variant == 3
|
|
724
|
+
return BrokerEvent::MESSAGE_PUBLISHED.new(
|
|
725
|
+
client_id: self.read_string(),
|
|
726
|
+
topic: self.read_string(),
|
|
727
|
+
qos: self.read_TypeQoS()
|
|
728
|
+
)
|
|
729
|
+
end
|
|
730
|
+
raise InternalError, 'Unexpected variant tag for TypeBrokerEvent'
|
|
731
|
+
end
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
# The Enum type EnhancedAuthOutcome.
|
|
738
|
+
|
|
739
|
+
def read_TypeEnhancedAuthOutcome
|
|
740
|
+
variant = unpack_from 4, 'l>'
|
|
741
|
+
|
|
742
|
+
if variant == 1
|
|
743
|
+
return EnhancedAuthOutcome::CONTINUE
|
|
744
|
+
end
|
|
745
|
+
if variant == 2
|
|
746
|
+
return EnhancedAuthOutcome::SUCCESS
|
|
747
|
+
end
|
|
748
|
+
if variant == 3
|
|
749
|
+
return EnhancedAuthOutcome::FAILURE
|
|
750
|
+
end
|
|
751
|
+
|
|
752
|
+
raise InternalError, 'Unexpected variant tag for TypeEnhancedAuthOutcome'
|
|
753
|
+
end
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
# The Error type MqttBrokerError
|
|
762
|
+
|
|
763
|
+
def read_TypeMqttBrokerError
|
|
764
|
+
variant = unpack_from 4, 'l>'
|
|
765
|
+
|
|
766
|
+
if variant == 1
|
|
767
|
+
return MqttBrokerError::AlreadyRunning.new(
|
|
768
|
+
read_string()
|
|
769
|
+
)
|
|
770
|
+
end
|
|
771
|
+
if variant == 2
|
|
772
|
+
return MqttBrokerError::Io.new(
|
|
773
|
+
read_string()
|
|
774
|
+
)
|
|
775
|
+
end
|
|
776
|
+
if variant == 3
|
|
777
|
+
return MqttBrokerError::Tls.new(
|
|
778
|
+
read_string()
|
|
779
|
+
)
|
|
780
|
+
end
|
|
781
|
+
|
|
782
|
+
raise InternalError, 'Unexpected variant tag for TypeMqttBrokerError'
|
|
783
|
+
end
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
# The Enum type QoS.
|
|
789
|
+
|
|
790
|
+
def read_TypeQoS
|
|
791
|
+
variant = unpack_from 4, 'l>'
|
|
792
|
+
|
|
793
|
+
if variant == 1
|
|
794
|
+
return QoS::AT_MOST_ONCE
|
|
795
|
+
end
|
|
796
|
+
if variant == 2
|
|
797
|
+
return QoS::AT_LEAST_ONCE
|
|
798
|
+
end
|
|
799
|
+
if variant == 3
|
|
800
|
+
return QoS::EXACTLY_ONCE
|
|
801
|
+
end
|
|
802
|
+
|
|
803
|
+
raise InternalError, 'Unexpected variant tag for TypeQoS'
|
|
804
|
+
end
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
# The Optional<T> type for u16.
|
|
810
|
+
|
|
811
|
+
def read_Optionalu16
|
|
812
|
+
flag = unpack_from 1, 'c'
|
|
813
|
+
|
|
814
|
+
if flag == 0
|
|
815
|
+
return nil
|
|
816
|
+
elsif flag == 1
|
|
817
|
+
return read_u16
|
|
818
|
+
else
|
|
819
|
+
raise InternalError, 'Unexpected flag byte for Optionalu16'
|
|
820
|
+
end
|
|
821
|
+
end
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
# The Optional<T> type for string.
|
|
825
|
+
|
|
826
|
+
def read_Optionalstring
|
|
827
|
+
flag = unpack_from 1, 'c'
|
|
828
|
+
|
|
829
|
+
if flag == 0
|
|
830
|
+
return nil
|
|
831
|
+
elsif flag == 1
|
|
832
|
+
return read_string
|
|
833
|
+
else
|
|
834
|
+
raise InternalError, 'Unexpected flag byte for Optionalstring'
|
|
835
|
+
end
|
|
836
|
+
end
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
# The Optional<T> type for bytes.
|
|
840
|
+
|
|
841
|
+
def read_Optionalbytes
|
|
842
|
+
flag = unpack_from 1, 'c'
|
|
843
|
+
|
|
844
|
+
if flag == 0
|
|
845
|
+
return nil
|
|
846
|
+
elsif flag == 1
|
|
847
|
+
return read_bytes
|
|
848
|
+
else
|
|
849
|
+
raise InternalError, 'Unexpected flag byte for Optionalbytes'
|
|
850
|
+
end
|
|
851
|
+
end
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
# The Optional<T> type for TypeAuthRequest.
|
|
855
|
+
|
|
856
|
+
def read_OptionalTypeAuthRequest
|
|
857
|
+
flag = unpack_from 1, 'c'
|
|
858
|
+
|
|
859
|
+
if flag == 0
|
|
860
|
+
return nil
|
|
861
|
+
elsif flag == 1
|
|
862
|
+
return read_TypeAuthRequest
|
|
863
|
+
else
|
|
864
|
+
raise InternalError, 'Unexpected flag byte for OptionalTypeAuthRequest'
|
|
865
|
+
end
|
|
866
|
+
end
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
# The Optional<T> type for TypeBrokerTlsConfig.
|
|
870
|
+
|
|
871
|
+
def read_OptionalTypeBrokerTlsConfig
|
|
872
|
+
flag = unpack_from 1, 'c'
|
|
873
|
+
|
|
874
|
+
if flag == 0
|
|
875
|
+
return nil
|
|
876
|
+
elsif flag == 1
|
|
877
|
+
return read_TypeBrokerTlsConfig
|
|
878
|
+
else
|
|
879
|
+
raise InternalError, 'Unexpected flag byte for OptionalTypeBrokerTlsConfig'
|
|
880
|
+
end
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
# The Optional<T> type for TypeBrokerEvent.
|
|
885
|
+
|
|
886
|
+
def read_OptionalTypeBrokerEvent
|
|
887
|
+
flag = unpack_from 1, 'c'
|
|
888
|
+
|
|
889
|
+
if flag == 0
|
|
890
|
+
return nil
|
|
891
|
+
elsif flag == 1
|
|
892
|
+
return read_TypeBrokerEvent
|
|
893
|
+
else
|
|
894
|
+
raise InternalError, 'Unexpected flag byte for OptionalTypeBrokerEvent'
|
|
895
|
+
end
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
def unpack_from(size, format)
|
|
901
|
+
raise InternalError, 'read past end of rust buffer' if @offset + size > @rbuf.len
|
|
902
|
+
|
|
903
|
+
value = @rbuf.data.get_bytes(@offset, size).unpack format
|
|
904
|
+
|
|
905
|
+
@offset += size
|
|
906
|
+
|
|
907
|
+
# TODO: verify this
|
|
908
|
+
raise 'more than one element!!!' if value.size > 1
|
|
909
|
+
|
|
910
|
+
value[0]
|
|
911
|
+
end
|
|
912
|
+
end
|
|
913
|
+
|
|
914
|
+
private_constant :RustBufferStream
|
|
915
|
+
|
|
916
|
+
# Helper for structured writing of values into a RustBuffer.
|
|
917
|
+
class RustBufferBuilder
|
|
918
|
+
def initialize
|
|
919
|
+
@rust_buf = RustBuffer.alloc 16
|
|
920
|
+
@rust_buf.len = 0
|
|
921
|
+
end
|
|
922
|
+
|
|
923
|
+
def finalize
|
|
924
|
+
rbuf = @rust_buf
|
|
925
|
+
|
|
926
|
+
@rust_buf = nil
|
|
927
|
+
|
|
928
|
+
rbuf
|
|
929
|
+
end
|
|
930
|
+
|
|
931
|
+
def discard
|
|
932
|
+
return if @rust_buf.nil?
|
|
933
|
+
|
|
934
|
+
rbuf = finalize
|
|
935
|
+
rbuf.free
|
|
936
|
+
end
|
|
937
|
+
|
|
938
|
+
def write(value)
|
|
939
|
+
reserve(value.bytes.size) do
|
|
940
|
+
@rust_buf.data.put_array_of_char @rust_buf.len, value.bytes
|
|
941
|
+
end
|
|
942
|
+
end
|
|
943
|
+
|
|
944
|
+
def write_u16(v)
|
|
945
|
+
v = ::MqttBroker::uniffi_in_range(v, "u16", 0, 2**16)
|
|
946
|
+
pack_into(2, 'S>', v)
|
|
947
|
+
end
|
|
948
|
+
|
|
949
|
+
def write_u32(v)
|
|
950
|
+
v = ::MqttBroker::uniffi_in_range(v, "u32", 0, 2**32)
|
|
951
|
+
pack_into(4, 'L>', v)
|
|
952
|
+
end
|
|
953
|
+
|
|
954
|
+
def write_u64(v)
|
|
955
|
+
v = ::MqttBroker::uniffi_in_range(v, "u64", 0, 2**64)
|
|
956
|
+
pack_into(8, 'Q>', v)
|
|
957
|
+
end
|
|
958
|
+
|
|
959
|
+
def write_bool(v)
|
|
960
|
+
pack_into(1, 'c', v ? 1 : 0)
|
|
961
|
+
end
|
|
962
|
+
|
|
963
|
+
def write_string(v)
|
|
964
|
+
v = ::MqttBroker::uniffi_utf8(v)
|
|
965
|
+
pack_into 4, 'l>', v.bytes.size
|
|
966
|
+
write v
|
|
967
|
+
end
|
|
968
|
+
|
|
969
|
+
def write_bytes(v)
|
|
970
|
+
v = ::MqttBroker::uniffi_bytes(v)
|
|
971
|
+
pack_into 4, 'l>', v.bytes.size
|
|
972
|
+
write v
|
|
973
|
+
end
|
|
974
|
+
|
|
975
|
+
# The Object type MqttAuthProvider.
|
|
976
|
+
|
|
977
|
+
def write_TypeMqttAuthProvider(obj)
|
|
978
|
+
handle = MqttAuthProvider.uniffi_lower obj
|
|
979
|
+
pack_into(8, 'Q>', handle)
|
|
980
|
+
end
|
|
981
|
+
|
|
982
|
+
# The Object type MqttBroker.
|
|
983
|
+
|
|
984
|
+
def write_TypeMqttBroker(obj)
|
|
985
|
+
handle = MqttBroker.uniffi_lower obj
|
|
986
|
+
pack_into(8, 'Q>', handle)
|
|
987
|
+
end
|
|
988
|
+
|
|
989
|
+
# The Object type MqttBrokerEventListener.
|
|
990
|
+
|
|
991
|
+
def write_TypeMqttBrokerEventListener(obj)
|
|
992
|
+
handle = MqttBrokerEventListener.uniffi_lower obj
|
|
993
|
+
pack_into(8, 'Q>', handle)
|
|
994
|
+
end
|
|
995
|
+
|
|
996
|
+
# The Object type MqttEnhancedAuthProvider.
|
|
997
|
+
|
|
998
|
+
def write_TypeMqttEnhancedAuthProvider(obj)
|
|
999
|
+
handle = MqttEnhancedAuthProvider.uniffi_lower obj
|
|
1000
|
+
pack_into(8, 'Q>', handle)
|
|
1001
|
+
end
|
|
1002
|
+
|
|
1003
|
+
# The Record type AuthRequest.
|
|
1004
|
+
|
|
1005
|
+
def write_TypeAuthRequest(v)
|
|
1006
|
+
self.write_u64(v.id)
|
|
1007
|
+
self.write_string(v.client_id)
|
|
1008
|
+
self.write_Optionalstring(v.username)
|
|
1009
|
+
self.write_Optionalbytes(v.password)
|
|
1010
|
+
end
|
|
1011
|
+
|
|
1012
|
+
# The Record type BrokerTlsConfig.
|
|
1013
|
+
|
|
1014
|
+
def write_TypeBrokerTlsConfig(v)
|
|
1015
|
+
self.write_u16(v.port)
|
|
1016
|
+
self.write_bytes(v.cert_pem)
|
|
1017
|
+
self.write_bytes(v.key_pem)
|
|
1018
|
+
self.write_Optionalbytes(v.client_ca_pem)
|
|
1019
|
+
end
|
|
1020
|
+
|
|
1021
|
+
# The Record type EnhancedAuthStep.
|
|
1022
|
+
|
|
1023
|
+
def write_TypeEnhancedAuthStep(v)
|
|
1024
|
+
self.write_TypeEnhancedAuthOutcome(v.outcome)
|
|
1025
|
+
self.write_bytes(v.data)
|
|
1026
|
+
end
|
|
1027
|
+
|
|
1028
|
+
# The Record type MqttBrokerConfig.
|
|
1029
|
+
|
|
1030
|
+
def write_TypeMqttBrokerConfig(v)
|
|
1031
|
+
self.write_string(v.bind_address)
|
|
1032
|
+
self.write_u16(v.port)
|
|
1033
|
+
self.write_Optionalu16(v.ws_port)
|
|
1034
|
+
self.write_bool(v.allow_anonymous)
|
|
1035
|
+
self.write_u32(v.max_clients)
|
|
1036
|
+
self.write_TypeQoS(v.max_qos)
|
|
1037
|
+
self.write_u32(v.max_retained_messages)
|
|
1038
|
+
self.write_u32(v.max_queued_per_client)
|
|
1039
|
+
self.write_u32(v.redelivery_interval_secs)
|
|
1040
|
+
self.write_OptionalTypeBrokerTlsConfig(v.tls)
|
|
1041
|
+
self.write_u32(v.max_packet_size)
|
|
1042
|
+
self.write_u32(v.max_outbound_queue)
|
|
1043
|
+
self.write_u32(v.session_expiry_secs)
|
|
1044
|
+
end
|
|
1045
|
+
|
|
1046
|
+
# The Enum type BrokerEvent.
|
|
1047
|
+
|
|
1048
|
+
def write_TypeBrokerEvent(v)
|
|
1049
|
+
if v.client_connected?
|
|
1050
|
+
pack_into(4, 'l>', 1)
|
|
1051
|
+
self.write_string(v.client_id)
|
|
1052
|
+
end
|
|
1053
|
+
if v.client_disconnected?
|
|
1054
|
+
pack_into(4, 'l>', 2)
|
|
1055
|
+
self.write_string(v.client_id)
|
|
1056
|
+
self.write_string(v.reason)
|
|
1057
|
+
end
|
|
1058
|
+
if v.message_published?
|
|
1059
|
+
pack_into(4, 'l>', 3)
|
|
1060
|
+
self.write_string(v.client_id)
|
|
1061
|
+
self.write_string(v.topic)
|
|
1062
|
+
self.write_TypeQoS(v.qos)
|
|
1063
|
+
end
|
|
1064
|
+
end
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
# The Enum type EnhancedAuthOutcome.
|
|
1068
|
+
|
|
1069
|
+
def write_TypeEnhancedAuthOutcome(v)
|
|
1070
|
+
if v == EnhancedAuthOutcome::CONTINUE
|
|
1071
|
+
pack_into(4, 'l>', 1)
|
|
1072
|
+
end
|
|
1073
|
+
if v == EnhancedAuthOutcome::SUCCESS
|
|
1074
|
+
pack_into(4, 'l>', 2)
|
|
1075
|
+
end
|
|
1076
|
+
if v == EnhancedAuthOutcome::FAILURE
|
|
1077
|
+
pack_into(4, 'l>', 3)
|
|
1078
|
+
end
|
|
1079
|
+
end
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
# The Error type MqttBrokerError - write for callback error returns.
|
|
1083
|
+
|
|
1084
|
+
def write_TypeMqttBrokerError(v)
|
|
1085
|
+
if v.is_a?(MqttBrokerError::AlreadyRunning)
|
|
1086
|
+
pack_into 4, 'l>', 1
|
|
1087
|
+
return
|
|
1088
|
+
end
|
|
1089
|
+
if v.is_a?(MqttBrokerError::Io)
|
|
1090
|
+
pack_into 4, 'l>', 2
|
|
1091
|
+
return
|
|
1092
|
+
end
|
|
1093
|
+
if v.is_a?(MqttBrokerError::Tls)
|
|
1094
|
+
pack_into 4, 'l>', 3
|
|
1095
|
+
return
|
|
1096
|
+
end
|
|
1097
|
+
end
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
# The Enum type QoS.
|
|
1101
|
+
|
|
1102
|
+
def write_TypeQoS(v)
|
|
1103
|
+
if v == QoS::AT_MOST_ONCE
|
|
1104
|
+
pack_into(4, 'l>', 1)
|
|
1105
|
+
end
|
|
1106
|
+
if v == QoS::AT_LEAST_ONCE
|
|
1107
|
+
pack_into(4, 'l>', 2)
|
|
1108
|
+
end
|
|
1109
|
+
if v == QoS::EXACTLY_ONCE
|
|
1110
|
+
pack_into(4, 'l>', 3)
|
|
1111
|
+
end
|
|
1112
|
+
end
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
# The Optional<T> type for u16.
|
|
1116
|
+
|
|
1117
|
+
def write_Optionalu16(v)
|
|
1118
|
+
if v.nil?
|
|
1119
|
+
pack_into(1, 'c', 0)
|
|
1120
|
+
else
|
|
1121
|
+
pack_into(1, 'c', 1)
|
|
1122
|
+
self.write_u16(v)
|
|
1123
|
+
end
|
|
1124
|
+
end
|
|
1125
|
+
|
|
1126
|
+
# The Optional<T> type for string.
|
|
1127
|
+
|
|
1128
|
+
def write_Optionalstring(v)
|
|
1129
|
+
if v.nil?
|
|
1130
|
+
pack_into(1, 'c', 0)
|
|
1131
|
+
else
|
|
1132
|
+
pack_into(1, 'c', 1)
|
|
1133
|
+
self.write_string(v)
|
|
1134
|
+
end
|
|
1135
|
+
end
|
|
1136
|
+
|
|
1137
|
+
# The Optional<T> type for bytes.
|
|
1138
|
+
|
|
1139
|
+
def write_Optionalbytes(v)
|
|
1140
|
+
if v.nil?
|
|
1141
|
+
pack_into(1, 'c', 0)
|
|
1142
|
+
else
|
|
1143
|
+
pack_into(1, 'c', 1)
|
|
1144
|
+
self.write_bytes(v)
|
|
1145
|
+
end
|
|
1146
|
+
end
|
|
1147
|
+
|
|
1148
|
+
# The Optional<T> type for TypeAuthRequest.
|
|
1149
|
+
|
|
1150
|
+
def write_OptionalTypeAuthRequest(v)
|
|
1151
|
+
if v.nil?
|
|
1152
|
+
pack_into(1, 'c', 0)
|
|
1153
|
+
else
|
|
1154
|
+
pack_into(1, 'c', 1)
|
|
1155
|
+
self.write_TypeAuthRequest(v)
|
|
1156
|
+
end
|
|
1157
|
+
end
|
|
1158
|
+
|
|
1159
|
+
# The Optional<T> type for TypeBrokerTlsConfig.
|
|
1160
|
+
|
|
1161
|
+
def write_OptionalTypeBrokerTlsConfig(v)
|
|
1162
|
+
if v.nil?
|
|
1163
|
+
pack_into(1, 'c', 0)
|
|
1164
|
+
else
|
|
1165
|
+
pack_into(1, 'c', 1)
|
|
1166
|
+
self.write_TypeBrokerTlsConfig(v)
|
|
1167
|
+
end
|
|
1168
|
+
end
|
|
1169
|
+
|
|
1170
|
+
# The Optional<T> type for TypeBrokerEvent.
|
|
1171
|
+
|
|
1172
|
+
def write_OptionalTypeBrokerEvent(v)
|
|
1173
|
+
if v.nil?
|
|
1174
|
+
pack_into(1, 'c', 0)
|
|
1175
|
+
else
|
|
1176
|
+
pack_into(1, 'c', 1)
|
|
1177
|
+
self.write_TypeBrokerEvent(v)
|
|
1178
|
+
end
|
|
1179
|
+
end
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
private
|
|
1184
|
+
|
|
1185
|
+
def reserve(num_bytes)
|
|
1186
|
+
if @rust_buf.len + num_bytes > @rust_buf.capacity
|
|
1187
|
+
@rust_buf = RustBuffer.reserve(@rust_buf, num_bytes)
|
|
1188
|
+
end
|
|
1189
|
+
|
|
1190
|
+
yield
|
|
1191
|
+
|
|
1192
|
+
@rust_buf.len += num_bytes
|
|
1193
|
+
end
|
|
1194
|
+
|
|
1195
|
+
def pack_into(size, format, value)
|
|
1196
|
+
reserve(size) do
|
|
1197
|
+
@rust_buf.data.put_array_of_char @rust_buf.len, [value].pack(format).bytes
|
|
1198
|
+
end
|
|
1199
|
+
end
|
|
1200
|
+
end
|
|
1201
|
+
|
|
1202
|
+
private_constant :RustBufferBuilder
|
|
1203
|
+
|
|
1204
|
+
# Error definitions
|
|
1205
|
+
class RustCallStatus < FFI::Struct
|
|
1206
|
+
layout :code, :int8,
|
|
1207
|
+
:error_buf, RustBuffer
|
|
1208
|
+
|
|
1209
|
+
def code
|
|
1210
|
+
self[:code]
|
|
1211
|
+
end
|
|
1212
|
+
|
|
1213
|
+
def error_buf
|
|
1214
|
+
self[:error_buf]
|
|
1215
|
+
end
|
|
1216
|
+
|
|
1217
|
+
def to_s
|
|
1218
|
+
"RustCallStatus(code=#{self[:code]})"
|
|
1219
|
+
end
|
|
1220
|
+
end
|
|
1221
|
+
|
|
1222
|
+
# These match the values from the uniffi::rustcalls module
|
|
1223
|
+
CALL_SUCCESS = 0
|
|
1224
|
+
CALL_ERROR = 1
|
|
1225
|
+
CALL_PANIC = 2
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
class MqttBrokerError
|
|
1231
|
+
AlreadyRunning = Class.new StandardError
|
|
1232
|
+
Io = Class.new StandardError
|
|
1233
|
+
Tls = Class.new StandardError
|
|
1234
|
+
|
|
1235
|
+
end
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
# Map error modules to the RustBuffer method name that reads them
|
|
1240
|
+
ERROR_MODULE_TO_READER_METHOD = {
|
|
1241
|
+
MqttBrokerError => :read_TypeMqttBrokerError,
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
private_constant :ERROR_MODULE_TO_READER_METHOD, :CALL_SUCCESS, :CALL_ERROR, :CALL_PANIC,
|
|
1245
|
+
:RustCallStatus
|
|
1246
|
+
|
|
1247
|
+
def self.consume_buffer_into_error(error_module, rust_buffer)
|
|
1248
|
+
rust_buffer.consumeWithStream do |stream|
|
|
1249
|
+
reader_method = ERROR_MODULE_TO_READER_METHOD[error_module] ||
|
|
1250
|
+
ERROR_MODULE_TO_READER_METHOD[error_module.name&.split('::')&.last]
|
|
1251
|
+
return stream.send(reader_method)
|
|
1252
|
+
end
|
|
1253
|
+
end
|
|
1254
|
+
|
|
1255
|
+
class InternalError < StandardError
|
|
1256
|
+
end
|
|
1257
|
+
|
|
1258
|
+
def self.rust_call(fn_name, *args)
|
|
1259
|
+
# Call a rust function
|
|
1260
|
+
rust_call_with_error(nil, fn_name, *args)
|
|
1261
|
+
end
|
|
1262
|
+
|
|
1263
|
+
def self.rust_call_with_error(error_module, fn_name, *args)
|
|
1264
|
+
# Call a rust function and handle errors
|
|
1265
|
+
#
|
|
1266
|
+
# Use this when the rust function returns a Result<>. error_module must be the error_module that corresponds to that Result.
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
# Note: RustCallStatus.new zeroes out the struct, which is exactly what we
|
|
1270
|
+
# want to pass to Rust (code=0, error_buf=RustBuffer(len=0, capacity=0,
|
|
1271
|
+
# data=NULL))
|
|
1272
|
+
status = RustCallStatus.new
|
|
1273
|
+
args << status
|
|
1274
|
+
|
|
1275
|
+
result = UniFFILib.public_send(fn_name, *args)
|
|
1276
|
+
|
|
1277
|
+
case status.code
|
|
1278
|
+
when CALL_SUCCESS
|
|
1279
|
+
result
|
|
1280
|
+
when CALL_ERROR
|
|
1281
|
+
if error_module.nil?
|
|
1282
|
+
status.error_buf.free
|
|
1283
|
+
raise InternalError, "CALL_ERROR with no error_module set"
|
|
1284
|
+
else
|
|
1285
|
+
raise consume_buffer_into_error(error_module, status.error_buf)
|
|
1286
|
+
end
|
|
1287
|
+
when CALL_PANIC
|
|
1288
|
+
# When the rust code sees a panic, it tries to construct a RustBuffer
|
|
1289
|
+
# with the message. But if that code panics, then it just sends back
|
|
1290
|
+
# an empty buffer.
|
|
1291
|
+
if status.error_buf.len > 0
|
|
1292
|
+
raise InternalError, status.error_buf.consume_into_string
|
|
1293
|
+
else
|
|
1294
|
+
raise InternalError, "Rust panic"
|
|
1295
|
+
end
|
|
1296
|
+
else
|
|
1297
|
+
raise InternalError, "Unknown call status: #{status.code}"
|
|
1298
|
+
end
|
|
1299
|
+
end
|
|
1300
|
+
|
|
1301
|
+
private_class_method :consume_buffer_into_error
|
|
1302
|
+
|
|
1303
|
+
# This is how we find and load the dynamic library provided by the component.
|
|
1304
|
+
# For now we just look it up by name.
|
|
1305
|
+
module UniFFILib
|
|
1306
|
+
extend FFI::Library
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
ffi_lib File.expand_path("native/#{FFI.map_library_name('mqtt_broker')}", __dir__)
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
# Define FFI callback types and structs (vtables, etc.)
|
|
1313
|
+
|
|
1314
|
+
callback :RustFutureContinuationCallback,
|
|
1315
|
+
[:uint64, :int8, ],
|
|
1316
|
+
:void
|
|
1317
|
+
|
|
1318
|
+
callback :ForeignFutureDroppedCallback,
|
|
1319
|
+
[:uint64, ],
|
|
1320
|
+
:void
|
|
1321
|
+
|
|
1322
|
+
callback :CallbackInterfaceFree,
|
|
1323
|
+
[:uint64, ],
|
|
1324
|
+
:void
|
|
1325
|
+
|
|
1326
|
+
callback :CallbackInterfaceClone,
|
|
1327
|
+
[:uint64, ],
|
|
1328
|
+
:uint64
|
|
1329
|
+
|
|
1330
|
+
class ForeignFutureDroppedCallbackStruct < FFI::Struct
|
|
1331
|
+
layout(
|
|
1332
|
+
:handle, :uint64,
|
|
1333
|
+
:free, :ForeignFutureDroppedCallback
|
|
1334
|
+
)
|
|
1335
|
+
end
|
|
1336
|
+
|
|
1337
|
+
class ForeignFutureResultU8 < FFI::Struct
|
|
1338
|
+
layout(
|
|
1339
|
+
:return_value, :uint8,
|
|
1340
|
+
:call_status, RustCallStatus
|
|
1341
|
+
)
|
|
1342
|
+
end
|
|
1343
|
+
|
|
1344
|
+
callback :ForeignFutureCompleteU8,
|
|
1345
|
+
[:uint64, ForeignFutureResultU8.by_value, ],
|
|
1346
|
+
:void
|
|
1347
|
+
|
|
1348
|
+
class ForeignFutureResultI8 < FFI::Struct
|
|
1349
|
+
layout(
|
|
1350
|
+
:return_value, :int8,
|
|
1351
|
+
:call_status, RustCallStatus
|
|
1352
|
+
)
|
|
1353
|
+
end
|
|
1354
|
+
|
|
1355
|
+
callback :ForeignFutureCompleteI8,
|
|
1356
|
+
[:uint64, ForeignFutureResultI8.by_value, ],
|
|
1357
|
+
:void
|
|
1358
|
+
|
|
1359
|
+
class ForeignFutureResultU16 < FFI::Struct
|
|
1360
|
+
layout(
|
|
1361
|
+
:return_value, :uint16,
|
|
1362
|
+
:call_status, RustCallStatus
|
|
1363
|
+
)
|
|
1364
|
+
end
|
|
1365
|
+
|
|
1366
|
+
callback :ForeignFutureCompleteU16,
|
|
1367
|
+
[:uint64, ForeignFutureResultU16.by_value, ],
|
|
1368
|
+
:void
|
|
1369
|
+
|
|
1370
|
+
class ForeignFutureResultI16 < FFI::Struct
|
|
1371
|
+
layout(
|
|
1372
|
+
:return_value, :int16,
|
|
1373
|
+
:call_status, RustCallStatus
|
|
1374
|
+
)
|
|
1375
|
+
end
|
|
1376
|
+
|
|
1377
|
+
callback :ForeignFutureCompleteI16,
|
|
1378
|
+
[:uint64, ForeignFutureResultI16.by_value, ],
|
|
1379
|
+
:void
|
|
1380
|
+
|
|
1381
|
+
class ForeignFutureResultU32 < FFI::Struct
|
|
1382
|
+
layout(
|
|
1383
|
+
:return_value, :uint32,
|
|
1384
|
+
:call_status, RustCallStatus
|
|
1385
|
+
)
|
|
1386
|
+
end
|
|
1387
|
+
|
|
1388
|
+
callback :ForeignFutureCompleteU32,
|
|
1389
|
+
[:uint64, ForeignFutureResultU32.by_value, ],
|
|
1390
|
+
:void
|
|
1391
|
+
|
|
1392
|
+
class ForeignFutureResultI32 < FFI::Struct
|
|
1393
|
+
layout(
|
|
1394
|
+
:return_value, :int32,
|
|
1395
|
+
:call_status, RustCallStatus
|
|
1396
|
+
)
|
|
1397
|
+
end
|
|
1398
|
+
|
|
1399
|
+
callback :ForeignFutureCompleteI32,
|
|
1400
|
+
[:uint64, ForeignFutureResultI32.by_value, ],
|
|
1401
|
+
:void
|
|
1402
|
+
|
|
1403
|
+
class ForeignFutureResultU64 < FFI::Struct
|
|
1404
|
+
layout(
|
|
1405
|
+
:return_value, :uint64,
|
|
1406
|
+
:call_status, RustCallStatus
|
|
1407
|
+
)
|
|
1408
|
+
end
|
|
1409
|
+
|
|
1410
|
+
callback :ForeignFutureCompleteU64,
|
|
1411
|
+
[:uint64, ForeignFutureResultU64.by_value, ],
|
|
1412
|
+
:void
|
|
1413
|
+
|
|
1414
|
+
class ForeignFutureResultI64 < FFI::Struct
|
|
1415
|
+
layout(
|
|
1416
|
+
:return_value, :int64,
|
|
1417
|
+
:call_status, RustCallStatus
|
|
1418
|
+
)
|
|
1419
|
+
end
|
|
1420
|
+
|
|
1421
|
+
callback :ForeignFutureCompleteI64,
|
|
1422
|
+
[:uint64, ForeignFutureResultI64.by_value, ],
|
|
1423
|
+
:void
|
|
1424
|
+
|
|
1425
|
+
class ForeignFutureResultF32 < FFI::Struct
|
|
1426
|
+
layout(
|
|
1427
|
+
:return_value, :float,
|
|
1428
|
+
:call_status, RustCallStatus
|
|
1429
|
+
)
|
|
1430
|
+
end
|
|
1431
|
+
|
|
1432
|
+
callback :ForeignFutureCompleteF32,
|
|
1433
|
+
[:uint64, ForeignFutureResultF32.by_value, ],
|
|
1434
|
+
:void
|
|
1435
|
+
|
|
1436
|
+
class ForeignFutureResultF64 < FFI::Struct
|
|
1437
|
+
layout(
|
|
1438
|
+
:return_value, :double,
|
|
1439
|
+
:call_status, RustCallStatus
|
|
1440
|
+
)
|
|
1441
|
+
end
|
|
1442
|
+
|
|
1443
|
+
callback :ForeignFutureCompleteF64,
|
|
1444
|
+
[:uint64, ForeignFutureResultF64.by_value, ],
|
|
1445
|
+
:void
|
|
1446
|
+
|
|
1447
|
+
class ForeignFutureResultRustBuffer < FFI::Struct
|
|
1448
|
+
layout(
|
|
1449
|
+
:return_value, RustBuffer.by_value,
|
|
1450
|
+
:call_status, RustCallStatus
|
|
1451
|
+
)
|
|
1452
|
+
end
|
|
1453
|
+
|
|
1454
|
+
callback :ForeignFutureCompleteRustBuffer,
|
|
1455
|
+
[:uint64, ForeignFutureResultRustBuffer.by_value, ],
|
|
1456
|
+
:void
|
|
1457
|
+
|
|
1458
|
+
class ForeignFutureResultVoid < FFI::Struct
|
|
1459
|
+
layout(
|
|
1460
|
+
:call_status, RustCallStatus
|
|
1461
|
+
)
|
|
1462
|
+
end
|
|
1463
|
+
|
|
1464
|
+
callback :ForeignFutureCompleteVoid,
|
|
1465
|
+
[:uint64, ForeignFutureResultVoid.by_value, ],
|
|
1466
|
+
:void
|
|
1467
|
+
|
|
1468
|
+
callback :CallbackInterfaceMqttAuthProviderMethod0,
|
|
1469
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
|
|
1470
|
+
:void
|
|
1471
|
+
|
|
1472
|
+
callback :CallbackInterfaceMqttBrokerEventListenerMethod0,
|
|
1473
|
+
[:uint64, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
|
|
1474
|
+
:void
|
|
1475
|
+
|
|
1476
|
+
callback :CallbackInterfaceMqttBrokerEventListenerMethod1,
|
|
1477
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
|
|
1478
|
+
:void
|
|
1479
|
+
|
|
1480
|
+
callback :CallbackInterfaceMqttBrokerEventListenerMethod2,
|
|
1481
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :pointer, RustCallStatus.by_ref],
|
|
1482
|
+
:void
|
|
1483
|
+
|
|
1484
|
+
callback :CallbackInterfaceMqttEnhancedAuthProviderMethod0,
|
|
1485
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :uint32, :pointer, RustCallStatus.by_ref],
|
|
1486
|
+
:void
|
|
1487
|
+
|
|
1488
|
+
class VTableCallbackInterfaceMqttAuthProvider < FFI::Struct
|
|
1489
|
+
layout(
|
|
1490
|
+
:uniffi_free, :CallbackInterfaceFree,
|
|
1491
|
+
:uniffi_clone, :CallbackInterfaceClone,
|
|
1492
|
+
:authenticate, :CallbackInterfaceMqttAuthProviderMethod0
|
|
1493
|
+
)
|
|
1494
|
+
end
|
|
1495
|
+
|
|
1496
|
+
class VTableCallbackInterfaceMqttBrokerEventListener < FFI::Struct
|
|
1497
|
+
layout(
|
|
1498
|
+
:uniffi_free, :CallbackInterfaceFree,
|
|
1499
|
+
:uniffi_clone, :CallbackInterfaceClone,
|
|
1500
|
+
:on_client_connected, :CallbackInterfaceMqttBrokerEventListenerMethod0,
|
|
1501
|
+
:on_client_disconnected, :CallbackInterfaceMqttBrokerEventListenerMethod1,
|
|
1502
|
+
:on_message_published, :CallbackInterfaceMqttBrokerEventListenerMethod2
|
|
1503
|
+
)
|
|
1504
|
+
end
|
|
1505
|
+
|
|
1506
|
+
class VTableCallbackInterfaceMqttEnhancedAuthProvider < FFI::Struct
|
|
1507
|
+
layout(
|
|
1508
|
+
:uniffi_free, :CallbackInterfaceFree,
|
|
1509
|
+
:uniffi_clone, :CallbackInterfaceClone,
|
|
1510
|
+
:step, :CallbackInterfaceMqttEnhancedAuthProviderMethod0
|
|
1511
|
+
)
|
|
1512
|
+
end
|
|
1513
|
+
|
|
1514
|
+
attach_function :uniffi_mqtt_broker_fn_clone_mqttbroker,
|
|
1515
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1516
|
+
:uint64
|
|
1517
|
+
|
|
1518
|
+
attach_function :uniffi_mqtt_broker_fn_free_mqttbroker,
|
|
1519
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1520
|
+
:void
|
|
1521
|
+
|
|
1522
|
+
attach_function :uniffi_mqtt_broker_fn_constructor_mqttbroker_new,
|
|
1523
|
+
[RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1524
|
+
:uint64
|
|
1525
|
+
|
|
1526
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_bound_port,
|
|
1527
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1528
|
+
RustBuffer.by_value
|
|
1529
|
+
|
|
1530
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_bound_tls_port,
|
|
1531
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1532
|
+
RustBuffer.by_value
|
|
1533
|
+
|
|
1534
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_bound_ws_port,
|
|
1535
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1536
|
+
RustBuffer.by_value
|
|
1537
|
+
|
|
1538
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_client_count,
|
|
1539
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1540
|
+
:uint32
|
|
1541
|
+
|
|
1542
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_enable_auth_queue,
|
|
1543
|
+
[:uint64, :uint32, RustCallStatus.by_ref],
|
|
1544
|
+
:void
|
|
1545
|
+
|
|
1546
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_enable_event_queue,
|
|
1547
|
+
[:uint64, :uint32, RustCallStatus.by_ref],
|
|
1548
|
+
:void
|
|
1549
|
+
|
|
1550
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_is_running,
|
|
1551
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1552
|
+
:int8
|
|
1553
|
+
|
|
1554
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_next_auth_request,
|
|
1555
|
+
[:uint64, :uint32, ],
|
|
1556
|
+
:uint64
|
|
1557
|
+
|
|
1558
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_next_event,
|
|
1559
|
+
[:uint64, :uint32, ],
|
|
1560
|
+
:uint64
|
|
1561
|
+
|
|
1562
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_resolve_auth_request,
|
|
1563
|
+
[:uint64, :uint64, :int8, RustCallStatus.by_ref],
|
|
1564
|
+
:int8
|
|
1565
|
+
|
|
1566
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_set_auth_provider,
|
|
1567
|
+
[:uint64, :uint64, RustCallStatus.by_ref],
|
|
1568
|
+
:void
|
|
1569
|
+
|
|
1570
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_set_enhanced_auth_provider,
|
|
1571
|
+
[:uint64, :uint64, RustCallStatus.by_ref],
|
|
1572
|
+
:void
|
|
1573
|
+
|
|
1574
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_set_event_listener,
|
|
1575
|
+
[:uint64, :uint64, RustCallStatus.by_ref],
|
|
1576
|
+
:void
|
|
1577
|
+
|
|
1578
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_start,
|
|
1579
|
+
[:uint64, ],
|
|
1580
|
+
:uint64
|
|
1581
|
+
|
|
1582
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbroker_stop,
|
|
1583
|
+
[:uint64, ],
|
|
1584
|
+
:uint64
|
|
1585
|
+
|
|
1586
|
+
attach_function :uniffi_mqtt_broker_fn_clone_mqttauthprovider,
|
|
1587
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1588
|
+
:uint64
|
|
1589
|
+
|
|
1590
|
+
attach_function :uniffi_mqtt_broker_fn_free_mqttauthprovider,
|
|
1591
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1592
|
+
:void
|
|
1593
|
+
|
|
1594
|
+
attach_function :uniffi_mqtt_broker_fn_init_callback_vtable_mqttauthprovider,
|
|
1595
|
+
[VTableCallbackInterfaceMqttAuthProvider.by_ref, ],
|
|
1596
|
+
:void
|
|
1597
|
+
|
|
1598
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttauthprovider_authenticate,
|
|
1599
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1600
|
+
:int8
|
|
1601
|
+
|
|
1602
|
+
attach_function :uniffi_mqtt_broker_fn_clone_mqttbrokereventlistener,
|
|
1603
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1604
|
+
:uint64
|
|
1605
|
+
|
|
1606
|
+
attach_function :uniffi_mqtt_broker_fn_free_mqttbrokereventlistener,
|
|
1607
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1608
|
+
:void
|
|
1609
|
+
|
|
1610
|
+
attach_function :uniffi_mqtt_broker_fn_init_callback_vtable_mqttbrokereventlistener,
|
|
1611
|
+
[VTableCallbackInterfaceMqttBrokerEventListener.by_ref, ],
|
|
1612
|
+
:void
|
|
1613
|
+
|
|
1614
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_client_connected,
|
|
1615
|
+
[:uint64, RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1616
|
+
:void
|
|
1617
|
+
|
|
1618
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_client_disconnected,
|
|
1619
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1620
|
+
:void
|
|
1621
|
+
|
|
1622
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_message_published,
|
|
1623
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1624
|
+
:void
|
|
1625
|
+
|
|
1626
|
+
attach_function :uniffi_mqtt_broker_fn_clone_mqttenhancedauthprovider,
|
|
1627
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1628
|
+
:uint64
|
|
1629
|
+
|
|
1630
|
+
attach_function :uniffi_mqtt_broker_fn_free_mqttenhancedauthprovider,
|
|
1631
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1632
|
+
:void
|
|
1633
|
+
|
|
1634
|
+
attach_function :uniffi_mqtt_broker_fn_init_callback_vtable_mqttenhancedauthprovider,
|
|
1635
|
+
[VTableCallbackInterfaceMqttEnhancedAuthProvider.by_ref, ],
|
|
1636
|
+
:void
|
|
1637
|
+
|
|
1638
|
+
attach_function :uniffi_mqtt_broker_fn_method_mqttenhancedauthprovider_step,
|
|
1639
|
+
[:uint64, RustBuffer.by_value, RustBuffer.by_value, RustBuffer.by_value, :uint32, RustCallStatus.by_ref],
|
|
1640
|
+
RustBuffer.by_value
|
|
1641
|
+
|
|
1642
|
+
attach_function :ffi_mqtt_broker_rustbuffer_alloc,
|
|
1643
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1644
|
+
RustBuffer.by_value
|
|
1645
|
+
|
|
1646
|
+
attach_function :ffi_mqtt_broker_rustbuffer_from_bytes,
|
|
1647
|
+
[ForeignBytes, RustCallStatus.by_ref],
|
|
1648
|
+
RustBuffer.by_value
|
|
1649
|
+
|
|
1650
|
+
attach_function :ffi_mqtt_broker_rustbuffer_free,
|
|
1651
|
+
[RustBuffer.by_value, RustCallStatus.by_ref],
|
|
1652
|
+
:void
|
|
1653
|
+
|
|
1654
|
+
attach_function :ffi_mqtt_broker_rustbuffer_reserve,
|
|
1655
|
+
[RustBuffer.by_value, :uint64, RustCallStatus.by_ref],
|
|
1656
|
+
RustBuffer.by_value
|
|
1657
|
+
|
|
1658
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_u8,
|
|
1659
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1660
|
+
:void
|
|
1661
|
+
|
|
1662
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_u8,
|
|
1663
|
+
[:uint64, ],
|
|
1664
|
+
:void
|
|
1665
|
+
|
|
1666
|
+
attach_function :ffi_mqtt_broker_rust_future_free_u8,
|
|
1667
|
+
[:uint64, ],
|
|
1668
|
+
:void
|
|
1669
|
+
|
|
1670
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_u8,
|
|
1671
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1672
|
+
:uint8
|
|
1673
|
+
|
|
1674
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_i8,
|
|
1675
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1676
|
+
:void
|
|
1677
|
+
|
|
1678
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_i8,
|
|
1679
|
+
[:uint64, ],
|
|
1680
|
+
:void
|
|
1681
|
+
|
|
1682
|
+
attach_function :ffi_mqtt_broker_rust_future_free_i8,
|
|
1683
|
+
[:uint64, ],
|
|
1684
|
+
:void
|
|
1685
|
+
|
|
1686
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_i8,
|
|
1687
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1688
|
+
:int8
|
|
1689
|
+
|
|
1690
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_u16,
|
|
1691
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1692
|
+
:void
|
|
1693
|
+
|
|
1694
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_u16,
|
|
1695
|
+
[:uint64, ],
|
|
1696
|
+
:void
|
|
1697
|
+
|
|
1698
|
+
attach_function :ffi_mqtt_broker_rust_future_free_u16,
|
|
1699
|
+
[:uint64, ],
|
|
1700
|
+
:void
|
|
1701
|
+
|
|
1702
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_u16,
|
|
1703
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1704
|
+
:uint16
|
|
1705
|
+
|
|
1706
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_i16,
|
|
1707
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1708
|
+
:void
|
|
1709
|
+
|
|
1710
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_i16,
|
|
1711
|
+
[:uint64, ],
|
|
1712
|
+
:void
|
|
1713
|
+
|
|
1714
|
+
attach_function :ffi_mqtt_broker_rust_future_free_i16,
|
|
1715
|
+
[:uint64, ],
|
|
1716
|
+
:void
|
|
1717
|
+
|
|
1718
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_i16,
|
|
1719
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1720
|
+
:int16
|
|
1721
|
+
|
|
1722
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_u32,
|
|
1723
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1724
|
+
:void
|
|
1725
|
+
|
|
1726
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_u32,
|
|
1727
|
+
[:uint64, ],
|
|
1728
|
+
:void
|
|
1729
|
+
|
|
1730
|
+
attach_function :ffi_mqtt_broker_rust_future_free_u32,
|
|
1731
|
+
[:uint64, ],
|
|
1732
|
+
:void
|
|
1733
|
+
|
|
1734
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_u32,
|
|
1735
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1736
|
+
:uint32
|
|
1737
|
+
|
|
1738
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_i32,
|
|
1739
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1740
|
+
:void
|
|
1741
|
+
|
|
1742
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_i32,
|
|
1743
|
+
[:uint64, ],
|
|
1744
|
+
:void
|
|
1745
|
+
|
|
1746
|
+
attach_function :ffi_mqtt_broker_rust_future_free_i32,
|
|
1747
|
+
[:uint64, ],
|
|
1748
|
+
:void
|
|
1749
|
+
|
|
1750
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_i32,
|
|
1751
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1752
|
+
:int32
|
|
1753
|
+
|
|
1754
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_u64,
|
|
1755
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1756
|
+
:void
|
|
1757
|
+
|
|
1758
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_u64,
|
|
1759
|
+
[:uint64, ],
|
|
1760
|
+
:void
|
|
1761
|
+
|
|
1762
|
+
attach_function :ffi_mqtt_broker_rust_future_free_u64,
|
|
1763
|
+
[:uint64, ],
|
|
1764
|
+
:void
|
|
1765
|
+
|
|
1766
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_u64,
|
|
1767
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1768
|
+
:uint64
|
|
1769
|
+
|
|
1770
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_i64,
|
|
1771
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1772
|
+
:void
|
|
1773
|
+
|
|
1774
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_i64,
|
|
1775
|
+
[:uint64, ],
|
|
1776
|
+
:void
|
|
1777
|
+
|
|
1778
|
+
attach_function :ffi_mqtt_broker_rust_future_free_i64,
|
|
1779
|
+
[:uint64, ],
|
|
1780
|
+
:void
|
|
1781
|
+
|
|
1782
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_i64,
|
|
1783
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1784
|
+
:int64
|
|
1785
|
+
|
|
1786
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_f32,
|
|
1787
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1788
|
+
:void
|
|
1789
|
+
|
|
1790
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_f32,
|
|
1791
|
+
[:uint64, ],
|
|
1792
|
+
:void
|
|
1793
|
+
|
|
1794
|
+
attach_function :ffi_mqtt_broker_rust_future_free_f32,
|
|
1795
|
+
[:uint64, ],
|
|
1796
|
+
:void
|
|
1797
|
+
|
|
1798
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_f32,
|
|
1799
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1800
|
+
:float
|
|
1801
|
+
|
|
1802
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_f64,
|
|
1803
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1804
|
+
:void
|
|
1805
|
+
|
|
1806
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_f64,
|
|
1807
|
+
[:uint64, ],
|
|
1808
|
+
:void
|
|
1809
|
+
|
|
1810
|
+
attach_function :ffi_mqtt_broker_rust_future_free_f64,
|
|
1811
|
+
[:uint64, ],
|
|
1812
|
+
:void
|
|
1813
|
+
|
|
1814
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_f64,
|
|
1815
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1816
|
+
:double
|
|
1817
|
+
|
|
1818
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_rust_buffer,
|
|
1819
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1820
|
+
:void
|
|
1821
|
+
|
|
1822
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_rust_buffer,
|
|
1823
|
+
[:uint64, ],
|
|
1824
|
+
:void
|
|
1825
|
+
|
|
1826
|
+
attach_function :ffi_mqtt_broker_rust_future_free_rust_buffer,
|
|
1827
|
+
[:uint64, ],
|
|
1828
|
+
:void
|
|
1829
|
+
|
|
1830
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_rust_buffer,
|
|
1831
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1832
|
+
RustBuffer.by_value
|
|
1833
|
+
|
|
1834
|
+
attach_function :ffi_mqtt_broker_rust_future_poll_void,
|
|
1835
|
+
[:uint64, :RustFutureContinuationCallback, :uint64, ],
|
|
1836
|
+
:void
|
|
1837
|
+
|
|
1838
|
+
attach_function :ffi_mqtt_broker_rust_future_cancel_void,
|
|
1839
|
+
[:uint64, ],
|
|
1840
|
+
:void
|
|
1841
|
+
|
|
1842
|
+
attach_function :ffi_mqtt_broker_rust_future_free_void,
|
|
1843
|
+
[:uint64, ],
|
|
1844
|
+
:void
|
|
1845
|
+
|
|
1846
|
+
attach_function :ffi_mqtt_broker_rust_future_complete_void,
|
|
1847
|
+
[:uint64, RustCallStatus.by_ref],
|
|
1848
|
+
:void
|
|
1849
|
+
|
|
1850
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_bound_port,
|
|
1851
|
+
[],
|
|
1852
|
+
:uint16
|
|
1853
|
+
|
|
1854
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_bound_tls_port,
|
|
1855
|
+
[],
|
|
1856
|
+
:uint16
|
|
1857
|
+
|
|
1858
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_bound_ws_port,
|
|
1859
|
+
[],
|
|
1860
|
+
:uint16
|
|
1861
|
+
|
|
1862
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_client_count,
|
|
1863
|
+
[],
|
|
1864
|
+
:uint16
|
|
1865
|
+
|
|
1866
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_enable_auth_queue,
|
|
1867
|
+
[],
|
|
1868
|
+
:uint16
|
|
1869
|
+
|
|
1870
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_enable_event_queue,
|
|
1871
|
+
[],
|
|
1872
|
+
:uint16
|
|
1873
|
+
|
|
1874
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_is_running,
|
|
1875
|
+
[],
|
|
1876
|
+
:uint16
|
|
1877
|
+
|
|
1878
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_next_auth_request,
|
|
1879
|
+
[],
|
|
1880
|
+
:uint16
|
|
1881
|
+
|
|
1882
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_next_event,
|
|
1883
|
+
[],
|
|
1884
|
+
:uint16
|
|
1885
|
+
|
|
1886
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_resolve_auth_request,
|
|
1887
|
+
[],
|
|
1888
|
+
:uint16
|
|
1889
|
+
|
|
1890
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_set_auth_provider,
|
|
1891
|
+
[],
|
|
1892
|
+
:uint16
|
|
1893
|
+
|
|
1894
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_set_enhanced_auth_provider,
|
|
1895
|
+
[],
|
|
1896
|
+
:uint16
|
|
1897
|
+
|
|
1898
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_set_event_listener,
|
|
1899
|
+
[],
|
|
1900
|
+
:uint16
|
|
1901
|
+
|
|
1902
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_start,
|
|
1903
|
+
[],
|
|
1904
|
+
:uint16
|
|
1905
|
+
|
|
1906
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbroker_stop,
|
|
1907
|
+
[],
|
|
1908
|
+
:uint16
|
|
1909
|
+
|
|
1910
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttauthprovider_authenticate,
|
|
1911
|
+
[],
|
|
1912
|
+
:uint16
|
|
1913
|
+
|
|
1914
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbrokereventlistener_on_client_connected,
|
|
1915
|
+
[],
|
|
1916
|
+
:uint16
|
|
1917
|
+
|
|
1918
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbrokereventlistener_on_client_disconnected,
|
|
1919
|
+
[],
|
|
1920
|
+
:uint16
|
|
1921
|
+
|
|
1922
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttbrokereventlistener_on_message_published,
|
|
1923
|
+
[],
|
|
1924
|
+
:uint16
|
|
1925
|
+
|
|
1926
|
+
attach_function :uniffi_mqtt_broker_checksum_method_mqttenhancedauthprovider_step,
|
|
1927
|
+
[],
|
|
1928
|
+
:uint16
|
|
1929
|
+
|
|
1930
|
+
attach_function :uniffi_mqtt_broker_checksum_constructor_mqttbroker_new,
|
|
1931
|
+
[],
|
|
1932
|
+
:uint16
|
|
1933
|
+
|
|
1934
|
+
attach_function :ffi_mqtt_broker_uniffi_contract_version,
|
|
1935
|
+
[],
|
|
1936
|
+
:uint32
|
|
1937
|
+
|
|
1938
|
+
end
|
|
1939
|
+
# RustFuture poll codes
|
|
1940
|
+
UNIFFI_RUST_FUTURE_POLL_READY = 0
|
|
1941
|
+
UNIFFI_RUST_FUTURE_POLL_WAKE = 1
|
|
1942
|
+
|
|
1943
|
+
# Handle map for storing write-end IO objects used by the continuation callbacks.
|
|
1944
|
+
UNIFFI_ASYNC_HANDLE_MAP = UniffiHandleMap.new
|
|
1945
|
+
|
|
1946
|
+
# Continuation callback for async functions.
|
|
1947
|
+
# Called by Rust when the future is ready to make progress.
|
|
1948
|
+
# Writes the poll code to the pipe so the waiting thread/fiber can continue.
|
|
1949
|
+
#
|
|
1950
|
+
# Exceptions must never escape this Proc.
|
|
1951
|
+
# Rust invokes it directly via FFI, so any unhandled Ruby exception would be caught
|
|
1952
|
+
# by Ruby-FFI, which swallows it (prints a warning) and returns a garbage value to Rust.
|
|
1953
|
+
# The poll code Rust receives would be invalid, causing the Ruby polling loop to
|
|
1954
|
+
# never see POLL_READY and block forever.
|
|
1955
|
+
UNIFFI_CONTINUATION_CALLBACK = Proc.new do |data, poll_code|
|
|
1956
|
+
begin
|
|
1957
|
+
wr = UNIFFI_ASYNC_HANDLE_MAP.get data
|
|
1958
|
+
|
|
1959
|
+
# This can only be blocking if pipe if full. Rust will never try to call continuation
|
|
1960
|
+
# callback more than once (so will not fill it up), hence this call should never block.
|
|
1961
|
+
wr.putc poll_code
|
|
1962
|
+
rescue Exception
|
|
1963
|
+
# Swallow exception. A leak or a hang is better than a hard VM segfault.
|
|
1964
|
+
end
|
|
1965
|
+
end
|
|
1966
|
+
|
|
1967
|
+
# Poll a Rust future to completion.
|
|
1968
|
+
#
|
|
1969
|
+
# This works both with and without a Fiber::Scheduler:
|
|
1970
|
+
# - Without scheduler: wait_readable blocks with a timeout, releasing the GVL
|
|
1971
|
+
# so the callback can fire from foreign threads (works around MRI limitation
|
|
1972
|
+
# where rb_thread_call_with_gvl cannot wake up threads in indefinite sleep).
|
|
1973
|
+
# - With scheduler: wait_readable hooks into io_wait, yielding the fiber.
|
|
1974
|
+
#
|
|
1975
|
+
# cancel_fn is called in the ensure block when exception interrupts an in-flight poll.
|
|
1976
|
+
# This guarantees Rust fires the continuation callback so the handle-map entry is released
|
|
1977
|
+
# and the pipe is drained before we free the future.
|
|
1978
|
+
def self.uniffi_rust_call_async(rust_future, poll_fn, cancel_fn, complete_fn, free_fn, lift_func, error_ffi_converter)
|
|
1979
|
+
rd = wr = nil
|
|
1980
|
+
handle = nil
|
|
1981
|
+
poll_in_flight = false
|
|
1982
|
+
|
|
1983
|
+
begin
|
|
1984
|
+
rd, wr = IO.pipe
|
|
1985
|
+
wr.sync = true # avoid buffering and delayed read for rd.wait_readable
|
|
1986
|
+
handle = UNIFFI_ASYNC_HANDLE_MAP.insert wr
|
|
1987
|
+
|
|
1988
|
+
loop do
|
|
1989
|
+
poll_in_flight = true
|
|
1990
|
+
UniFFILib.public_send(poll_fn, rust_future, UNIFFI_CONTINUATION_CALLBACK, handle)
|
|
1991
|
+
|
|
1992
|
+
# Blocks until the continuation callback writes to the pipe.
|
|
1993
|
+
# Releases the GVL so the callback can fire from foreign threads.
|
|
1994
|
+
# With a Fiber::Scheduler, this hooks into io_wait for non-blocking concurrency.
|
|
1995
|
+
rd.wait_readable
|
|
1996
|
+
poll_code = rd.getbyte
|
|
1997
|
+
poll_in_flight = false
|
|
1998
|
+
|
|
1999
|
+
break if poll_code == UNIFFI_RUST_FUTURE_POLL_READY
|
|
2000
|
+
end
|
|
2001
|
+
|
|
2002
|
+
result = if error_ffi_converter.nil?
|
|
2003
|
+
::MqttBroker.rust_call(complete_fn, rust_future)
|
|
2004
|
+
else
|
|
2005
|
+
::MqttBroker.rust_call_with_error(error_ffi_converter, complete_fn, rust_future)
|
|
2006
|
+
end
|
|
2007
|
+
|
|
2008
|
+
lift_func.call(result)
|
|
2009
|
+
ensure
|
|
2010
|
+
# Defer any further Thread#raise / Timeout during cleanup so all steps execute
|
|
2011
|
+
# automatically. Without this, a second raise during wait_readable(0.5) would skip
|
|
2012
|
+
# handle-map removal, pipe close, and free_fn - leaking FDs and Rust memory.
|
|
2013
|
+
Thread.handle_interrupt(Exception => :never) do
|
|
2014
|
+
if poll_in_flight
|
|
2015
|
+
# An exception interrupted an in-flight poll. Cancel and drain the byte
|
|
2016
|
+
# the continuation callback will write so we don't leak the pipe.
|
|
2017
|
+
UniFFILib.public_send(cancel_fn, rust_future)
|
|
2018
|
+
# rd.wait_readable may time out and return nil if the poll was never actually sent
|
|
2019
|
+
# (raise landed between poll_in_flight=true and the FFI call).
|
|
2020
|
+
if rd.wait_readable(0.5)
|
|
2021
|
+
rd.getbyte
|
|
2022
|
+
end
|
|
2023
|
+
end
|
|
2024
|
+
|
|
2025
|
+
# Remove handle first so any late-firing callback's `get` raises (swallowed by rescue).
|
|
2026
|
+
UNIFFI_ASYNC_HANDLE_MAP.remove(handle) rescue nil if handle
|
|
2027
|
+
rd&.close rescue nil
|
|
2028
|
+
wr&.close rescue nil
|
|
2029
|
+
UniFFILib.public_send(free_fn, rust_future)
|
|
2030
|
+
end
|
|
2031
|
+
end
|
|
2032
|
+
end
|
|
2033
|
+
# Base class for callback interface FfiConverters.
|
|
2034
|
+
# Stores Ruby callback objects in a handle map, and converts to/from integer handles.
|
|
2035
|
+
|
|
2036
|
+
class CallbackInterfaceFfiConverter
|
|
2037
|
+
attr_reader :handle_map
|
|
2038
|
+
|
|
2039
|
+
def initialize
|
|
2040
|
+
@handle_map = UniffiHandleMap.new
|
|
2041
|
+
end
|
|
2042
|
+
|
|
2043
|
+
def lift(handle)
|
|
2044
|
+
@handle_map.get handle
|
|
2045
|
+
end
|
|
2046
|
+
|
|
2047
|
+
def lower(cb)
|
|
2048
|
+
@handle_map.insert cb
|
|
2049
|
+
end
|
|
2050
|
+
end
|
|
2051
|
+
|
|
2052
|
+
private_constant :CallbackInterfaceFfiConverter
|
|
2053
|
+
|
|
2054
|
+
# Custom type definitions.
|
|
2055
|
+
|
|
2056
|
+
# Public interface members begin here.
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
|
|
2060
|
+
|
|
2061
|
+
|
|
2062
|
+
class EnhancedAuthOutcome
|
|
2063
|
+
CONTINUE = 0
|
|
2064
|
+
SUCCESS = 1
|
|
2065
|
+
FAILURE = 2
|
|
2066
|
+
|
|
2067
|
+
end
|
|
2068
|
+
|
|
2069
|
+
|
|
2070
|
+
|
|
2071
|
+
|
|
2072
|
+
|
|
2073
|
+
|
|
2074
|
+
class QoS
|
|
2075
|
+
AT_MOST_ONCE = 0
|
|
2076
|
+
AT_LEAST_ONCE = 1
|
|
2077
|
+
EXACTLY_ONCE = 2
|
|
2078
|
+
|
|
2079
|
+
end
|
|
2080
|
+
|
|
2081
|
+
|
|
2082
|
+
|
|
2083
|
+
|
|
2084
|
+
|
|
2085
|
+
|
|
2086
|
+
|
|
2087
|
+
class BrokerEvent
|
|
2088
|
+
def initialize
|
|
2089
|
+
raise RuntimeError, 'BrokerEvent cannot be instantiated directly'
|
|
2090
|
+
end
|
|
2091
|
+
|
|
2092
|
+
|
|
2093
|
+
# Each enum variant is a nested class of the enum itself.
|
|
2094
|
+
class CLIENT_CONNECTED < BrokerEvent
|
|
2095
|
+
|
|
2096
|
+
attr_reader :client_id
|
|
2097
|
+
|
|
2098
|
+
def initialize(client_id:
|
|
2099
|
+
)
|
|
2100
|
+
@client_id = client_id
|
|
2101
|
+
end
|
|
2102
|
+
def to_s
|
|
2103
|
+
"BrokerEvent::CLIENT_CONNECTED"
|
|
2104
|
+
end
|
|
2105
|
+
def ==(other)
|
|
2106
|
+
return false unless other.respond_to?(:client_connected?)
|
|
2107
|
+
return false unless other.client_connected?
|
|
2108
|
+
return false if @client_id != other.client_id
|
|
2109
|
+
true
|
|
2110
|
+
end
|
|
2111
|
+
|
|
2112
|
+
# For each variant, we have an `NAME?` method for easily checking
|
|
2113
|
+
# whether an instance is that variant.
|
|
2114
|
+
|
|
2115
|
+
def client_connected?
|
|
2116
|
+
instance_of? BrokerEvent::CLIENT_CONNECTED
|
|
2117
|
+
end
|
|
2118
|
+
|
|
2119
|
+
def client_disconnected?
|
|
2120
|
+
instance_of? BrokerEvent::CLIENT_DISCONNECTED
|
|
2121
|
+
end
|
|
2122
|
+
|
|
2123
|
+
def message_published?
|
|
2124
|
+
instance_of? BrokerEvent::MESSAGE_PUBLISHED
|
|
2125
|
+
end
|
|
2126
|
+
|
|
2127
|
+
end
|
|
2128
|
+
class CLIENT_DISCONNECTED < BrokerEvent
|
|
2129
|
+
|
|
2130
|
+
attr_reader :client_id, :reason
|
|
2131
|
+
|
|
2132
|
+
def initialize(client_id:
|
|
2133
|
+
, reason:
|
|
2134
|
+
)
|
|
2135
|
+
@client_id = client_id
|
|
2136
|
+
@reason = reason
|
|
2137
|
+
end
|
|
2138
|
+
def to_s
|
|
2139
|
+
"BrokerEvent::CLIENT_DISCONNECTED"
|
|
2140
|
+
end
|
|
2141
|
+
def ==(other)
|
|
2142
|
+
return false unless other.respond_to?(:client_disconnected?)
|
|
2143
|
+
return false unless other.client_disconnected?
|
|
2144
|
+
return false if @client_id != other.client_id
|
|
2145
|
+
return false if @reason != other.reason
|
|
2146
|
+
true
|
|
2147
|
+
end
|
|
2148
|
+
|
|
2149
|
+
# For each variant, we have an `NAME?` method for easily checking
|
|
2150
|
+
# whether an instance is that variant.
|
|
2151
|
+
|
|
2152
|
+
def client_connected?
|
|
2153
|
+
instance_of? BrokerEvent::CLIENT_CONNECTED
|
|
2154
|
+
end
|
|
2155
|
+
|
|
2156
|
+
def client_disconnected?
|
|
2157
|
+
instance_of? BrokerEvent::CLIENT_DISCONNECTED
|
|
2158
|
+
end
|
|
2159
|
+
|
|
2160
|
+
def message_published?
|
|
2161
|
+
instance_of? BrokerEvent::MESSAGE_PUBLISHED
|
|
2162
|
+
end
|
|
2163
|
+
|
|
2164
|
+
end
|
|
2165
|
+
class MESSAGE_PUBLISHED < BrokerEvent
|
|
2166
|
+
|
|
2167
|
+
attr_reader :client_id, :topic, :qos
|
|
2168
|
+
|
|
2169
|
+
def initialize(client_id:
|
|
2170
|
+
, topic:
|
|
2171
|
+
, qos:
|
|
2172
|
+
)
|
|
2173
|
+
@client_id = client_id
|
|
2174
|
+
@topic = topic
|
|
2175
|
+
@qos = qos
|
|
2176
|
+
end
|
|
2177
|
+
def to_s
|
|
2178
|
+
"BrokerEvent::MESSAGE_PUBLISHED"
|
|
2179
|
+
end
|
|
2180
|
+
def ==(other)
|
|
2181
|
+
return false unless other.respond_to?(:message_published?)
|
|
2182
|
+
return false unless other.message_published?
|
|
2183
|
+
return false if @client_id != other.client_id
|
|
2184
|
+
return false if @topic != other.topic
|
|
2185
|
+
return false if @qos != other.qos
|
|
2186
|
+
true
|
|
2187
|
+
end
|
|
2188
|
+
|
|
2189
|
+
# For each variant, we have an `NAME?` method for easily checking
|
|
2190
|
+
# whether an instance is that variant.
|
|
2191
|
+
|
|
2192
|
+
def client_connected?
|
|
2193
|
+
instance_of? BrokerEvent::CLIENT_CONNECTED
|
|
2194
|
+
end
|
|
2195
|
+
|
|
2196
|
+
def client_disconnected?
|
|
2197
|
+
instance_of? BrokerEvent::CLIENT_DISCONNECTED
|
|
2198
|
+
end
|
|
2199
|
+
|
|
2200
|
+
def message_published?
|
|
2201
|
+
instance_of? BrokerEvent::MESSAGE_PUBLISHED
|
|
2202
|
+
end
|
|
2203
|
+
|
|
2204
|
+
end
|
|
2205
|
+
|
|
2206
|
+
end
|
|
2207
|
+
|
|
2208
|
+
|
|
2209
|
+
|
|
2210
|
+
# Record type AuthRequest
|
|
2211
|
+
class AuthRequest
|
|
2212
|
+
attr_reader :id, :client_id, :username, :password
|
|
2213
|
+
|
|
2214
|
+
def initialize(id:, client_id:, username:, password:)
|
|
2215
|
+
@id = id
|
|
2216
|
+
@client_id = client_id
|
|
2217
|
+
@username = username
|
|
2218
|
+
@password = password
|
|
2219
|
+
end
|
|
2220
|
+
|
|
2221
|
+
def ==(other)
|
|
2222
|
+
if @id != other.id
|
|
2223
|
+
return false
|
|
2224
|
+
end
|
|
2225
|
+
if @client_id != other.client_id
|
|
2226
|
+
return false
|
|
2227
|
+
end
|
|
2228
|
+
if @username != other.username
|
|
2229
|
+
return false
|
|
2230
|
+
end
|
|
2231
|
+
if @password != other.password
|
|
2232
|
+
return false
|
|
2233
|
+
end
|
|
2234
|
+
|
|
2235
|
+
true
|
|
2236
|
+
end
|
|
2237
|
+
|
|
2238
|
+
end
|
|
2239
|
+
|
|
2240
|
+
# Record type BrokerTlsConfig
|
|
2241
|
+
class BrokerTlsConfig
|
|
2242
|
+
attr_reader :port, :cert_pem, :key_pem, :client_ca_pem
|
|
2243
|
+
|
|
2244
|
+
def initialize(port:, cert_pem:, key_pem:, client_ca_pem:)
|
|
2245
|
+
@port = port
|
|
2246
|
+
@cert_pem = cert_pem
|
|
2247
|
+
@key_pem = key_pem
|
|
2248
|
+
@client_ca_pem = client_ca_pem
|
|
2249
|
+
end
|
|
2250
|
+
|
|
2251
|
+
def ==(other)
|
|
2252
|
+
if @port != other.port
|
|
2253
|
+
return false
|
|
2254
|
+
end
|
|
2255
|
+
if @cert_pem != other.cert_pem
|
|
2256
|
+
return false
|
|
2257
|
+
end
|
|
2258
|
+
if @key_pem != other.key_pem
|
|
2259
|
+
return false
|
|
2260
|
+
end
|
|
2261
|
+
if @client_ca_pem != other.client_ca_pem
|
|
2262
|
+
return false
|
|
2263
|
+
end
|
|
2264
|
+
|
|
2265
|
+
true
|
|
2266
|
+
end
|
|
2267
|
+
|
|
2268
|
+
end
|
|
2269
|
+
|
|
2270
|
+
# Record type EnhancedAuthStep
|
|
2271
|
+
class EnhancedAuthStep
|
|
2272
|
+
attr_reader :outcome, :data
|
|
2273
|
+
|
|
2274
|
+
def initialize(outcome:, data:)
|
|
2275
|
+
@outcome = outcome
|
|
2276
|
+
@data = data
|
|
2277
|
+
end
|
|
2278
|
+
|
|
2279
|
+
def ==(other)
|
|
2280
|
+
if @outcome != other.outcome
|
|
2281
|
+
return false
|
|
2282
|
+
end
|
|
2283
|
+
if @data != other.data
|
|
2284
|
+
return false
|
|
2285
|
+
end
|
|
2286
|
+
|
|
2287
|
+
true
|
|
2288
|
+
end
|
|
2289
|
+
|
|
2290
|
+
end
|
|
2291
|
+
|
|
2292
|
+
# Record type MqttBrokerConfig
|
|
2293
|
+
class MqttBrokerConfig
|
|
2294
|
+
attr_reader :bind_address, :port, :ws_port, :allow_anonymous, :max_clients, :max_qos, :max_retained_messages, :max_queued_per_client, :redelivery_interval_secs, :tls, :max_packet_size, :max_outbound_queue, :session_expiry_secs
|
|
2295
|
+
|
|
2296
|
+
def initialize(bind_address:, port:, ws_port:, allow_anonymous:, max_clients:, max_qos:, max_retained_messages:, max_queued_per_client:, redelivery_interval_secs:, tls:, max_packet_size: 0, max_outbound_queue: 0, session_expiry_secs: 0)
|
|
2297
|
+
@bind_address = bind_address
|
|
2298
|
+
@port = port
|
|
2299
|
+
@ws_port = ws_port
|
|
2300
|
+
@allow_anonymous = allow_anonymous
|
|
2301
|
+
@max_clients = max_clients
|
|
2302
|
+
@max_qos = max_qos
|
|
2303
|
+
@max_retained_messages = max_retained_messages
|
|
2304
|
+
@max_queued_per_client = max_queued_per_client
|
|
2305
|
+
@redelivery_interval_secs = redelivery_interval_secs
|
|
2306
|
+
@tls = tls
|
|
2307
|
+
@max_packet_size = max_packet_size
|
|
2308
|
+
@max_outbound_queue = max_outbound_queue
|
|
2309
|
+
@session_expiry_secs = session_expiry_secs
|
|
2310
|
+
end
|
|
2311
|
+
|
|
2312
|
+
def ==(other)
|
|
2313
|
+
if @bind_address != other.bind_address
|
|
2314
|
+
return false
|
|
2315
|
+
end
|
|
2316
|
+
if @port != other.port
|
|
2317
|
+
return false
|
|
2318
|
+
end
|
|
2319
|
+
if @ws_port != other.ws_port
|
|
2320
|
+
return false
|
|
2321
|
+
end
|
|
2322
|
+
if @allow_anonymous != other.allow_anonymous
|
|
2323
|
+
return false
|
|
2324
|
+
end
|
|
2325
|
+
if @max_clients != other.max_clients
|
|
2326
|
+
return false
|
|
2327
|
+
end
|
|
2328
|
+
if @max_qos != other.max_qos
|
|
2329
|
+
return false
|
|
2330
|
+
end
|
|
2331
|
+
if @max_retained_messages != other.max_retained_messages
|
|
2332
|
+
return false
|
|
2333
|
+
end
|
|
2334
|
+
if @max_queued_per_client != other.max_queued_per_client
|
|
2335
|
+
return false
|
|
2336
|
+
end
|
|
2337
|
+
if @redelivery_interval_secs != other.redelivery_interval_secs
|
|
2338
|
+
return false
|
|
2339
|
+
end
|
|
2340
|
+
if @tls != other.tls
|
|
2341
|
+
return false
|
|
2342
|
+
end
|
|
2343
|
+
if @max_packet_size != other.max_packet_size
|
|
2344
|
+
return false
|
|
2345
|
+
end
|
|
2346
|
+
if @max_outbound_queue != other.max_outbound_queue
|
|
2347
|
+
return false
|
|
2348
|
+
end
|
|
2349
|
+
if @session_expiry_secs != other.session_expiry_secs
|
|
2350
|
+
return false
|
|
2351
|
+
end
|
|
2352
|
+
|
|
2353
|
+
true
|
|
2354
|
+
end
|
|
2355
|
+
|
|
2356
|
+
end
|
|
2357
|
+
|
|
2358
|
+
|
|
2359
|
+
|
|
2360
|
+
|
|
2361
|
+
|
|
2362
|
+
class MqttBroker
|
|
2363
|
+
|
|
2364
|
+
# A private helper for initializing instances of the class from a raw handle,
|
|
2365
|
+
# bypassing any initialization logic and ensuring they are GC'd properly.
|
|
2366
|
+
def self.uniffi_allocate(handle)
|
|
2367
|
+
inst = allocate
|
|
2368
|
+
inst.instance_variable_set :@handle, handle
|
|
2369
|
+
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
|
|
2370
|
+
return inst
|
|
2371
|
+
end
|
|
2372
|
+
|
|
2373
|
+
# A private helper for registering an object finalizer.
|
|
2374
|
+
# N.B. it's important that this does not capture a reference
|
|
2375
|
+
# to the actual instance, only its underlying handle.
|
|
2376
|
+
def self.uniffi_define_finalizer_by_handle(handle, object_id)
|
|
2377
|
+
Proc.new do |_id|
|
|
2378
|
+
::MqttBroker.rust_call(
|
|
2379
|
+
:uniffi_mqtt_broker_fn_free_mqttbroker,
|
|
2380
|
+
handle
|
|
2381
|
+
)
|
|
2382
|
+
end
|
|
2383
|
+
end
|
|
2384
|
+
# A private helper for lowering instances into a raw handle.
|
|
2385
|
+
# This does an explicit typecheck, because accidentally lowering a different type of
|
|
2386
|
+
# object in a place where this type is expected, could lead to memory unsafety.
|
|
2387
|
+
def self.uniffi_check_lower(inst)
|
|
2388
|
+
if !inst.is_a? self
|
|
2389
|
+
raise TypeError.new "Expected a MqttBroker instance, got #{inst}"
|
|
2390
|
+
end
|
|
2391
|
+
end
|
|
2392
|
+
|
|
2393
|
+
def uniffi_clone_handle()
|
|
2394
|
+
return ::MqttBroker.rust_call(
|
|
2395
|
+
:uniffi_mqtt_broker_fn_clone_mqttbroker,
|
|
2396
|
+
@handle
|
|
2397
|
+
)
|
|
2398
|
+
end
|
|
2399
|
+
|
|
2400
|
+
def self.uniffi_lower(inst)
|
|
2401
|
+
return inst.uniffi_clone_handle()
|
|
2402
|
+
end
|
|
2403
|
+
|
|
2404
|
+
def self.uniffi_lift(handle)
|
|
2405
|
+
uniffi_allocate handle
|
|
2406
|
+
end
|
|
2407
|
+
def initialize(config)
|
|
2408
|
+
config = config
|
|
2409
|
+
RustBuffer.check_lower_TypeMqttBrokerConfig(config)
|
|
2410
|
+
handle = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_constructor_mqttbroker_new,RustBuffer.alloc_from_TypeMqttBrokerConfig(config))
|
|
2411
|
+
@handle = handle
|
|
2412
|
+
ObjectSpace.define_finalizer(self, self.class.uniffi_define_finalizer_by_handle(handle, self.object_id))
|
|
2413
|
+
end
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
def bound_port()
|
|
2418
|
+
result = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_bound_port,uniffi_clone_handle(),)
|
|
2419
|
+
return result.consume_into_Optionalu16
|
|
2420
|
+
end
|
|
2421
|
+
def bound_tls_port()
|
|
2422
|
+
result = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_bound_tls_port,uniffi_clone_handle(),)
|
|
2423
|
+
return result.consume_into_Optionalu16
|
|
2424
|
+
end
|
|
2425
|
+
def bound_ws_port()
|
|
2426
|
+
result = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_bound_ws_port,uniffi_clone_handle(),)
|
|
2427
|
+
return result.consume_into_Optionalu16
|
|
2428
|
+
end
|
|
2429
|
+
def client_count()
|
|
2430
|
+
result = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_client_count,uniffi_clone_handle(),)
|
|
2431
|
+
return result.to_i
|
|
2432
|
+
end
|
|
2433
|
+
def enable_auth_queue(capacity)
|
|
2434
|
+
capacity = ::MqttBroker::uniffi_in_range(capacity, "u32", 0, 2**32)
|
|
2435
|
+
|
|
2436
|
+
::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_enable_auth_queue,uniffi_clone_handle(),capacity)
|
|
2437
|
+
end
|
|
2438
|
+
|
|
2439
|
+
def enable_event_queue(capacity)
|
|
2440
|
+
capacity = ::MqttBroker::uniffi_in_range(capacity, "u32", 0, 2**32)
|
|
2441
|
+
|
|
2442
|
+
::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_enable_event_queue,uniffi_clone_handle(),capacity)
|
|
2443
|
+
end
|
|
2444
|
+
|
|
2445
|
+
def is_running()
|
|
2446
|
+
result = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_is_running,uniffi_clone_handle(),)
|
|
2447
|
+
return 1 == result
|
|
2448
|
+
end
|
|
2449
|
+
|
|
2450
|
+
def next_auth_request(timeout_ms)
|
|
2451
|
+
timeout_ms = ::MqttBroker::uniffi_in_range(timeout_ms, "u32", 0, 2**32)
|
|
2452
|
+
|
|
2453
|
+
::MqttBroker.uniffi_rust_call_async(
|
|
2454
|
+
UniFFILib.uniffi_mqtt_broker_fn_method_mqttbroker_next_auth_request(uniffi_clone_handle(),timeout_ms),
|
|
2455
|
+
:ffi_mqtt_broker_rust_future_poll_rust_buffer,
|
|
2456
|
+
:ffi_mqtt_broker_rust_future_cancel_rust_buffer,
|
|
2457
|
+
:ffi_mqtt_broker_rust_future_complete_rust_buffer,
|
|
2458
|
+
:ffi_mqtt_broker_rust_future_free_rust_buffer,
|
|
2459
|
+
Proc.new { |v| v.consume_into_OptionalTypeAuthRequest },
|
|
2460
|
+
nil
|
|
2461
|
+
)
|
|
2462
|
+
end
|
|
2463
|
+
|
|
2464
|
+
def next_event(timeout_ms)
|
|
2465
|
+
timeout_ms = ::MqttBroker::uniffi_in_range(timeout_ms, "u32", 0, 2**32)
|
|
2466
|
+
|
|
2467
|
+
::MqttBroker.uniffi_rust_call_async(
|
|
2468
|
+
UniFFILib.uniffi_mqtt_broker_fn_method_mqttbroker_next_event(uniffi_clone_handle(),timeout_ms),
|
|
2469
|
+
:ffi_mqtt_broker_rust_future_poll_rust_buffer,
|
|
2470
|
+
:ffi_mqtt_broker_rust_future_cancel_rust_buffer,
|
|
2471
|
+
:ffi_mqtt_broker_rust_future_complete_rust_buffer,
|
|
2472
|
+
:ffi_mqtt_broker_rust_future_free_rust_buffer,
|
|
2473
|
+
Proc.new { |v| v.consume_into_OptionalTypeBrokerEvent },
|
|
2474
|
+
nil
|
|
2475
|
+
)
|
|
2476
|
+
end
|
|
2477
|
+
def resolve_auth_request(id, allow)
|
|
2478
|
+
id = ::MqttBroker::uniffi_in_range(id, "u64", 0, 2**64)
|
|
2479
|
+
|
|
2480
|
+
allow = allow ? true : false
|
|
2481
|
+
|
|
2482
|
+
result = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_resolve_auth_request,uniffi_clone_handle(),id,(allow ? 1 : 0))
|
|
2483
|
+
return 1 == result
|
|
2484
|
+
end
|
|
2485
|
+
def set_auth_provider(provider)
|
|
2486
|
+
provider = provider
|
|
2487
|
+
(MqttAuthProvider.uniffi_check_lower provider)
|
|
2488
|
+
::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_set_auth_provider,uniffi_clone_handle(),(MqttAuthProvider.uniffi_lower provider))
|
|
2489
|
+
end
|
|
2490
|
+
|
|
2491
|
+
def set_enhanced_auth_provider(provider)
|
|
2492
|
+
provider = provider
|
|
2493
|
+
(MqttEnhancedAuthProvider.uniffi_check_lower provider)
|
|
2494
|
+
::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_set_enhanced_auth_provider,uniffi_clone_handle(),(MqttEnhancedAuthProvider.uniffi_lower provider))
|
|
2495
|
+
end
|
|
2496
|
+
|
|
2497
|
+
def set_event_listener(listener)
|
|
2498
|
+
listener = listener
|
|
2499
|
+
(MqttBrokerEventListener.uniffi_check_lower listener)
|
|
2500
|
+
::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbroker_set_event_listener,uniffi_clone_handle(),(MqttBrokerEventListener.uniffi_lower listener))
|
|
2501
|
+
end
|
|
2502
|
+
|
|
2503
|
+
|
|
2504
|
+
def start()
|
|
2505
|
+
::MqttBroker.uniffi_rust_call_async(
|
|
2506
|
+
UniFFILib.uniffi_mqtt_broker_fn_method_mqttbroker_start(uniffi_clone_handle(),),
|
|
2507
|
+
:ffi_mqtt_broker_rust_future_poll_void,
|
|
2508
|
+
:ffi_mqtt_broker_rust_future_cancel_void,
|
|
2509
|
+
:ffi_mqtt_broker_rust_future_complete_void,
|
|
2510
|
+
:ffi_mqtt_broker_rust_future_free_void,
|
|
2511
|
+
Proc.new { |v| nil },
|
|
2512
|
+
MqttBrokerError
|
|
2513
|
+
)
|
|
2514
|
+
end
|
|
2515
|
+
|
|
2516
|
+
def stop()
|
|
2517
|
+
::MqttBroker.uniffi_rust_call_async(
|
|
2518
|
+
UniFFILib.uniffi_mqtt_broker_fn_method_mqttbroker_stop(uniffi_clone_handle(),),
|
|
2519
|
+
:ffi_mqtt_broker_rust_future_poll_void,
|
|
2520
|
+
:ffi_mqtt_broker_rust_future_cancel_void,
|
|
2521
|
+
:ffi_mqtt_broker_rust_future_complete_void,
|
|
2522
|
+
:ffi_mqtt_broker_rust_future_free_void,
|
|
2523
|
+
Proc.new { |v| nil },
|
|
2524
|
+
MqttBrokerError
|
|
2525
|
+
)
|
|
2526
|
+
end
|
|
2527
|
+
|
|
2528
|
+
end
|
|
2529
|
+
|
|
2530
|
+
class MqttAuthProvider
|
|
2531
|
+
|
|
2532
|
+
# A private helper for initializing instances of the class from a raw handle,
|
|
2533
|
+
# bypassing any initialization logic and ensuring they are GC'd properly.
|
|
2534
|
+
def self.uniffi_allocate(handle)
|
|
2535
|
+
inst = allocate
|
|
2536
|
+
inst.instance_variable_set :@handle, handle
|
|
2537
|
+
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
|
|
2538
|
+
return inst
|
|
2539
|
+
end
|
|
2540
|
+
|
|
2541
|
+
# A private helper for registering an object finalizer.
|
|
2542
|
+
# N.B. it's important that this does not capture a reference
|
|
2543
|
+
# to the actual instance, only its underlying handle.
|
|
2544
|
+
def self.uniffi_define_finalizer_by_handle(handle, object_id)
|
|
2545
|
+
Proc.new do |_id|
|
|
2546
|
+
::MqttBroker.rust_call(
|
|
2547
|
+
:uniffi_mqtt_broker_fn_free_mqttauthprovider,
|
|
2548
|
+
handle
|
|
2549
|
+
)
|
|
2550
|
+
end
|
|
2551
|
+
end
|
|
2552
|
+
# HandleMap for trait interface: stores Ruby-native objects keyed by odd handles.
|
|
2553
|
+
@uniffi_handle_map = UniffiHandleMap.new
|
|
2554
|
+
|
|
2555
|
+
class << self
|
|
2556
|
+
attr_reader :uniffi_handle_map
|
|
2557
|
+
end
|
|
2558
|
+
|
|
2559
|
+
# For trait interfaces: check that the object is either a Rust-backed instance or
|
|
2560
|
+
# responds to the required interface methods.
|
|
2561
|
+
def self.uniffi_check_lower(inst)
|
|
2562
|
+
if !inst.respond_to?(:authenticate)
|
|
2563
|
+
raise TypeError.new "Expected a MqttAuthProvider instance or an object implementing the interface, got #{inst}"
|
|
2564
|
+
end
|
|
2565
|
+
end
|
|
2566
|
+
|
|
2567
|
+
def uniffi_clone_handle
|
|
2568
|
+
return ::MqttBroker.rust_call(
|
|
2569
|
+
:uniffi_mqtt_broker_fn_clone_mqttauthprovider,
|
|
2570
|
+
@handle
|
|
2571
|
+
)
|
|
2572
|
+
end
|
|
2573
|
+
|
|
2574
|
+
# For trait interfaces: lowering distinguishes between Rust-backed and Ruby-native instances.
|
|
2575
|
+
def self.uniffi_lower(inst)
|
|
2576
|
+
if inst.is_a?(self) && inst.instance_variable_defined?(:@handle)
|
|
2577
|
+
inst.uniffi_clone_handle()
|
|
2578
|
+
else
|
|
2579
|
+
@uniffi_handle_map.insert(inst)
|
|
2580
|
+
end
|
|
2581
|
+
end
|
|
2582
|
+
|
|
2583
|
+
# For trait interfaces: lifting distinguishes even handles (Rust) from odd handles (Ruby).
|
|
2584
|
+
def self.uniffi_lift(handle)
|
|
2585
|
+
if (handle & 1) == 0
|
|
2586
|
+
uniffi_allocate handle
|
|
2587
|
+
else
|
|
2588
|
+
@uniffi_handle_map.remove handle
|
|
2589
|
+
end
|
|
2590
|
+
end
|
|
2591
|
+
|
|
2592
|
+
|
|
2593
|
+
|
|
2594
|
+
def authenticate(client_id, username, password)
|
|
2595
|
+
client_id = ::MqttBroker::uniffi_utf8(client_id)
|
|
2596
|
+
|
|
2597
|
+
username = (username ? ::MqttBroker::uniffi_utf8(username) : nil)
|
|
2598
|
+
RustBuffer.check_lower_Optionalstring(username)
|
|
2599
|
+
password = (password ? ::MqttBroker::uniffi_bytes(password) : nil)
|
|
2600
|
+
RustBuffer.check_lower_Optionalbytes(password)
|
|
2601
|
+
result = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttauthprovider_authenticate,uniffi_clone_handle(),RustBuffer.alloc_from_string(client_id),RustBuffer.alloc_from_Optionalstring(username),RustBuffer.alloc_from_Optionalbytes(password))
|
|
2602
|
+
return 1 == result
|
|
2603
|
+
end
|
|
2604
|
+
|
|
2605
|
+
end
|
|
2606
|
+
|
|
2607
|
+
|
|
2608
|
+
# Trait interface vtable implementation for MqttAuthProvider.
|
|
2609
|
+
module UniffiCallbackInterfaceMqttAuthProvider
|
|
2610
|
+
# Callback method for authenticate
|
|
2611
|
+
AUTHENTICATE_CALLBACK = Proc.new do |uniffi_handle, client_id, username, password, uniffi_out_return, uniffi_call_status|
|
|
2612
|
+
uniffi_obj = MqttAuthProvider.uniffi_handle_map.get(uniffi_handle)
|
|
2613
|
+
make_call = Proc.new do
|
|
2614
|
+
uniffi_obj.authenticate(
|
|
2615
|
+
client_id.consume_into_string,
|
|
2616
|
+
username.consume_into_Optionalstring,
|
|
2617
|
+
password.consume_into_Optionalbytes
|
|
2618
|
+
)
|
|
2619
|
+
end
|
|
2620
|
+
write_return_value = Proc.new do |v|
|
|
2621
|
+
lowered = (v ? 1 : 0)
|
|
2622
|
+
uniffi_out_return.write_int8(lowered)
|
|
2623
|
+
end
|
|
2624
|
+
::MqttBroker.uniffi_trait_interface_call(
|
|
2625
|
+
uniffi_call_status,
|
|
2626
|
+
make_call,
|
|
2627
|
+
write_return_value,
|
|
2628
|
+
)
|
|
2629
|
+
end
|
|
2630
|
+
|
|
2631
|
+
# Free callback: removes the handle from the map.
|
|
2632
|
+
UNIFFI_FREE_CALLBACK = Proc.new do |uniffi_handle|
|
|
2633
|
+
MqttAuthProvider.uniffi_handle_map.remove uniffi_handle
|
|
2634
|
+
end
|
|
2635
|
+
|
|
2636
|
+
# Clone callback: clones the handle in the map.
|
|
2637
|
+
UNIFFI_CLONE_CALLBACK = Proc.new do |uniffi_handle|
|
|
2638
|
+
MqttAuthProvider.uniffi_handle_map.clone_handle(uniffi_handle)
|
|
2639
|
+
end
|
|
2640
|
+
|
|
2641
|
+
# Create the VTable struct instance.
|
|
2642
|
+
UNIFFI_VTABLE = UniFFILib::VTableCallbackInterfaceMqttAuthProvider.new
|
|
2643
|
+
UNIFFI_VTABLE[:uniffi_free] = UNIFFI_FREE_CALLBACK
|
|
2644
|
+
UNIFFI_VTABLE[:uniffi_clone] = UNIFFI_CLONE_CALLBACK
|
|
2645
|
+
UNIFFI_VTABLE[:authenticate] = AUTHENTICATE_CALLBACK
|
|
2646
|
+
|
|
2647
|
+
# Register the VTable with Rust.
|
|
2648
|
+
UniFFILib.uniffi_mqtt_broker_fn_init_callback_vtable_mqttauthprovider(UNIFFI_VTABLE)
|
|
2649
|
+
end
|
|
2650
|
+
|
|
2651
|
+
class MqttBrokerEventListener
|
|
2652
|
+
|
|
2653
|
+
# A private helper for initializing instances of the class from a raw handle,
|
|
2654
|
+
# bypassing any initialization logic and ensuring they are GC'd properly.
|
|
2655
|
+
def self.uniffi_allocate(handle)
|
|
2656
|
+
inst = allocate
|
|
2657
|
+
inst.instance_variable_set :@handle, handle
|
|
2658
|
+
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
|
|
2659
|
+
return inst
|
|
2660
|
+
end
|
|
2661
|
+
|
|
2662
|
+
# A private helper for registering an object finalizer.
|
|
2663
|
+
# N.B. it's important that this does not capture a reference
|
|
2664
|
+
# to the actual instance, only its underlying handle.
|
|
2665
|
+
def self.uniffi_define_finalizer_by_handle(handle, object_id)
|
|
2666
|
+
Proc.new do |_id|
|
|
2667
|
+
::MqttBroker.rust_call(
|
|
2668
|
+
:uniffi_mqtt_broker_fn_free_mqttbrokereventlistener,
|
|
2669
|
+
handle
|
|
2670
|
+
)
|
|
2671
|
+
end
|
|
2672
|
+
end
|
|
2673
|
+
# HandleMap for trait interface: stores Ruby-native objects keyed by odd handles.
|
|
2674
|
+
@uniffi_handle_map = UniffiHandleMap.new
|
|
2675
|
+
|
|
2676
|
+
class << self
|
|
2677
|
+
attr_reader :uniffi_handle_map
|
|
2678
|
+
end
|
|
2679
|
+
|
|
2680
|
+
# For trait interfaces: check that the object is either a Rust-backed instance or
|
|
2681
|
+
# responds to the required interface methods.
|
|
2682
|
+
def self.uniffi_check_lower(inst)
|
|
2683
|
+
if !inst.respond_to?(:on_client_connected)
|
|
2684
|
+
raise TypeError.new "Expected a MqttBrokerEventListener instance or an object implementing the interface, got #{inst}"
|
|
2685
|
+
end
|
|
2686
|
+
if !inst.respond_to?(:on_client_disconnected)
|
|
2687
|
+
raise TypeError.new "Expected a MqttBrokerEventListener instance or an object implementing the interface, got #{inst}"
|
|
2688
|
+
end
|
|
2689
|
+
if !inst.respond_to?(:on_message_published)
|
|
2690
|
+
raise TypeError.new "Expected a MqttBrokerEventListener instance or an object implementing the interface, got #{inst}"
|
|
2691
|
+
end
|
|
2692
|
+
end
|
|
2693
|
+
|
|
2694
|
+
def uniffi_clone_handle
|
|
2695
|
+
return ::MqttBroker.rust_call(
|
|
2696
|
+
:uniffi_mqtt_broker_fn_clone_mqttbrokereventlistener,
|
|
2697
|
+
@handle
|
|
2698
|
+
)
|
|
2699
|
+
end
|
|
2700
|
+
|
|
2701
|
+
# For trait interfaces: lowering distinguishes between Rust-backed and Ruby-native instances.
|
|
2702
|
+
def self.uniffi_lower(inst)
|
|
2703
|
+
if inst.is_a?(self) && inst.instance_variable_defined?(:@handle)
|
|
2704
|
+
inst.uniffi_clone_handle()
|
|
2705
|
+
else
|
|
2706
|
+
@uniffi_handle_map.insert(inst)
|
|
2707
|
+
end
|
|
2708
|
+
end
|
|
2709
|
+
|
|
2710
|
+
# For trait interfaces: lifting distinguishes even handles (Rust) from odd handles (Ruby).
|
|
2711
|
+
def self.uniffi_lift(handle)
|
|
2712
|
+
if (handle & 1) == 0
|
|
2713
|
+
uniffi_allocate handle
|
|
2714
|
+
else
|
|
2715
|
+
@uniffi_handle_map.remove handle
|
|
2716
|
+
end
|
|
2717
|
+
end
|
|
2718
|
+
|
|
2719
|
+
|
|
2720
|
+
|
|
2721
|
+
def on_client_connected(client_id)
|
|
2722
|
+
client_id = ::MqttBroker::uniffi_utf8(client_id)
|
|
2723
|
+
|
|
2724
|
+
::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_client_connected,uniffi_clone_handle(),RustBuffer.alloc_from_string(client_id))
|
|
2725
|
+
end
|
|
2726
|
+
|
|
2727
|
+
def on_client_disconnected(client_id, reason)
|
|
2728
|
+
client_id = ::MqttBroker::uniffi_utf8(client_id)
|
|
2729
|
+
|
|
2730
|
+
reason = ::MqttBroker::uniffi_utf8(reason)
|
|
2731
|
+
|
|
2732
|
+
::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_client_disconnected,uniffi_clone_handle(),RustBuffer.alloc_from_string(client_id),RustBuffer.alloc_from_string(reason))
|
|
2733
|
+
end
|
|
2734
|
+
|
|
2735
|
+
def on_message_published(client_id, topic, qos)
|
|
2736
|
+
client_id = ::MqttBroker::uniffi_utf8(client_id)
|
|
2737
|
+
|
|
2738
|
+
topic = ::MqttBroker::uniffi_utf8(topic)
|
|
2739
|
+
|
|
2740
|
+
qos = qos
|
|
2741
|
+
RustBuffer.check_lower_TypeQoS(qos)
|
|
2742
|
+
::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttbrokereventlistener_on_message_published,uniffi_clone_handle(),RustBuffer.alloc_from_string(client_id),RustBuffer.alloc_from_string(topic),RustBuffer.alloc_from_TypeQoS(qos))
|
|
2743
|
+
end
|
|
2744
|
+
|
|
2745
|
+
|
|
2746
|
+
end
|
|
2747
|
+
|
|
2748
|
+
|
|
2749
|
+
# Trait interface vtable implementation for MqttBrokerEventListener.
|
|
2750
|
+
module UniffiCallbackInterfaceMqttBrokerEventListener
|
|
2751
|
+
# Callback method for on_client_connected
|
|
2752
|
+
ON_CLIENT_CONNECTED_CALLBACK = Proc.new do |uniffi_handle, client_id, uniffi_out_return, uniffi_call_status|
|
|
2753
|
+
uniffi_obj = MqttBrokerEventListener.uniffi_handle_map.get(uniffi_handle)
|
|
2754
|
+
make_call = Proc.new do
|
|
2755
|
+
uniffi_obj.on_client_connected(
|
|
2756
|
+
client_id.consume_into_string
|
|
2757
|
+
)
|
|
2758
|
+
end
|
|
2759
|
+
# No return value, so do nothing
|
|
2760
|
+
write_return_value = Proc.new { |_v| }
|
|
2761
|
+
::MqttBroker.uniffi_trait_interface_call(
|
|
2762
|
+
uniffi_call_status,
|
|
2763
|
+
make_call,
|
|
2764
|
+
write_return_value,
|
|
2765
|
+
)
|
|
2766
|
+
end
|
|
2767
|
+
# Callback method for on_client_disconnected
|
|
2768
|
+
ON_CLIENT_DISCONNECTED_CALLBACK = Proc.new do |uniffi_handle, client_id, reason, uniffi_out_return, uniffi_call_status|
|
|
2769
|
+
uniffi_obj = MqttBrokerEventListener.uniffi_handle_map.get(uniffi_handle)
|
|
2770
|
+
make_call = Proc.new do
|
|
2771
|
+
uniffi_obj.on_client_disconnected(
|
|
2772
|
+
client_id.consume_into_string,
|
|
2773
|
+
reason.consume_into_string
|
|
2774
|
+
)
|
|
2775
|
+
end
|
|
2776
|
+
# No return value, so do nothing
|
|
2777
|
+
write_return_value = Proc.new { |_v| }
|
|
2778
|
+
::MqttBroker.uniffi_trait_interface_call(
|
|
2779
|
+
uniffi_call_status,
|
|
2780
|
+
make_call,
|
|
2781
|
+
write_return_value,
|
|
2782
|
+
)
|
|
2783
|
+
end
|
|
2784
|
+
# Callback method for on_message_published
|
|
2785
|
+
ON_MESSAGE_PUBLISHED_CALLBACK = Proc.new do |uniffi_handle, client_id, topic, qos, uniffi_out_return, uniffi_call_status|
|
|
2786
|
+
uniffi_obj = MqttBrokerEventListener.uniffi_handle_map.get(uniffi_handle)
|
|
2787
|
+
make_call = Proc.new do
|
|
2788
|
+
uniffi_obj.on_message_published(
|
|
2789
|
+
client_id.consume_into_string,
|
|
2790
|
+
topic.consume_into_string,
|
|
2791
|
+
qos.consume_into_TypeQoS
|
|
2792
|
+
)
|
|
2793
|
+
end
|
|
2794
|
+
# No return value, so do nothing
|
|
2795
|
+
write_return_value = Proc.new { |_v| }
|
|
2796
|
+
::MqttBroker.uniffi_trait_interface_call(
|
|
2797
|
+
uniffi_call_status,
|
|
2798
|
+
make_call,
|
|
2799
|
+
write_return_value,
|
|
2800
|
+
)
|
|
2801
|
+
end
|
|
2802
|
+
|
|
2803
|
+
# Free callback: removes the handle from the map.
|
|
2804
|
+
UNIFFI_FREE_CALLBACK = Proc.new do |uniffi_handle|
|
|
2805
|
+
MqttBrokerEventListener.uniffi_handle_map.remove uniffi_handle
|
|
2806
|
+
end
|
|
2807
|
+
|
|
2808
|
+
# Clone callback: clones the handle in the map.
|
|
2809
|
+
UNIFFI_CLONE_CALLBACK = Proc.new do |uniffi_handle|
|
|
2810
|
+
MqttBrokerEventListener.uniffi_handle_map.clone_handle(uniffi_handle)
|
|
2811
|
+
end
|
|
2812
|
+
|
|
2813
|
+
# Create the VTable struct instance.
|
|
2814
|
+
UNIFFI_VTABLE = UniFFILib::VTableCallbackInterfaceMqttBrokerEventListener.new
|
|
2815
|
+
UNIFFI_VTABLE[:uniffi_free] = UNIFFI_FREE_CALLBACK
|
|
2816
|
+
UNIFFI_VTABLE[:uniffi_clone] = UNIFFI_CLONE_CALLBACK
|
|
2817
|
+
UNIFFI_VTABLE[:on_client_connected] = ON_CLIENT_CONNECTED_CALLBACK
|
|
2818
|
+
UNIFFI_VTABLE[:on_client_disconnected] = ON_CLIENT_DISCONNECTED_CALLBACK
|
|
2819
|
+
UNIFFI_VTABLE[:on_message_published] = ON_MESSAGE_PUBLISHED_CALLBACK
|
|
2820
|
+
|
|
2821
|
+
# Register the VTable with Rust.
|
|
2822
|
+
UniFFILib.uniffi_mqtt_broker_fn_init_callback_vtable_mqttbrokereventlistener(UNIFFI_VTABLE)
|
|
2823
|
+
end
|
|
2824
|
+
|
|
2825
|
+
class MqttEnhancedAuthProvider
|
|
2826
|
+
|
|
2827
|
+
# A private helper for initializing instances of the class from a raw handle,
|
|
2828
|
+
# bypassing any initialization logic and ensuring they are GC'd properly.
|
|
2829
|
+
def self.uniffi_allocate(handle)
|
|
2830
|
+
inst = allocate
|
|
2831
|
+
inst.instance_variable_set :@handle, handle
|
|
2832
|
+
ObjectSpace.define_finalizer(inst, uniffi_define_finalizer_by_handle(handle, inst.object_id))
|
|
2833
|
+
return inst
|
|
2834
|
+
end
|
|
2835
|
+
|
|
2836
|
+
# A private helper for registering an object finalizer.
|
|
2837
|
+
# N.B. it's important that this does not capture a reference
|
|
2838
|
+
# to the actual instance, only its underlying handle.
|
|
2839
|
+
def self.uniffi_define_finalizer_by_handle(handle, object_id)
|
|
2840
|
+
Proc.new do |_id|
|
|
2841
|
+
::MqttBroker.rust_call(
|
|
2842
|
+
:uniffi_mqtt_broker_fn_free_mqttenhancedauthprovider,
|
|
2843
|
+
handle
|
|
2844
|
+
)
|
|
2845
|
+
end
|
|
2846
|
+
end
|
|
2847
|
+
# HandleMap for trait interface: stores Ruby-native objects keyed by odd handles.
|
|
2848
|
+
@uniffi_handle_map = UniffiHandleMap.new
|
|
2849
|
+
|
|
2850
|
+
class << self
|
|
2851
|
+
attr_reader :uniffi_handle_map
|
|
2852
|
+
end
|
|
2853
|
+
|
|
2854
|
+
# For trait interfaces: check that the object is either a Rust-backed instance or
|
|
2855
|
+
# responds to the required interface methods.
|
|
2856
|
+
def self.uniffi_check_lower(inst)
|
|
2857
|
+
if !inst.respond_to?(:step)
|
|
2858
|
+
raise TypeError.new "Expected a MqttEnhancedAuthProvider instance or an object implementing the interface, got #{inst}"
|
|
2859
|
+
end
|
|
2860
|
+
end
|
|
2861
|
+
|
|
2862
|
+
def uniffi_clone_handle
|
|
2863
|
+
return ::MqttBroker.rust_call(
|
|
2864
|
+
:uniffi_mqtt_broker_fn_clone_mqttenhancedauthprovider,
|
|
2865
|
+
@handle
|
|
2866
|
+
)
|
|
2867
|
+
end
|
|
2868
|
+
|
|
2869
|
+
# For trait interfaces: lowering distinguishes between Rust-backed and Ruby-native instances.
|
|
2870
|
+
def self.uniffi_lower(inst)
|
|
2871
|
+
if inst.is_a?(self) && inst.instance_variable_defined?(:@handle)
|
|
2872
|
+
inst.uniffi_clone_handle()
|
|
2873
|
+
else
|
|
2874
|
+
@uniffi_handle_map.insert(inst)
|
|
2875
|
+
end
|
|
2876
|
+
end
|
|
2877
|
+
|
|
2878
|
+
# For trait interfaces: lifting distinguishes even handles (Rust) from odd handles (Ruby).
|
|
2879
|
+
def self.uniffi_lift(handle)
|
|
2880
|
+
if (handle & 1) == 0
|
|
2881
|
+
uniffi_allocate handle
|
|
2882
|
+
else
|
|
2883
|
+
@uniffi_handle_map.remove handle
|
|
2884
|
+
end
|
|
2885
|
+
end
|
|
2886
|
+
|
|
2887
|
+
|
|
2888
|
+
|
|
2889
|
+
def step(client_id, method, data, round)
|
|
2890
|
+
client_id = ::MqttBroker::uniffi_utf8(client_id)
|
|
2891
|
+
|
|
2892
|
+
method = ::MqttBroker::uniffi_utf8(method)
|
|
2893
|
+
|
|
2894
|
+
data = (data ? ::MqttBroker::uniffi_bytes(data) : nil)
|
|
2895
|
+
RustBuffer.check_lower_Optionalbytes(data)
|
|
2896
|
+
round = ::MqttBroker::uniffi_in_range(round, "u32", 0, 2**32)
|
|
2897
|
+
|
|
2898
|
+
result = ::MqttBroker.rust_call(:uniffi_mqtt_broker_fn_method_mqttenhancedauthprovider_step,uniffi_clone_handle(),RustBuffer.alloc_from_string(client_id),RustBuffer.alloc_from_string(method),RustBuffer.alloc_from_Optionalbytes(data),round)
|
|
2899
|
+
return result.consume_into_TypeEnhancedAuthStep
|
|
2900
|
+
end
|
|
2901
|
+
|
|
2902
|
+
end
|
|
2903
|
+
|
|
2904
|
+
|
|
2905
|
+
# Trait interface vtable implementation for MqttEnhancedAuthProvider.
|
|
2906
|
+
module UniffiCallbackInterfaceMqttEnhancedAuthProvider
|
|
2907
|
+
# Callback method for step
|
|
2908
|
+
STEP_CALLBACK = Proc.new do |uniffi_handle, client_id, method, data, round, uniffi_out_return, uniffi_call_status|
|
|
2909
|
+
uniffi_obj = MqttEnhancedAuthProvider.uniffi_handle_map.get(uniffi_handle)
|
|
2910
|
+
make_call = Proc.new do
|
|
2911
|
+
uniffi_obj.step(
|
|
2912
|
+
client_id.consume_into_string,
|
|
2913
|
+
method.consume_into_string,
|
|
2914
|
+
data.consume_into_Optionalbytes,
|
|
2915
|
+
round.to_i
|
|
2916
|
+
)
|
|
2917
|
+
end
|
|
2918
|
+
write_return_value = Proc.new do |v|
|
|
2919
|
+
lowered = RustBuffer.alloc_from_TypeEnhancedAuthStep(v)
|
|
2920
|
+
# Write a RustBuffer struct into the out pointer
|
|
2921
|
+
out_buf = RustBuffer.new uniffi_out_return
|
|
2922
|
+
out_buf[:capacity] = lowered[:capacity]
|
|
2923
|
+
out_buf[:len] = lowered[:len]
|
|
2924
|
+
out_buf[:data] = lowered[:data]
|
|
2925
|
+
end
|
|
2926
|
+
::MqttBroker.uniffi_trait_interface_call(
|
|
2927
|
+
uniffi_call_status,
|
|
2928
|
+
make_call,
|
|
2929
|
+
write_return_value,
|
|
2930
|
+
)
|
|
2931
|
+
end
|
|
2932
|
+
|
|
2933
|
+
# Free callback: removes the handle from the map.
|
|
2934
|
+
UNIFFI_FREE_CALLBACK = Proc.new do |uniffi_handle|
|
|
2935
|
+
MqttEnhancedAuthProvider.uniffi_handle_map.remove uniffi_handle
|
|
2936
|
+
end
|
|
2937
|
+
|
|
2938
|
+
# Clone callback: clones the handle in the map.
|
|
2939
|
+
UNIFFI_CLONE_CALLBACK = Proc.new do |uniffi_handle|
|
|
2940
|
+
MqttEnhancedAuthProvider.uniffi_handle_map.clone_handle(uniffi_handle)
|
|
2941
|
+
end
|
|
2942
|
+
|
|
2943
|
+
# Create the VTable struct instance.
|
|
2944
|
+
UNIFFI_VTABLE = UniFFILib::VTableCallbackInterfaceMqttEnhancedAuthProvider.new
|
|
2945
|
+
UNIFFI_VTABLE[:uniffi_free] = UNIFFI_FREE_CALLBACK
|
|
2946
|
+
UNIFFI_VTABLE[:uniffi_clone] = UNIFFI_CLONE_CALLBACK
|
|
2947
|
+
UNIFFI_VTABLE[:step] = STEP_CALLBACK
|
|
2948
|
+
|
|
2949
|
+
# Register the VTable with Rust.
|
|
2950
|
+
UniFFILib.uniffi_mqtt_broker_fn_init_callback_vtable_mqttenhancedauthprovider(UNIFFI_VTABLE)
|
|
2951
|
+
end
|
|
2952
|
+
|
|
2953
|
+
|
|
2954
|
+
|
|
2955
|
+
end
|
|
2956
|
+
|