ping-openmls-sdk-react-native-macos 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Frameworks/.gitkeep +0 -0
- package/Frameworks/libping_ffi.a +0 -0
- package/README.md +64 -0
- package/ios/.gitkeep +0 -0
- package/ios/Generated.swift +3239 -0
- package/ios/JSObserverBridge.swift +35 -0
- package/ios/JSStorageBridge.swift +135 -0
- package/ios/JSTransportBridge.swift +126 -0
- package/ios/PingNativeModule.m +143 -0
- package/ios/PingNativeModule.swift +656 -0
- package/ios/TypeBridge.swift +297 -0
- package/ios/module.modulemap +4 -0
- package/ios/pingFFI.h +990 -0
- package/package.json +34 -0
- package/ping-openmls-sdk-react-native-macos.podspec +54 -0
- package/src/MessagingClient.ts +488 -0
- package/src/NativePing.ts +162 -0
- package/src/WebSocketTransport.ts +118 -0
- package/src/clipboard.ts +37 -0
- package/src/index.ts +112 -0
- package/src/storage-bridge.ts +124 -0
- package/src/transport-bridge.ts +89 -0
|
@@ -0,0 +1,3239 @@
|
|
|
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
|
+
// swiftlint:disable all
|
|
5
|
+
import Foundation
|
|
6
|
+
|
|
7
|
+
// Depending on the consumer's build setup, the low-level FFI code
|
|
8
|
+
// might be in a separate module, or it might be compiled inline into
|
|
9
|
+
// this module. This is a bit of light hackery to work with both.
|
|
10
|
+
#if canImport(pingFFI)
|
|
11
|
+
import pingFFI
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
private extension RustBuffer {
|
|
15
|
+
/// Allocate a new buffer, copying the contents of a `UInt8` array.
|
|
16
|
+
init(bytes: [UInt8]) {
|
|
17
|
+
let rbuf = bytes.withUnsafeBufferPointer { ptr in
|
|
18
|
+
RustBuffer.from(ptr)
|
|
19
|
+
}
|
|
20
|
+
self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static func empty() -> RustBuffer {
|
|
24
|
+
RustBuffer(capacity: 0, len: 0, data: nil)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
|
|
28
|
+
try! rustCall { ffi_ping_ffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// Frees the buffer in place.
|
|
32
|
+
/// The buffer must not be used after this is called.
|
|
33
|
+
func deallocate() {
|
|
34
|
+
try! rustCall { ffi_ping_ffi_rustbuffer_free(self, $0) }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private extension ForeignBytes {
|
|
39
|
+
init(bufferPointer: UnsafeBufferPointer<UInt8>) {
|
|
40
|
+
self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// For every type used in the interface, we provide helper methods for conveniently
|
|
45
|
+
// lifting and lowering that type from C-compatible data, and for reading and writing
|
|
46
|
+
// values of that type in a buffer.
|
|
47
|
+
|
|
48
|
+
// Helper classes/extensions that don't change.
|
|
49
|
+
// Someday, this will be in a library of its own.
|
|
50
|
+
|
|
51
|
+
private extension Data {
|
|
52
|
+
init(rustBuffer: RustBuffer) {
|
|
53
|
+
self.init(
|
|
54
|
+
bytesNoCopy: rustBuffer.data!,
|
|
55
|
+
count: Int(rustBuffer.len),
|
|
56
|
+
deallocator: .none
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Define reader functionality. Normally this would be defined in a class or
|
|
62
|
+
// struct, but we use standalone functions instead in order to make external
|
|
63
|
+
// types work.
|
|
64
|
+
//
|
|
65
|
+
// With external types, one swift source file needs to be able to call the read
|
|
66
|
+
// method on another source file's FfiConverter, but then what visibility
|
|
67
|
+
// should Reader have?
|
|
68
|
+
// - If Reader is fileprivate, then this means the read() must also
|
|
69
|
+
// be fileprivate, which doesn't work with external types.
|
|
70
|
+
// - If Reader is internal/public, we'll get compile errors since both source
|
|
71
|
+
// files will try define the same type.
|
|
72
|
+
//
|
|
73
|
+
// Instead, the read() method and these helper functions input a tuple of data
|
|
74
|
+
|
|
75
|
+
private func createReader(data: Data) -> (data: Data, offset: Data.Index) {
|
|
76
|
+
(data: data, offset: 0)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// Reads an integer at the current offset, in big-endian order, and advances
|
|
80
|
+
/// the offset on success. Throws if reading the integer would move the
|
|
81
|
+
/// offset past the end of the buffer.
|
|
82
|
+
private func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
|
|
83
|
+
let range = reader.offset ..< reader.offset + MemoryLayout<T>.size
|
|
84
|
+
guard reader.data.count >= range.upperBound else {
|
|
85
|
+
throw UniffiInternalError.bufferOverflow
|
|
86
|
+
}
|
|
87
|
+
if T.self == UInt8.self {
|
|
88
|
+
let value = reader.data[reader.offset]
|
|
89
|
+
reader.offset += 1
|
|
90
|
+
return value as! T
|
|
91
|
+
}
|
|
92
|
+
var value: T = 0
|
|
93
|
+
let _ = withUnsafeMutableBytes(of: &value) { reader.data.copyBytes(to: $0, from: range) }
|
|
94
|
+
reader.offset = range.upperBound
|
|
95
|
+
return value.bigEndian
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/// Reads an arbitrary number of bytes, to be used to read
|
|
99
|
+
/// raw bytes, this is useful when lifting strings
|
|
100
|
+
private func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> [UInt8] {
|
|
101
|
+
let range = reader.offset ..< (reader.offset + count)
|
|
102
|
+
guard reader.data.count >= range.upperBound else {
|
|
103
|
+
throw UniffiInternalError.bufferOverflow
|
|
104
|
+
}
|
|
105
|
+
var value = [UInt8](repeating: 0, count: count)
|
|
106
|
+
value.withUnsafeMutableBufferPointer { buffer in
|
|
107
|
+
reader.data.copyBytes(to: buffer, from: range)
|
|
108
|
+
}
|
|
109
|
+
reader.offset = range.upperBound
|
|
110
|
+
return value
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Reads a float at the current offset.
|
|
114
|
+
private func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
|
|
115
|
+
return try Float(bitPattern: readInt(&reader))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Reads a float at the current offset.
|
|
119
|
+
private func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
|
|
120
|
+
return try Double(bitPattern: readInt(&reader))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// Indicates if the offset has reached the end of the buffer.
|
|
124
|
+
private func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
|
|
125
|
+
return reader.offset < reader.data.count
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Define writer functionality. Normally this would be defined in a class or
|
|
129
|
+
// struct, but we use standalone functions instead in order to make external
|
|
130
|
+
// types work. See the above discussion on Readers for details.
|
|
131
|
+
|
|
132
|
+
private func createWriter() -> [UInt8] {
|
|
133
|
+
return []
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private func writeBytes<S: Sequence>(_ writer: inout [UInt8], _ byteArr: S) where S.Element == UInt8 {
|
|
137
|
+
writer.append(contentsOf: byteArr)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// Writes an integer in big-endian order.
|
|
141
|
+
///
|
|
142
|
+
/// Warning: make sure what you are trying to write
|
|
143
|
+
/// is in the correct type!
|
|
144
|
+
private func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
|
|
145
|
+
var value = value.bigEndian
|
|
146
|
+
withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private func writeFloat(_ writer: inout [UInt8], _ value: Float) {
|
|
150
|
+
writeInt(&writer, value.bitPattern)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private func writeDouble(_ writer: inout [UInt8], _ value: Double) {
|
|
154
|
+
writeInt(&writer, value.bitPattern)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/// Protocol for types that transfer other types across the FFI. This is
|
|
158
|
+
/// analogous to the Rust trait of the same name.
|
|
159
|
+
private protocol FfiConverter {
|
|
160
|
+
associatedtype FfiType
|
|
161
|
+
associatedtype SwiftType
|
|
162
|
+
|
|
163
|
+
static func lift(_ value: FfiType) throws -> SwiftType
|
|
164
|
+
static func lower(_ value: SwiftType) -> FfiType
|
|
165
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
|
|
166
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8])
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/// Types conforming to `Primitive` pass themselves directly over the FFI.
|
|
170
|
+
private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {}
|
|
171
|
+
|
|
172
|
+
extension FfiConverterPrimitive {
|
|
173
|
+
#if swift(>=5.8)
|
|
174
|
+
@_documentation(visibility: private)
|
|
175
|
+
#endif
|
|
176
|
+
public static func lift(_ value: FfiType) throws -> SwiftType {
|
|
177
|
+
return value
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#if swift(>=5.8)
|
|
181
|
+
@_documentation(visibility: private)
|
|
182
|
+
#endif
|
|
183
|
+
public static func lower(_ value: SwiftType) -> FfiType {
|
|
184
|
+
return value
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
|
|
189
|
+
/// Used for complex types where it's hard to write a custom lift/lower.
|
|
190
|
+
private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
|
|
191
|
+
|
|
192
|
+
extension FfiConverterRustBuffer {
|
|
193
|
+
#if swift(>=5.8)
|
|
194
|
+
@_documentation(visibility: private)
|
|
195
|
+
#endif
|
|
196
|
+
public static func lift(_ buf: RustBuffer) throws -> SwiftType {
|
|
197
|
+
var reader = createReader(data: Data(rustBuffer: buf))
|
|
198
|
+
let value = try read(from: &reader)
|
|
199
|
+
if hasRemaining(reader) {
|
|
200
|
+
throw UniffiInternalError.incompleteData
|
|
201
|
+
}
|
|
202
|
+
buf.deallocate()
|
|
203
|
+
return value
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#if swift(>=5.8)
|
|
207
|
+
@_documentation(visibility: private)
|
|
208
|
+
#endif
|
|
209
|
+
public static func lower(_ value: SwiftType) -> RustBuffer {
|
|
210
|
+
var writer = createWriter()
|
|
211
|
+
write(value, into: &writer)
|
|
212
|
+
return RustBuffer(bytes: writer)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/// An error type for FFI errors. These errors occur at the UniFFI level, not
|
|
217
|
+
/// the library level.
|
|
218
|
+
private enum UniffiInternalError: LocalizedError {
|
|
219
|
+
case bufferOverflow
|
|
220
|
+
case incompleteData
|
|
221
|
+
case unexpectedOptionalTag
|
|
222
|
+
case unexpectedEnumCase
|
|
223
|
+
case unexpectedNullPointer
|
|
224
|
+
case unexpectedRustCallStatusCode
|
|
225
|
+
case unexpectedRustCallError
|
|
226
|
+
case unexpectedStaleHandle
|
|
227
|
+
case rustPanic(_ message: String)
|
|
228
|
+
|
|
229
|
+
var errorDescription: String? {
|
|
230
|
+
switch self {
|
|
231
|
+
case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
|
|
232
|
+
case .incompleteData: return "The buffer still has data after lifting its containing value"
|
|
233
|
+
case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
|
|
234
|
+
case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
|
|
235
|
+
case .unexpectedNullPointer: return "Raw pointer value was null"
|
|
236
|
+
case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
|
|
237
|
+
case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
|
|
238
|
+
case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
|
|
239
|
+
case let .rustPanic(message): return message
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private extension NSLock {
|
|
245
|
+
func withLock<T>(f: () throws -> T) rethrows -> T {
|
|
246
|
+
lock()
|
|
247
|
+
defer { self.unlock() }
|
|
248
|
+
return try f()
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private let CALL_SUCCESS: Int8 = 0
|
|
253
|
+
private let CALL_ERROR: Int8 = 1
|
|
254
|
+
private let CALL_UNEXPECTED_ERROR: Int8 = 2
|
|
255
|
+
private let CALL_CANCELLED: Int8 = 3
|
|
256
|
+
|
|
257
|
+
private extension RustCallStatus {
|
|
258
|
+
init() {
|
|
259
|
+
self.init(
|
|
260
|
+
code: CALL_SUCCESS,
|
|
261
|
+
errorBuf: RustBuffer(
|
|
262
|
+
capacity: 0,
|
|
263
|
+
len: 0,
|
|
264
|
+
data: nil
|
|
265
|
+
)
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
|
271
|
+
let neverThrow: ((RustBuffer) throws -> Never)? = nil
|
|
272
|
+
return try makeRustCall(callback, errorHandler: neverThrow)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private func rustCallWithError<T, E: Swift.Error>(
|
|
276
|
+
_ errorHandler: @escaping (RustBuffer) throws -> E,
|
|
277
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T
|
|
278
|
+
) throws -> T {
|
|
279
|
+
try makeRustCall(callback, errorHandler: errorHandler)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private func makeRustCall<T, E: Swift.Error>(
|
|
283
|
+
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
|
|
284
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
285
|
+
) throws -> T {
|
|
286
|
+
uniffiEnsureInitialized()
|
|
287
|
+
var callStatus = RustCallStatus()
|
|
288
|
+
let returnedVal = callback(&callStatus)
|
|
289
|
+
try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
|
|
290
|
+
return returnedVal
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private func uniffiCheckCallStatus<E: Swift.Error>(
|
|
294
|
+
callStatus: RustCallStatus,
|
|
295
|
+
errorHandler: ((RustBuffer) throws -> E)?
|
|
296
|
+
) throws {
|
|
297
|
+
switch callStatus.code {
|
|
298
|
+
case CALL_SUCCESS:
|
|
299
|
+
return
|
|
300
|
+
|
|
301
|
+
case CALL_ERROR:
|
|
302
|
+
if let errorHandler = errorHandler {
|
|
303
|
+
throw try errorHandler(callStatus.errorBuf)
|
|
304
|
+
} else {
|
|
305
|
+
callStatus.errorBuf.deallocate()
|
|
306
|
+
throw UniffiInternalError.unexpectedRustCallError
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
case CALL_UNEXPECTED_ERROR:
|
|
310
|
+
// When the rust code sees a panic, it tries to construct a RustBuffer
|
|
311
|
+
// with the message. But if that code panics, then it just sends back
|
|
312
|
+
// an empty buffer.
|
|
313
|
+
if callStatus.errorBuf.len > 0 {
|
|
314
|
+
throw try UniffiInternalError.rustPanic(FfiConverterString.lift(callStatus.errorBuf))
|
|
315
|
+
} else {
|
|
316
|
+
callStatus.errorBuf.deallocate()
|
|
317
|
+
throw UniffiInternalError.rustPanic("Rust panic")
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
case CALL_CANCELLED:
|
|
321
|
+
fatalError("Cancellation not supported yet")
|
|
322
|
+
|
|
323
|
+
default:
|
|
324
|
+
throw UniffiInternalError.unexpectedRustCallStatusCode
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
private func uniffiTraitInterfaceCall<T>(
|
|
329
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
330
|
+
makeCall: () throws -> T,
|
|
331
|
+
writeReturn: (T) -> Void
|
|
332
|
+
) {
|
|
333
|
+
do {
|
|
334
|
+
try writeReturn(makeCall())
|
|
335
|
+
} catch {
|
|
336
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
337
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private func uniffiTraitInterfaceCallWithError<T, E>(
|
|
342
|
+
callStatus: UnsafeMutablePointer<RustCallStatus>,
|
|
343
|
+
makeCall: () throws -> T,
|
|
344
|
+
writeReturn: (T) -> Void,
|
|
345
|
+
lowerError: (E) -> RustBuffer
|
|
346
|
+
) {
|
|
347
|
+
do {
|
|
348
|
+
try writeReturn(makeCall())
|
|
349
|
+
} catch let error as E {
|
|
350
|
+
callStatus.pointee.code = CALL_ERROR
|
|
351
|
+
callStatus.pointee.errorBuf = lowerError(error)
|
|
352
|
+
} catch {
|
|
353
|
+
callStatus.pointee.code = CALL_UNEXPECTED_ERROR
|
|
354
|
+
callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private class UniffiHandleMap<T> {
|
|
359
|
+
private var map: [UInt64: T] = [:]
|
|
360
|
+
private let lock = NSLock()
|
|
361
|
+
private var currentHandle: UInt64 = 1
|
|
362
|
+
|
|
363
|
+
func insert(obj: T) -> UInt64 {
|
|
364
|
+
lock.withLock {
|
|
365
|
+
let handle = currentHandle
|
|
366
|
+
currentHandle += 1
|
|
367
|
+
map[handle] = obj
|
|
368
|
+
return handle
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
func get(handle: UInt64) throws -> T {
|
|
373
|
+
try lock.withLock {
|
|
374
|
+
guard let obj = map[handle] else {
|
|
375
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
376
|
+
}
|
|
377
|
+
return obj
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
@discardableResult
|
|
382
|
+
func remove(handle: UInt64) throws -> T {
|
|
383
|
+
try lock.withLock {
|
|
384
|
+
guard let obj = map.removeValue(forKey: handle) else {
|
|
385
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
386
|
+
}
|
|
387
|
+
return obj
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
var count: Int {
|
|
392
|
+
map.count
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Public interface members begin here.
|
|
397
|
+
|
|
398
|
+
#if swift(>=5.8)
|
|
399
|
+
@_documentation(visibility: private)
|
|
400
|
+
#endif
|
|
401
|
+
private struct FfiConverterUInt8: FfiConverterPrimitive {
|
|
402
|
+
typealias FfiType = UInt8
|
|
403
|
+
typealias SwiftType = UInt8
|
|
404
|
+
|
|
405
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 {
|
|
406
|
+
return try lift(readInt(&buf))
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
static func write(_ value: UInt8, into buf: inout [UInt8]) {
|
|
410
|
+
writeInt(&buf, lower(value))
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
#if swift(>=5.8)
|
|
415
|
+
@_documentation(visibility: private)
|
|
416
|
+
#endif
|
|
417
|
+
private struct FfiConverterUInt32: FfiConverterPrimitive {
|
|
418
|
+
typealias FfiType = UInt32
|
|
419
|
+
typealias SwiftType = UInt32
|
|
420
|
+
|
|
421
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
|
|
422
|
+
return try lift(readInt(&buf))
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
426
|
+
writeInt(&buf, lower(value))
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
#if swift(>=5.8)
|
|
431
|
+
@_documentation(visibility: private)
|
|
432
|
+
#endif
|
|
433
|
+
private struct FfiConverterUInt64: FfiConverterPrimitive {
|
|
434
|
+
typealias FfiType = UInt64
|
|
435
|
+
typealias SwiftType = UInt64
|
|
436
|
+
|
|
437
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 {
|
|
438
|
+
return try lift(readInt(&buf))
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
442
|
+
writeInt(&buf, lower(value))
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
#if swift(>=5.8)
|
|
447
|
+
@_documentation(visibility: private)
|
|
448
|
+
#endif
|
|
449
|
+
private struct FfiConverterBool: FfiConverter {
|
|
450
|
+
typealias FfiType = Int8
|
|
451
|
+
typealias SwiftType = Bool
|
|
452
|
+
|
|
453
|
+
static func lift(_ value: Int8) throws -> Bool {
|
|
454
|
+
return value != 0
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
static func lower(_ value: Bool) -> Int8 {
|
|
458
|
+
return value ? 1 : 0
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
|
|
462
|
+
return try lift(readInt(&buf))
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
static func write(_ value: Bool, into buf: inout [UInt8]) {
|
|
466
|
+
writeInt(&buf, lower(value))
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
#if swift(>=5.8)
|
|
471
|
+
@_documentation(visibility: private)
|
|
472
|
+
#endif
|
|
473
|
+
private struct FfiConverterString: FfiConverter {
|
|
474
|
+
typealias SwiftType = String
|
|
475
|
+
typealias FfiType = RustBuffer
|
|
476
|
+
|
|
477
|
+
static func lift(_ value: RustBuffer) throws -> String {
|
|
478
|
+
defer {
|
|
479
|
+
value.deallocate()
|
|
480
|
+
}
|
|
481
|
+
if value.data == nil {
|
|
482
|
+
return String()
|
|
483
|
+
}
|
|
484
|
+
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
|
|
485
|
+
return String(bytes: bytes, encoding: String.Encoding.utf8)!
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
static func lower(_ value: String) -> RustBuffer {
|
|
489
|
+
return value.utf8CString.withUnsafeBufferPointer { ptr in
|
|
490
|
+
// The swift string gives us int8_t, we want uint8_t.
|
|
491
|
+
ptr.withMemoryRebound(to: UInt8.self) { ptr in
|
|
492
|
+
// The swift string gives us a trailing null byte, we don't want it.
|
|
493
|
+
let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
|
|
494
|
+
return RustBuffer.from(buf)
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
|
|
500
|
+
let len: Int32 = try readInt(&buf)
|
|
501
|
+
return try String(bytes: readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
static func write(_ value: String, into buf: inout [UInt8]) {
|
|
505
|
+
let len = Int32(value.utf8.count)
|
|
506
|
+
writeInt(&buf, len)
|
|
507
|
+
writeBytes(&buf, value.utf8)
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
#if swift(>=5.8)
|
|
512
|
+
@_documentation(visibility: private)
|
|
513
|
+
#endif
|
|
514
|
+
private struct FfiConverterData: FfiConverterRustBuffer {
|
|
515
|
+
typealias SwiftType = Data
|
|
516
|
+
|
|
517
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
|
|
518
|
+
let len: Int32 = try readInt(&buf)
|
|
519
|
+
return try Data(readBytes(&buf, count: Int(len)))
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
static func write(_ value: Data, into buf: inout [UInt8]) {
|
|
523
|
+
let len = Int32(value.count)
|
|
524
|
+
writeInt(&buf, len)
|
|
525
|
+
writeBytes(&buf, value)
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
public protocol MessageObserver: AnyObject {
|
|
530
|
+
func onApplicationMessage(msg: IncomingMessage)
|
|
531
|
+
|
|
532
|
+
func onConversationUpdated(id: ConversationId, newEpoch: UInt64)
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
open class MessageObserverImpl:
|
|
536
|
+
MessageObserver
|
|
537
|
+
{
|
|
538
|
+
fileprivate let pointer: UnsafeMutableRawPointer!
|
|
539
|
+
|
|
540
|
+
// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
|
|
541
|
+
#if swift(>=5.8)
|
|
542
|
+
@_documentation(visibility: private)
|
|
543
|
+
#endif
|
|
544
|
+
public struct NoPointer {
|
|
545
|
+
public init() {}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
549
|
+
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
550
|
+
// make it `required` without making it `public`.
|
|
551
|
+
public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
552
|
+
self.pointer = pointer
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// This constructor can be used to instantiate a fake object.
|
|
556
|
+
// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
|
|
557
|
+
//
|
|
558
|
+
// - Warning:
|
|
559
|
+
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
|
|
560
|
+
#if swift(>=5.8)
|
|
561
|
+
@_documentation(visibility: private)
|
|
562
|
+
#endif
|
|
563
|
+
public init(noPointer _: NoPointer) {
|
|
564
|
+
pointer = nil
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
#if swift(>=5.8)
|
|
568
|
+
@_documentation(visibility: private)
|
|
569
|
+
#endif
|
|
570
|
+
public func uniffiClonePointer() -> UnsafeMutableRawPointer {
|
|
571
|
+
return try! rustCall { uniffi_ping_ffi_fn_clone_messageobserver(self.pointer, $0) }
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// No primary constructor declared for this class.
|
|
575
|
+
|
|
576
|
+
deinit {
|
|
577
|
+
guard let pointer = pointer else {
|
|
578
|
+
return
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
try! rustCall { uniffi_ping_ffi_fn_free_messageobserver(pointer, $0) }
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
open func onApplicationMessage(msg: IncomingMessage) {
|
|
585
|
+
try! rustCall {
|
|
586
|
+
uniffi_ping_ffi_fn_method_messageobserver_on_application_message(self.uniffiClonePointer(),
|
|
587
|
+
FfiConverterTypeIncomingMessage.lower(msg), $0)
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
open func onConversationUpdated(id: ConversationId, newEpoch: UInt64) {
|
|
592
|
+
try! rustCall {
|
|
593
|
+
uniffi_ping_ffi_fn_method_messageobserver_on_conversation_updated(self.uniffiClonePointer(),
|
|
594
|
+
FfiConverterTypeConversationId.lower(id),
|
|
595
|
+
FfiConverterUInt64.lower(newEpoch), $0)
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/// Magic number for the Rust proxy to call using the same mechanism as every other method,
|
|
601
|
+
/// to free the callback once it's dropped by Rust.
|
|
602
|
+
private let IDX_CALLBACK_FREE: Int32 = 0
|
|
603
|
+
// Callback return codes
|
|
604
|
+
private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0
|
|
605
|
+
private let UNIFFI_CALLBACK_ERROR: Int32 = 1
|
|
606
|
+
private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2
|
|
607
|
+
|
|
608
|
+
/// Put the implementation in a struct so we don't pollute the top-level namespace
|
|
609
|
+
private enum UniffiCallbackInterfaceMessageObserver {
|
|
610
|
+
/// Create the VTable using a series of closures.
|
|
611
|
+
/// Swift automatically converts these into C callback functions.
|
|
612
|
+
static var vtable: UniffiVTableCallbackInterfaceMessageObserver = .init(
|
|
613
|
+
onApplicationMessage: { (
|
|
614
|
+
uniffiHandle: UInt64,
|
|
615
|
+
msg: RustBuffer,
|
|
616
|
+
_: UnsafeMutableRawPointer,
|
|
617
|
+
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
|
|
618
|
+
) in
|
|
619
|
+
let makeCall = {
|
|
620
|
+
() throws in
|
|
621
|
+
guard let uniffiObj = try? FfiConverterTypeMessageObserver.handleMap.get(handle: uniffiHandle) else {
|
|
622
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
623
|
+
}
|
|
624
|
+
return try uniffiObj.onApplicationMessage(
|
|
625
|
+
msg: FfiConverterTypeIncomingMessage.lift(msg)
|
|
626
|
+
)
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
let writeReturn = { () }
|
|
630
|
+
uniffiTraitInterfaceCall(
|
|
631
|
+
callStatus: uniffiCallStatus,
|
|
632
|
+
makeCall: makeCall,
|
|
633
|
+
writeReturn: writeReturn
|
|
634
|
+
)
|
|
635
|
+
},
|
|
636
|
+
onConversationUpdated: { (
|
|
637
|
+
uniffiHandle: UInt64,
|
|
638
|
+
id: RustBuffer,
|
|
639
|
+
newEpoch: UInt64,
|
|
640
|
+
_: UnsafeMutableRawPointer,
|
|
641
|
+
uniffiCallStatus: UnsafeMutablePointer<RustCallStatus>
|
|
642
|
+
) in
|
|
643
|
+
let makeCall = {
|
|
644
|
+
() throws in
|
|
645
|
+
guard let uniffiObj = try? FfiConverterTypeMessageObserver.handleMap.get(handle: uniffiHandle) else {
|
|
646
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
647
|
+
}
|
|
648
|
+
return try uniffiObj.onConversationUpdated(
|
|
649
|
+
id: FfiConverterTypeConversationId.lift(id),
|
|
650
|
+
newEpoch: FfiConverterUInt64.lift(newEpoch)
|
|
651
|
+
)
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
let writeReturn = { () }
|
|
655
|
+
uniffiTraitInterfaceCall(
|
|
656
|
+
callStatus: uniffiCallStatus,
|
|
657
|
+
makeCall: makeCall,
|
|
658
|
+
writeReturn: writeReturn
|
|
659
|
+
)
|
|
660
|
+
},
|
|
661
|
+
uniffiFree: { (uniffiHandle: UInt64) in
|
|
662
|
+
let result = try? FfiConverterTypeMessageObserver.handleMap.remove(handle: uniffiHandle)
|
|
663
|
+
if result == nil {
|
|
664
|
+
print("Uniffi callback interface MessageObserver: handle missing in uniffiFree")
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
)
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
private func uniffiCallbackInitMessageObserver() {
|
|
671
|
+
uniffi_ping_ffi_fn_init_callback_vtable_messageobserver(&UniffiCallbackInterfaceMessageObserver.vtable)
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
#if swift(>=5.8)
|
|
675
|
+
@_documentation(visibility: private)
|
|
676
|
+
#endif
|
|
677
|
+
public struct FfiConverterTypeMessageObserver: FfiConverter {
|
|
678
|
+
fileprivate static var handleMap = UniffiHandleMap<MessageObserver>()
|
|
679
|
+
|
|
680
|
+
typealias FfiType = UnsafeMutableRawPointer
|
|
681
|
+
typealias SwiftType = MessageObserver
|
|
682
|
+
|
|
683
|
+
public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MessageObserver {
|
|
684
|
+
return MessageObserverImpl(unsafeFromRawPointer: pointer)
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
public static func lower(_ value: MessageObserver) -> UnsafeMutableRawPointer {
|
|
688
|
+
guard let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: handleMap.insert(obj: value))) else {
|
|
689
|
+
fatalError("Cast to UnsafeMutableRawPointer failed")
|
|
690
|
+
}
|
|
691
|
+
return ptr
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MessageObserver {
|
|
695
|
+
let v: UInt64 = try readInt(&buf)
|
|
696
|
+
// The Rust code won't compile if a pointer won't fit in a UInt64.
|
|
697
|
+
// We have to go via `UInt` because that's the thing that's the size of a pointer.
|
|
698
|
+
let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
|
|
699
|
+
if ptr == nil {
|
|
700
|
+
throw UniffiInternalError.unexpectedNullPointer
|
|
701
|
+
}
|
|
702
|
+
return try lift(ptr!)
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
public static func write(_ value: MessageObserver, into buf: inout [UInt8]) {
|
|
706
|
+
// This fiddling is because `Int` is the thing that's the same size as a pointer.
|
|
707
|
+
// The Rust code won't compile if a pointer won't fit in a `UInt64`.
|
|
708
|
+
writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
#if swift(>=5.8)
|
|
713
|
+
@_documentation(visibility: private)
|
|
714
|
+
#endif
|
|
715
|
+
public func FfiConverterTypeMessageObserver_lift(_ pointer: UnsafeMutableRawPointer) throws -> MessageObserver {
|
|
716
|
+
return try FfiConverterTypeMessageObserver.lift(pointer)
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
#if swift(>=5.8)
|
|
720
|
+
@_documentation(visibility: private)
|
|
721
|
+
#endif
|
|
722
|
+
public func FfiConverterTypeMessageObserver_lower(_ value: MessageObserver) -> UnsafeMutableRawPointer {
|
|
723
|
+
return FfiConverterTypeMessageObserver.lower(value)
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
public protocol MessagingClientProtocol: AnyObject {
|
|
727
|
+
func addMembers(conversationId: ConversationId, keyPackages: [Data], nowMs: UInt64) async throws
|
|
728
|
+
|
|
729
|
+
func buildLinkingTicket(newDeviceId: DeviceId, newDeviceKp: Data, nowMs: UInt64) async throws -> LinkingTicket
|
|
730
|
+
|
|
731
|
+
func consumeLinkingTicket(ticket: LinkingTicket, nowMs: UInt64) async throws
|
|
732
|
+
|
|
733
|
+
func createConversation(name: String?, nowMs: UInt64) async throws -> ConversationId
|
|
734
|
+
|
|
735
|
+
func deviceId() -> DeviceId
|
|
736
|
+
|
|
737
|
+
func deviceInfo(nowMs: UInt64) -> DeviceInfo
|
|
738
|
+
|
|
739
|
+
func freshKeyPackage() throws -> Data
|
|
740
|
+
|
|
741
|
+
func joinConversation(welcome: MessageEnvelope, nowMs: UInt64) async throws -> ConversationId
|
|
742
|
+
|
|
743
|
+
func listConversations() -> [ConversationMeta]
|
|
744
|
+
|
|
745
|
+
func listDevices() -> [DeviceInfo]
|
|
746
|
+
|
|
747
|
+
func processEnvelope(envelope: MessageEnvelope, nowMs: UInt64) async throws -> IncomingMessage?
|
|
748
|
+
|
|
749
|
+
func removeMembers(conversationId: ConversationId, leafIndexes: [UInt32], nowMs: UInt64) async throws
|
|
750
|
+
|
|
751
|
+
func revokeDevice(deviceId: DeviceId, nowMs: UInt64) async throws
|
|
752
|
+
|
|
753
|
+
func send(conversationId: ConversationId, plaintext: Data, nowMs: UInt64) async throws -> MessageEnvelope
|
|
754
|
+
|
|
755
|
+
func setObserver(observer: MessageObserver)
|
|
756
|
+
|
|
757
|
+
func syncConversations(nowMs: UInt64) async throws -> [IncomingMessage]
|
|
758
|
+
|
|
759
|
+
func userId() -> UserId
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
open class MessagingClient:
|
|
763
|
+
MessagingClientProtocol
|
|
764
|
+
{
|
|
765
|
+
fileprivate let pointer: UnsafeMutableRawPointer!
|
|
766
|
+
|
|
767
|
+
// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
|
|
768
|
+
#if swift(>=5.8)
|
|
769
|
+
@_documentation(visibility: private)
|
|
770
|
+
#endif
|
|
771
|
+
public struct NoPointer {
|
|
772
|
+
public init() {}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
776
|
+
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
777
|
+
// make it `required` without making it `public`.
|
|
778
|
+
public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
779
|
+
self.pointer = pointer
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// This constructor can be used to instantiate a fake object.
|
|
783
|
+
// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
|
|
784
|
+
//
|
|
785
|
+
// - Warning:
|
|
786
|
+
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
|
|
787
|
+
#if swift(>=5.8)
|
|
788
|
+
@_documentation(visibility: private)
|
|
789
|
+
#endif
|
|
790
|
+
public init(noPointer _: NoPointer) {
|
|
791
|
+
pointer = nil
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
#if swift(>=5.8)
|
|
795
|
+
@_documentation(visibility: private)
|
|
796
|
+
#endif
|
|
797
|
+
public func uniffiClonePointer() -> UnsafeMutableRawPointer {
|
|
798
|
+
return try! rustCall { uniffi_ping_ffi_fn_clone_messagingclient(self.pointer, $0) }
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// No primary constructor declared for this class.
|
|
802
|
+
|
|
803
|
+
deinit {
|
|
804
|
+
guard let pointer = pointer else {
|
|
805
|
+
return
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
try! rustCall { uniffi_ping_ffi_fn_free_messagingclient(pointer, $0) }
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
public static func `init`(identityExport: Data, deviceLabel: String, storage: Storage, transport: Transport, nowMs: UInt64) async throws -> MessagingClient {
|
|
812
|
+
return
|
|
813
|
+
try await uniffiRustCallAsync(
|
|
814
|
+
rustFutureFunc: {
|
|
815
|
+
uniffi_ping_ffi_fn_constructor_messagingclient_init(FfiConverterData.lower(identityExport), FfiConverterString.lower(deviceLabel), FfiConverterTypeStorage.lower(storage), FfiConverterTypeTransport.lower(transport), FfiConverterUInt64.lower(nowMs))
|
|
816
|
+
},
|
|
817
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_pointer,
|
|
818
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_pointer,
|
|
819
|
+
freeFunc: ffi_ping_ffi_rust_future_free_pointer,
|
|
820
|
+
liftFunc: FfiConverterTypeMessagingClient.lift,
|
|
821
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
822
|
+
)
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
open func addMembers(conversationId: ConversationId, keyPackages: [Data], nowMs: UInt64) async throws {
|
|
826
|
+
return
|
|
827
|
+
try await uniffiRustCallAsync(
|
|
828
|
+
rustFutureFunc: {
|
|
829
|
+
uniffi_ping_ffi_fn_method_messagingclient_add_members(
|
|
830
|
+
self.uniffiClonePointer(),
|
|
831
|
+
FfiConverterTypeConversationId.lower(conversationId), FfiConverterSequenceData.lower(keyPackages), FfiConverterUInt64.lower(nowMs)
|
|
832
|
+
)
|
|
833
|
+
},
|
|
834
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_void,
|
|
835
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_void,
|
|
836
|
+
freeFunc: ffi_ping_ffi_rust_future_free_void,
|
|
837
|
+
liftFunc: { $0 },
|
|
838
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
839
|
+
)
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
open func buildLinkingTicket(newDeviceId: DeviceId, newDeviceKp: Data, nowMs: UInt64) async throws -> LinkingTicket {
|
|
843
|
+
return
|
|
844
|
+
try await uniffiRustCallAsync(
|
|
845
|
+
rustFutureFunc: {
|
|
846
|
+
uniffi_ping_ffi_fn_method_messagingclient_build_linking_ticket(
|
|
847
|
+
self.uniffiClonePointer(),
|
|
848
|
+
FfiConverterTypeDeviceId.lower(newDeviceId), FfiConverterData.lower(newDeviceKp), FfiConverterUInt64.lower(nowMs)
|
|
849
|
+
)
|
|
850
|
+
},
|
|
851
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
852
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
853
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
854
|
+
liftFunc: FfiConverterTypeLinkingTicket.lift,
|
|
855
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
856
|
+
)
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
open func consumeLinkingTicket(ticket: LinkingTicket, nowMs: UInt64) async throws {
|
|
860
|
+
return
|
|
861
|
+
try await uniffiRustCallAsync(
|
|
862
|
+
rustFutureFunc: {
|
|
863
|
+
uniffi_ping_ffi_fn_method_messagingclient_consume_linking_ticket(
|
|
864
|
+
self.uniffiClonePointer(),
|
|
865
|
+
FfiConverterTypeLinkingTicket.lower(ticket), FfiConverterUInt64.lower(nowMs)
|
|
866
|
+
)
|
|
867
|
+
},
|
|
868
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_void,
|
|
869
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_void,
|
|
870
|
+
freeFunc: ffi_ping_ffi_rust_future_free_void,
|
|
871
|
+
liftFunc: { $0 },
|
|
872
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
873
|
+
)
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
open func createConversation(name: String?, nowMs: UInt64) async throws -> ConversationId {
|
|
877
|
+
return
|
|
878
|
+
try await uniffiRustCallAsync(
|
|
879
|
+
rustFutureFunc: {
|
|
880
|
+
uniffi_ping_ffi_fn_method_messagingclient_create_conversation(
|
|
881
|
+
self.uniffiClonePointer(),
|
|
882
|
+
FfiConverterOptionString.lower(name), FfiConverterUInt64.lower(nowMs)
|
|
883
|
+
)
|
|
884
|
+
},
|
|
885
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
886
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
887
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
888
|
+
liftFunc: FfiConverterTypeConversationId.lift,
|
|
889
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
890
|
+
)
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
open func deviceId() -> DeviceId {
|
|
894
|
+
return try! FfiConverterTypeDeviceId.lift(try! rustCall {
|
|
895
|
+
uniffi_ping_ffi_fn_method_messagingclient_device_id(self.uniffiClonePointer(), $0)
|
|
896
|
+
})
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
open func deviceInfo(nowMs: UInt64) -> DeviceInfo {
|
|
900
|
+
return try! FfiConverterTypeDeviceInfo.lift(try! rustCall {
|
|
901
|
+
uniffi_ping_ffi_fn_method_messagingclient_device_info(self.uniffiClonePointer(),
|
|
902
|
+
FfiConverterUInt64.lower(nowMs), $0)
|
|
903
|
+
})
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
open func freshKeyPackage() throws -> Data {
|
|
907
|
+
return try FfiConverterData.lift(rustCallWithError(FfiConverterTypePingError.lift) {
|
|
908
|
+
uniffi_ping_ffi_fn_method_messagingclient_fresh_key_package(self.uniffiClonePointer(), $0)
|
|
909
|
+
})
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
open func joinConversation(welcome: MessageEnvelope, nowMs: UInt64) async throws -> ConversationId {
|
|
913
|
+
return
|
|
914
|
+
try await uniffiRustCallAsync(
|
|
915
|
+
rustFutureFunc: {
|
|
916
|
+
uniffi_ping_ffi_fn_method_messagingclient_join_conversation(
|
|
917
|
+
self.uniffiClonePointer(),
|
|
918
|
+
FfiConverterTypeMessageEnvelope.lower(welcome), FfiConverterUInt64.lower(nowMs)
|
|
919
|
+
)
|
|
920
|
+
},
|
|
921
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
922
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
923
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
924
|
+
liftFunc: FfiConverterTypeConversationId.lift,
|
|
925
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
926
|
+
)
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
open func listConversations() -> [ConversationMeta] {
|
|
930
|
+
return try! FfiConverterSequenceTypeConversationMeta.lift(try! rustCall {
|
|
931
|
+
uniffi_ping_ffi_fn_method_messagingclient_list_conversations(self.uniffiClonePointer(), $0)
|
|
932
|
+
})
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
open func listDevices() -> [DeviceInfo] {
|
|
936
|
+
return try! FfiConverterSequenceTypeDeviceInfo.lift(try! rustCall {
|
|
937
|
+
uniffi_ping_ffi_fn_method_messagingclient_list_devices(self.uniffiClonePointer(), $0)
|
|
938
|
+
})
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
open func processEnvelope(envelope: MessageEnvelope, nowMs: UInt64) async throws -> IncomingMessage? {
|
|
942
|
+
return
|
|
943
|
+
try await uniffiRustCallAsync(
|
|
944
|
+
rustFutureFunc: {
|
|
945
|
+
uniffi_ping_ffi_fn_method_messagingclient_process_envelope(
|
|
946
|
+
self.uniffiClonePointer(),
|
|
947
|
+
FfiConverterTypeMessageEnvelope.lower(envelope), FfiConverterUInt64.lower(nowMs)
|
|
948
|
+
)
|
|
949
|
+
},
|
|
950
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
951
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
952
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
953
|
+
liftFunc: FfiConverterOptionTypeIncomingMessage.lift,
|
|
954
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
955
|
+
)
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
open func removeMembers(conversationId: ConversationId, leafIndexes: [UInt32], nowMs: UInt64) async throws {
|
|
959
|
+
return
|
|
960
|
+
try await uniffiRustCallAsync(
|
|
961
|
+
rustFutureFunc: {
|
|
962
|
+
uniffi_ping_ffi_fn_method_messagingclient_remove_members(
|
|
963
|
+
self.uniffiClonePointer(),
|
|
964
|
+
FfiConverterTypeConversationId.lower(conversationId), FfiConverterSequenceUInt32.lower(leafIndexes), FfiConverterUInt64.lower(nowMs)
|
|
965
|
+
)
|
|
966
|
+
},
|
|
967
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_void,
|
|
968
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_void,
|
|
969
|
+
freeFunc: ffi_ping_ffi_rust_future_free_void,
|
|
970
|
+
liftFunc: { $0 },
|
|
971
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
972
|
+
)
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
open func revokeDevice(deviceId: DeviceId, nowMs: UInt64) async throws {
|
|
976
|
+
return
|
|
977
|
+
try await uniffiRustCallAsync(
|
|
978
|
+
rustFutureFunc: {
|
|
979
|
+
uniffi_ping_ffi_fn_method_messagingclient_revoke_device(
|
|
980
|
+
self.uniffiClonePointer(),
|
|
981
|
+
FfiConverterTypeDeviceId.lower(deviceId), FfiConverterUInt64.lower(nowMs)
|
|
982
|
+
)
|
|
983
|
+
},
|
|
984
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_void,
|
|
985
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_void,
|
|
986
|
+
freeFunc: ffi_ping_ffi_rust_future_free_void,
|
|
987
|
+
liftFunc: { $0 },
|
|
988
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
989
|
+
)
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
open func send(conversationId: ConversationId, plaintext: Data, nowMs: UInt64) async throws -> MessageEnvelope {
|
|
993
|
+
return
|
|
994
|
+
try await uniffiRustCallAsync(
|
|
995
|
+
rustFutureFunc: {
|
|
996
|
+
uniffi_ping_ffi_fn_method_messagingclient_send(
|
|
997
|
+
self.uniffiClonePointer(),
|
|
998
|
+
FfiConverterTypeConversationId.lower(conversationId), FfiConverterData.lower(plaintext), FfiConverterUInt64.lower(nowMs)
|
|
999
|
+
)
|
|
1000
|
+
},
|
|
1001
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
1002
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
1003
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
1004
|
+
liftFunc: FfiConverterTypeMessageEnvelope.lift,
|
|
1005
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1006
|
+
)
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
open func setObserver(observer: MessageObserver) {
|
|
1010
|
+
try! rustCall {
|
|
1011
|
+
uniffi_ping_ffi_fn_method_messagingclient_set_observer(self.uniffiClonePointer(),
|
|
1012
|
+
FfiConverterTypeMessageObserver.lower(observer), $0)
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
open func syncConversations(nowMs: UInt64) async throws -> [IncomingMessage] {
|
|
1017
|
+
return
|
|
1018
|
+
try await uniffiRustCallAsync(
|
|
1019
|
+
rustFutureFunc: {
|
|
1020
|
+
uniffi_ping_ffi_fn_method_messagingclient_sync_conversations(
|
|
1021
|
+
self.uniffiClonePointer(),
|
|
1022
|
+
FfiConverterUInt64.lower(nowMs)
|
|
1023
|
+
)
|
|
1024
|
+
},
|
|
1025
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
1026
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
1027
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
1028
|
+
liftFunc: FfiConverterSequenceTypeIncomingMessage.lift,
|
|
1029
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1030
|
+
)
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
open func userId() -> UserId {
|
|
1034
|
+
return try! FfiConverterTypeUserId.lift(try! rustCall {
|
|
1035
|
+
uniffi_ping_ffi_fn_method_messagingclient_user_id(self.uniffiClonePointer(), $0)
|
|
1036
|
+
})
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
#if swift(>=5.8)
|
|
1041
|
+
@_documentation(visibility: private)
|
|
1042
|
+
#endif
|
|
1043
|
+
public struct FfiConverterTypeMessagingClient: FfiConverter {
|
|
1044
|
+
typealias FfiType = UnsafeMutableRawPointer
|
|
1045
|
+
typealias SwiftType = MessagingClient
|
|
1046
|
+
|
|
1047
|
+
public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MessagingClient {
|
|
1048
|
+
return MessagingClient(unsafeFromRawPointer: pointer)
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
public static func lower(_ value: MessagingClient) -> UnsafeMutableRawPointer {
|
|
1052
|
+
return value.uniffiClonePointer()
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MessagingClient {
|
|
1056
|
+
let v: UInt64 = try readInt(&buf)
|
|
1057
|
+
// The Rust code won't compile if a pointer won't fit in a UInt64.
|
|
1058
|
+
// We have to go via `UInt` because that's the thing that's the size of a pointer.
|
|
1059
|
+
let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
|
|
1060
|
+
if ptr == nil {
|
|
1061
|
+
throw UniffiInternalError.unexpectedNullPointer
|
|
1062
|
+
}
|
|
1063
|
+
return try lift(ptr!)
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
public static func write(_ value: MessagingClient, into buf: inout [UInt8]) {
|
|
1067
|
+
// This fiddling is because `Int` is the thing that's the same size as a pointer.
|
|
1068
|
+
// The Rust code won't compile if a pointer won't fit in a `UInt64`.
|
|
1069
|
+
writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
#if swift(>=5.8)
|
|
1074
|
+
@_documentation(visibility: private)
|
|
1075
|
+
#endif
|
|
1076
|
+
public func FfiConverterTypeMessagingClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> MessagingClient {
|
|
1077
|
+
return try FfiConverterTypeMessagingClient.lift(pointer)
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
#if swift(>=5.8)
|
|
1081
|
+
@_documentation(visibility: private)
|
|
1082
|
+
#endif
|
|
1083
|
+
public func FfiConverterTypeMessagingClient_lower(_ value: MessagingClient) -> UnsafeMutableRawPointer {
|
|
1084
|
+
return FfiConverterTypeMessagingClient.lower(value)
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
public protocol Storage: AnyObject {
|
|
1088
|
+
func delete(namespace: String, key: String) async throws
|
|
1089
|
+
|
|
1090
|
+
func get(namespace: String, key: String) async throws -> Data?
|
|
1091
|
+
|
|
1092
|
+
func listKeys(namespace: String, prefix: String) async throws -> [String]
|
|
1093
|
+
|
|
1094
|
+
func put(namespace: String, key: String, value: Data) async throws
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
open class StorageImpl:
|
|
1098
|
+
Storage
|
|
1099
|
+
{
|
|
1100
|
+
fileprivate let pointer: UnsafeMutableRawPointer!
|
|
1101
|
+
|
|
1102
|
+
// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
|
|
1103
|
+
#if swift(>=5.8)
|
|
1104
|
+
@_documentation(visibility: private)
|
|
1105
|
+
#endif
|
|
1106
|
+
public struct NoPointer {
|
|
1107
|
+
public init() {}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
1111
|
+
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
1112
|
+
// make it `required` without making it `public`.
|
|
1113
|
+
public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
1114
|
+
self.pointer = pointer
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// This constructor can be used to instantiate a fake object.
|
|
1118
|
+
// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
|
|
1119
|
+
//
|
|
1120
|
+
// - Warning:
|
|
1121
|
+
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
|
|
1122
|
+
#if swift(>=5.8)
|
|
1123
|
+
@_documentation(visibility: private)
|
|
1124
|
+
#endif
|
|
1125
|
+
public init(noPointer _: NoPointer) {
|
|
1126
|
+
pointer = nil
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
#if swift(>=5.8)
|
|
1130
|
+
@_documentation(visibility: private)
|
|
1131
|
+
#endif
|
|
1132
|
+
public func uniffiClonePointer() -> UnsafeMutableRawPointer {
|
|
1133
|
+
return try! rustCall { uniffi_ping_ffi_fn_clone_storage(self.pointer, $0) }
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// No primary constructor declared for this class.
|
|
1137
|
+
|
|
1138
|
+
deinit {
|
|
1139
|
+
guard let pointer = pointer else {
|
|
1140
|
+
return
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
try! rustCall { uniffi_ping_ffi_fn_free_storage(pointer, $0) }
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
open func delete(namespace: String, key: String) async throws {
|
|
1147
|
+
return
|
|
1148
|
+
try await uniffiRustCallAsync(
|
|
1149
|
+
rustFutureFunc: {
|
|
1150
|
+
uniffi_ping_ffi_fn_method_storage_delete(
|
|
1151
|
+
self.uniffiClonePointer(),
|
|
1152
|
+
FfiConverterString.lower(namespace), FfiConverterString.lower(key)
|
|
1153
|
+
)
|
|
1154
|
+
},
|
|
1155
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_void,
|
|
1156
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_void,
|
|
1157
|
+
freeFunc: ffi_ping_ffi_rust_future_free_void,
|
|
1158
|
+
liftFunc: { $0 },
|
|
1159
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1160
|
+
)
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
open func get(namespace: String, key: String) async throws -> Data? {
|
|
1164
|
+
return
|
|
1165
|
+
try await uniffiRustCallAsync(
|
|
1166
|
+
rustFutureFunc: {
|
|
1167
|
+
uniffi_ping_ffi_fn_method_storage_get(
|
|
1168
|
+
self.uniffiClonePointer(),
|
|
1169
|
+
FfiConverterString.lower(namespace), FfiConverterString.lower(key)
|
|
1170
|
+
)
|
|
1171
|
+
},
|
|
1172
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
1173
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
1174
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
1175
|
+
liftFunc: FfiConverterOptionData.lift,
|
|
1176
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1177
|
+
)
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
open func listKeys(namespace: String, prefix: String) async throws -> [String] {
|
|
1181
|
+
return
|
|
1182
|
+
try await uniffiRustCallAsync(
|
|
1183
|
+
rustFutureFunc: {
|
|
1184
|
+
uniffi_ping_ffi_fn_method_storage_list_keys(
|
|
1185
|
+
self.uniffiClonePointer(),
|
|
1186
|
+
FfiConverterString.lower(namespace), FfiConverterString.lower(prefix)
|
|
1187
|
+
)
|
|
1188
|
+
},
|
|
1189
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
1190
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
1191
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
1192
|
+
liftFunc: FfiConverterSequenceString.lift,
|
|
1193
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1194
|
+
)
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
open func put(namespace: String, key: String, value: Data) async throws {
|
|
1198
|
+
return
|
|
1199
|
+
try await uniffiRustCallAsync(
|
|
1200
|
+
rustFutureFunc: {
|
|
1201
|
+
uniffi_ping_ffi_fn_method_storage_put(
|
|
1202
|
+
self.uniffiClonePointer(),
|
|
1203
|
+
FfiConverterString.lower(namespace), FfiConverterString.lower(key), FfiConverterData.lower(value)
|
|
1204
|
+
)
|
|
1205
|
+
},
|
|
1206
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_void,
|
|
1207
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_void,
|
|
1208
|
+
freeFunc: ffi_ping_ffi_rust_future_free_void,
|
|
1209
|
+
liftFunc: { $0 },
|
|
1210
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1211
|
+
)
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/// Put the implementation in a struct so we don't pollute the top-level namespace
|
|
1216
|
+
private enum UniffiCallbackInterfaceStorage {
|
|
1217
|
+
/// Create the VTable using a series of closures.
|
|
1218
|
+
/// Swift automatically converts these into C callback functions.
|
|
1219
|
+
static var vtable: UniffiVTableCallbackInterfaceStorage = .init(
|
|
1220
|
+
delete: { (
|
|
1221
|
+
uniffiHandle: UInt64,
|
|
1222
|
+
namespace: RustBuffer,
|
|
1223
|
+
key: RustBuffer,
|
|
1224
|
+
uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid,
|
|
1225
|
+
uniffiCallbackData: UInt64,
|
|
1226
|
+
uniffiOutReturn: UnsafeMutablePointer<UniffiForeignFuture>
|
|
1227
|
+
) in
|
|
1228
|
+
let makeCall = {
|
|
1229
|
+
() async throws in
|
|
1230
|
+
guard let uniffiObj = try? FfiConverterTypeStorage.handleMap.get(handle: uniffiHandle) else {
|
|
1231
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
1232
|
+
}
|
|
1233
|
+
return try await uniffiObj.delete(
|
|
1234
|
+
namespace: FfiConverterString.lift(namespace),
|
|
1235
|
+
key: FfiConverterString.lift(key)
|
|
1236
|
+
)
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
let uniffiHandleSuccess = { (_: ()) in
|
|
1240
|
+
uniffiFutureCallback(
|
|
1241
|
+
uniffiCallbackData,
|
|
1242
|
+
UniffiForeignFutureStructVoid(
|
|
1243
|
+
callStatus: RustCallStatus()
|
|
1244
|
+
)
|
|
1245
|
+
)
|
|
1246
|
+
}
|
|
1247
|
+
let uniffiHandleError = { statusCode, errorBuf in
|
|
1248
|
+
uniffiFutureCallback(
|
|
1249
|
+
uniffiCallbackData,
|
|
1250
|
+
UniffiForeignFutureStructVoid(
|
|
1251
|
+
callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf)
|
|
1252
|
+
)
|
|
1253
|
+
)
|
|
1254
|
+
}
|
|
1255
|
+
let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError(
|
|
1256
|
+
makeCall: makeCall,
|
|
1257
|
+
handleSuccess: uniffiHandleSuccess,
|
|
1258
|
+
handleError: uniffiHandleError,
|
|
1259
|
+
lowerError: FfiConverterTypePingError.lower
|
|
1260
|
+
)
|
|
1261
|
+
uniffiOutReturn.pointee = uniffiForeignFuture
|
|
1262
|
+
},
|
|
1263
|
+
get: { (
|
|
1264
|
+
uniffiHandle: UInt64,
|
|
1265
|
+
namespace: RustBuffer,
|
|
1266
|
+
key: RustBuffer,
|
|
1267
|
+
uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer,
|
|
1268
|
+
uniffiCallbackData: UInt64,
|
|
1269
|
+
uniffiOutReturn: UnsafeMutablePointer<UniffiForeignFuture>
|
|
1270
|
+
) in
|
|
1271
|
+
let makeCall = {
|
|
1272
|
+
() async throws -> Data? in
|
|
1273
|
+
guard let uniffiObj = try? FfiConverterTypeStorage.handleMap.get(handle: uniffiHandle) else {
|
|
1274
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
1275
|
+
}
|
|
1276
|
+
return try await uniffiObj.get(
|
|
1277
|
+
namespace: FfiConverterString.lift(namespace),
|
|
1278
|
+
key: FfiConverterString.lift(key)
|
|
1279
|
+
)
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
let uniffiHandleSuccess = { (returnValue: Data?) in
|
|
1283
|
+
uniffiFutureCallback(
|
|
1284
|
+
uniffiCallbackData,
|
|
1285
|
+
UniffiForeignFutureStructRustBuffer(
|
|
1286
|
+
returnValue: FfiConverterOptionData.lower(returnValue),
|
|
1287
|
+
callStatus: RustCallStatus()
|
|
1288
|
+
)
|
|
1289
|
+
)
|
|
1290
|
+
}
|
|
1291
|
+
let uniffiHandleError = { statusCode, errorBuf in
|
|
1292
|
+
uniffiFutureCallback(
|
|
1293
|
+
uniffiCallbackData,
|
|
1294
|
+
UniffiForeignFutureStructRustBuffer(
|
|
1295
|
+
returnValue: RustBuffer.empty(),
|
|
1296
|
+
callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf)
|
|
1297
|
+
)
|
|
1298
|
+
)
|
|
1299
|
+
}
|
|
1300
|
+
let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError(
|
|
1301
|
+
makeCall: makeCall,
|
|
1302
|
+
handleSuccess: uniffiHandleSuccess,
|
|
1303
|
+
handleError: uniffiHandleError,
|
|
1304
|
+
lowerError: FfiConverterTypePingError.lower
|
|
1305
|
+
)
|
|
1306
|
+
uniffiOutReturn.pointee = uniffiForeignFuture
|
|
1307
|
+
},
|
|
1308
|
+
listKeys: { (
|
|
1309
|
+
uniffiHandle: UInt64,
|
|
1310
|
+
namespace: RustBuffer,
|
|
1311
|
+
prefix: RustBuffer,
|
|
1312
|
+
uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer,
|
|
1313
|
+
uniffiCallbackData: UInt64,
|
|
1314
|
+
uniffiOutReturn: UnsafeMutablePointer<UniffiForeignFuture>
|
|
1315
|
+
) in
|
|
1316
|
+
let makeCall = {
|
|
1317
|
+
() async throws -> [String] in
|
|
1318
|
+
guard let uniffiObj = try? FfiConverterTypeStorage.handleMap.get(handle: uniffiHandle) else {
|
|
1319
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
1320
|
+
}
|
|
1321
|
+
return try await uniffiObj.listKeys(
|
|
1322
|
+
namespace: FfiConverterString.lift(namespace),
|
|
1323
|
+
prefix: FfiConverterString.lift(prefix)
|
|
1324
|
+
)
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
let uniffiHandleSuccess = { (returnValue: [String]) in
|
|
1328
|
+
uniffiFutureCallback(
|
|
1329
|
+
uniffiCallbackData,
|
|
1330
|
+
UniffiForeignFutureStructRustBuffer(
|
|
1331
|
+
returnValue: FfiConverterSequenceString.lower(returnValue),
|
|
1332
|
+
callStatus: RustCallStatus()
|
|
1333
|
+
)
|
|
1334
|
+
)
|
|
1335
|
+
}
|
|
1336
|
+
let uniffiHandleError = { statusCode, errorBuf in
|
|
1337
|
+
uniffiFutureCallback(
|
|
1338
|
+
uniffiCallbackData,
|
|
1339
|
+
UniffiForeignFutureStructRustBuffer(
|
|
1340
|
+
returnValue: RustBuffer.empty(),
|
|
1341
|
+
callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf)
|
|
1342
|
+
)
|
|
1343
|
+
)
|
|
1344
|
+
}
|
|
1345
|
+
let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError(
|
|
1346
|
+
makeCall: makeCall,
|
|
1347
|
+
handleSuccess: uniffiHandleSuccess,
|
|
1348
|
+
handleError: uniffiHandleError,
|
|
1349
|
+
lowerError: FfiConverterTypePingError.lower
|
|
1350
|
+
)
|
|
1351
|
+
uniffiOutReturn.pointee = uniffiForeignFuture
|
|
1352
|
+
},
|
|
1353
|
+
put: { (
|
|
1354
|
+
uniffiHandle: UInt64,
|
|
1355
|
+
namespace: RustBuffer,
|
|
1356
|
+
key: RustBuffer,
|
|
1357
|
+
value: RustBuffer,
|
|
1358
|
+
uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid,
|
|
1359
|
+
uniffiCallbackData: UInt64,
|
|
1360
|
+
uniffiOutReturn: UnsafeMutablePointer<UniffiForeignFuture>
|
|
1361
|
+
) in
|
|
1362
|
+
let makeCall = {
|
|
1363
|
+
() async throws in
|
|
1364
|
+
guard let uniffiObj = try? FfiConverterTypeStorage.handleMap.get(handle: uniffiHandle) else {
|
|
1365
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
1366
|
+
}
|
|
1367
|
+
return try await uniffiObj.put(
|
|
1368
|
+
namespace: FfiConverterString.lift(namespace),
|
|
1369
|
+
key: FfiConverterString.lift(key),
|
|
1370
|
+
value: FfiConverterData.lift(value)
|
|
1371
|
+
)
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
let uniffiHandleSuccess = { (_: ()) in
|
|
1375
|
+
uniffiFutureCallback(
|
|
1376
|
+
uniffiCallbackData,
|
|
1377
|
+
UniffiForeignFutureStructVoid(
|
|
1378
|
+
callStatus: RustCallStatus()
|
|
1379
|
+
)
|
|
1380
|
+
)
|
|
1381
|
+
}
|
|
1382
|
+
let uniffiHandleError = { statusCode, errorBuf in
|
|
1383
|
+
uniffiFutureCallback(
|
|
1384
|
+
uniffiCallbackData,
|
|
1385
|
+
UniffiForeignFutureStructVoid(
|
|
1386
|
+
callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf)
|
|
1387
|
+
)
|
|
1388
|
+
)
|
|
1389
|
+
}
|
|
1390
|
+
let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError(
|
|
1391
|
+
makeCall: makeCall,
|
|
1392
|
+
handleSuccess: uniffiHandleSuccess,
|
|
1393
|
+
handleError: uniffiHandleError,
|
|
1394
|
+
lowerError: FfiConverterTypePingError.lower
|
|
1395
|
+
)
|
|
1396
|
+
uniffiOutReturn.pointee = uniffiForeignFuture
|
|
1397
|
+
},
|
|
1398
|
+
uniffiFree: { (uniffiHandle: UInt64) in
|
|
1399
|
+
let result = try? FfiConverterTypeStorage.handleMap.remove(handle: uniffiHandle)
|
|
1400
|
+
if result == nil {
|
|
1401
|
+
print("Uniffi callback interface Storage: handle missing in uniffiFree")
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
)
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
private func uniffiCallbackInitStorage() {
|
|
1408
|
+
uniffi_ping_ffi_fn_init_callback_vtable_storage(&UniffiCallbackInterfaceStorage.vtable)
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
#if swift(>=5.8)
|
|
1412
|
+
@_documentation(visibility: private)
|
|
1413
|
+
#endif
|
|
1414
|
+
public struct FfiConverterTypeStorage: FfiConverter {
|
|
1415
|
+
fileprivate static var handleMap = UniffiHandleMap<Storage>()
|
|
1416
|
+
|
|
1417
|
+
typealias FfiType = UnsafeMutableRawPointer
|
|
1418
|
+
typealias SwiftType = Storage
|
|
1419
|
+
|
|
1420
|
+
public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Storage {
|
|
1421
|
+
return StorageImpl(unsafeFromRawPointer: pointer)
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
public static func lower(_ value: Storage) -> UnsafeMutableRawPointer {
|
|
1425
|
+
guard let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: handleMap.insert(obj: value))) else {
|
|
1426
|
+
fatalError("Cast to UnsafeMutableRawPointer failed")
|
|
1427
|
+
}
|
|
1428
|
+
return ptr
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Storage {
|
|
1432
|
+
let v: UInt64 = try readInt(&buf)
|
|
1433
|
+
// The Rust code won't compile if a pointer won't fit in a UInt64.
|
|
1434
|
+
// We have to go via `UInt` because that's the thing that's the size of a pointer.
|
|
1435
|
+
let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
|
|
1436
|
+
if ptr == nil {
|
|
1437
|
+
throw UniffiInternalError.unexpectedNullPointer
|
|
1438
|
+
}
|
|
1439
|
+
return try lift(ptr!)
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
public static func write(_ value: Storage, into buf: inout [UInt8]) {
|
|
1443
|
+
// This fiddling is because `Int` is the thing that's the same size as a pointer.
|
|
1444
|
+
// The Rust code won't compile if a pointer won't fit in a `UInt64`.
|
|
1445
|
+
writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
#if swift(>=5.8)
|
|
1450
|
+
@_documentation(visibility: private)
|
|
1451
|
+
#endif
|
|
1452
|
+
public func FfiConverterTypeStorage_lift(_ pointer: UnsafeMutableRawPointer) throws -> Storage {
|
|
1453
|
+
return try FfiConverterTypeStorage.lift(pointer)
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
#if swift(>=5.8)
|
|
1457
|
+
@_documentation(visibility: private)
|
|
1458
|
+
#endif
|
|
1459
|
+
public func FfiConverterTypeStorage_lower(_ value: Storage) -> UnsafeMutableRawPointer {
|
|
1460
|
+
return FfiConverterTypeStorage.lower(value)
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
public protocol Transport: AnyObject {
|
|
1464
|
+
func discoverDevices(userId: UserId) async throws -> [DiscoveredDevice]
|
|
1465
|
+
|
|
1466
|
+
func fetchSince(conversationId: ConversationId, cursorToken: Data, limit: UInt32) async throws -> [MessageEnvelope]
|
|
1467
|
+
|
|
1468
|
+
func send(envelope: MessageEnvelope) async throws
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
open class TransportImpl:
|
|
1472
|
+
Transport
|
|
1473
|
+
{
|
|
1474
|
+
fileprivate let pointer: UnsafeMutableRawPointer!
|
|
1475
|
+
|
|
1476
|
+
// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
|
|
1477
|
+
#if swift(>=5.8)
|
|
1478
|
+
@_documentation(visibility: private)
|
|
1479
|
+
#endif
|
|
1480
|
+
public struct NoPointer {
|
|
1481
|
+
public init() {}
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// TODO: We'd like this to be `private` but for Swifty reasons,
|
|
1485
|
+
// we can't implement `FfiConverter` without making this `required` and we can't
|
|
1486
|
+
// make it `required` without making it `public`.
|
|
1487
|
+
public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
|
1488
|
+
self.pointer = pointer
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
// This constructor can be used to instantiate a fake object.
|
|
1492
|
+
// - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
|
|
1493
|
+
//
|
|
1494
|
+
// - Warning:
|
|
1495
|
+
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
|
|
1496
|
+
#if swift(>=5.8)
|
|
1497
|
+
@_documentation(visibility: private)
|
|
1498
|
+
#endif
|
|
1499
|
+
public init(noPointer _: NoPointer) {
|
|
1500
|
+
pointer = nil
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
#if swift(>=5.8)
|
|
1504
|
+
@_documentation(visibility: private)
|
|
1505
|
+
#endif
|
|
1506
|
+
public func uniffiClonePointer() -> UnsafeMutableRawPointer {
|
|
1507
|
+
return try! rustCall { uniffi_ping_ffi_fn_clone_transport(self.pointer, $0) }
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// No primary constructor declared for this class.
|
|
1511
|
+
|
|
1512
|
+
deinit {
|
|
1513
|
+
guard let pointer = pointer else {
|
|
1514
|
+
return
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
try! rustCall { uniffi_ping_ffi_fn_free_transport(pointer, $0) }
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
open func discoverDevices(userId: UserId) async throws -> [DiscoveredDevice] {
|
|
1521
|
+
return
|
|
1522
|
+
try await uniffiRustCallAsync(
|
|
1523
|
+
rustFutureFunc: {
|
|
1524
|
+
uniffi_ping_ffi_fn_method_transport_discover_devices(
|
|
1525
|
+
self.uniffiClonePointer(),
|
|
1526
|
+
FfiConverterTypeUserId.lower(userId)
|
|
1527
|
+
)
|
|
1528
|
+
},
|
|
1529
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
1530
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
1531
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
1532
|
+
liftFunc: FfiConverterSequenceTypeDiscoveredDevice.lift,
|
|
1533
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1534
|
+
)
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
open func fetchSince(conversationId: ConversationId, cursorToken: Data, limit: UInt32) async throws -> [MessageEnvelope] {
|
|
1538
|
+
return
|
|
1539
|
+
try await uniffiRustCallAsync(
|
|
1540
|
+
rustFutureFunc: {
|
|
1541
|
+
uniffi_ping_ffi_fn_method_transport_fetch_since(
|
|
1542
|
+
self.uniffiClonePointer(),
|
|
1543
|
+
FfiConverterTypeConversationId.lower(conversationId), FfiConverterData.lower(cursorToken), FfiConverterUInt32.lower(limit)
|
|
1544
|
+
)
|
|
1545
|
+
},
|
|
1546
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_rust_buffer,
|
|
1547
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_rust_buffer,
|
|
1548
|
+
freeFunc: ffi_ping_ffi_rust_future_free_rust_buffer,
|
|
1549
|
+
liftFunc: FfiConverterSequenceTypeMessageEnvelope.lift,
|
|
1550
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1551
|
+
)
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
open func send(envelope: MessageEnvelope) async throws {
|
|
1555
|
+
return
|
|
1556
|
+
try await uniffiRustCallAsync(
|
|
1557
|
+
rustFutureFunc: {
|
|
1558
|
+
uniffi_ping_ffi_fn_method_transport_send(
|
|
1559
|
+
self.uniffiClonePointer(),
|
|
1560
|
+
FfiConverterTypeMessageEnvelope.lower(envelope)
|
|
1561
|
+
)
|
|
1562
|
+
},
|
|
1563
|
+
pollFunc: ffi_ping_ffi_rust_future_poll_void,
|
|
1564
|
+
completeFunc: ffi_ping_ffi_rust_future_complete_void,
|
|
1565
|
+
freeFunc: ffi_ping_ffi_rust_future_free_void,
|
|
1566
|
+
liftFunc: { $0 },
|
|
1567
|
+
errorHandler: FfiConverterTypePingError.lift
|
|
1568
|
+
)
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
/// Put the implementation in a struct so we don't pollute the top-level namespace
|
|
1573
|
+
private enum UniffiCallbackInterfaceTransport {
|
|
1574
|
+
/// Create the VTable using a series of closures.
|
|
1575
|
+
/// Swift automatically converts these into C callback functions.
|
|
1576
|
+
static var vtable: UniffiVTableCallbackInterfaceTransport = .init(
|
|
1577
|
+
discoverDevices: { (
|
|
1578
|
+
uniffiHandle: UInt64,
|
|
1579
|
+
userId: RustBuffer,
|
|
1580
|
+
uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer,
|
|
1581
|
+
uniffiCallbackData: UInt64,
|
|
1582
|
+
uniffiOutReturn: UnsafeMutablePointer<UniffiForeignFuture>
|
|
1583
|
+
) in
|
|
1584
|
+
let makeCall = {
|
|
1585
|
+
() async throws -> [DiscoveredDevice] in
|
|
1586
|
+
guard let uniffiObj = try? FfiConverterTypeTransport.handleMap.get(handle: uniffiHandle) else {
|
|
1587
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
1588
|
+
}
|
|
1589
|
+
return try await uniffiObj.discoverDevices(
|
|
1590
|
+
userId: FfiConverterTypeUserId.lift(userId)
|
|
1591
|
+
)
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
let uniffiHandleSuccess = { (returnValue: [DiscoveredDevice]) in
|
|
1595
|
+
uniffiFutureCallback(
|
|
1596
|
+
uniffiCallbackData,
|
|
1597
|
+
UniffiForeignFutureStructRustBuffer(
|
|
1598
|
+
returnValue: FfiConverterSequenceTypeDiscoveredDevice.lower(returnValue),
|
|
1599
|
+
callStatus: RustCallStatus()
|
|
1600
|
+
)
|
|
1601
|
+
)
|
|
1602
|
+
}
|
|
1603
|
+
let uniffiHandleError = { statusCode, errorBuf in
|
|
1604
|
+
uniffiFutureCallback(
|
|
1605
|
+
uniffiCallbackData,
|
|
1606
|
+
UniffiForeignFutureStructRustBuffer(
|
|
1607
|
+
returnValue: RustBuffer.empty(),
|
|
1608
|
+
callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf)
|
|
1609
|
+
)
|
|
1610
|
+
)
|
|
1611
|
+
}
|
|
1612
|
+
let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError(
|
|
1613
|
+
makeCall: makeCall,
|
|
1614
|
+
handleSuccess: uniffiHandleSuccess,
|
|
1615
|
+
handleError: uniffiHandleError,
|
|
1616
|
+
lowerError: FfiConverterTypePingError.lower
|
|
1617
|
+
)
|
|
1618
|
+
uniffiOutReturn.pointee = uniffiForeignFuture
|
|
1619
|
+
},
|
|
1620
|
+
fetchSince: { (
|
|
1621
|
+
uniffiHandle: UInt64,
|
|
1622
|
+
conversationId: RustBuffer,
|
|
1623
|
+
cursorToken: RustBuffer,
|
|
1624
|
+
limit: UInt32,
|
|
1625
|
+
uniffiFutureCallback: @escaping UniffiForeignFutureCompleteRustBuffer,
|
|
1626
|
+
uniffiCallbackData: UInt64,
|
|
1627
|
+
uniffiOutReturn: UnsafeMutablePointer<UniffiForeignFuture>
|
|
1628
|
+
) in
|
|
1629
|
+
let makeCall = {
|
|
1630
|
+
() async throws -> [MessageEnvelope] in
|
|
1631
|
+
guard let uniffiObj = try? FfiConverterTypeTransport.handleMap.get(handle: uniffiHandle) else {
|
|
1632
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
1633
|
+
}
|
|
1634
|
+
return try await uniffiObj.fetchSince(
|
|
1635
|
+
conversationId: FfiConverterTypeConversationId.lift(conversationId),
|
|
1636
|
+
cursorToken: FfiConverterData.lift(cursorToken),
|
|
1637
|
+
limit: FfiConverterUInt32.lift(limit)
|
|
1638
|
+
)
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
let uniffiHandleSuccess = { (returnValue: [MessageEnvelope]) in
|
|
1642
|
+
uniffiFutureCallback(
|
|
1643
|
+
uniffiCallbackData,
|
|
1644
|
+
UniffiForeignFutureStructRustBuffer(
|
|
1645
|
+
returnValue: FfiConverterSequenceTypeMessageEnvelope.lower(returnValue),
|
|
1646
|
+
callStatus: RustCallStatus()
|
|
1647
|
+
)
|
|
1648
|
+
)
|
|
1649
|
+
}
|
|
1650
|
+
let uniffiHandleError = { statusCode, errorBuf in
|
|
1651
|
+
uniffiFutureCallback(
|
|
1652
|
+
uniffiCallbackData,
|
|
1653
|
+
UniffiForeignFutureStructRustBuffer(
|
|
1654
|
+
returnValue: RustBuffer.empty(),
|
|
1655
|
+
callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf)
|
|
1656
|
+
)
|
|
1657
|
+
)
|
|
1658
|
+
}
|
|
1659
|
+
let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError(
|
|
1660
|
+
makeCall: makeCall,
|
|
1661
|
+
handleSuccess: uniffiHandleSuccess,
|
|
1662
|
+
handleError: uniffiHandleError,
|
|
1663
|
+
lowerError: FfiConverterTypePingError.lower
|
|
1664
|
+
)
|
|
1665
|
+
uniffiOutReturn.pointee = uniffiForeignFuture
|
|
1666
|
+
},
|
|
1667
|
+
send: { (
|
|
1668
|
+
uniffiHandle: UInt64,
|
|
1669
|
+
envelope: RustBuffer,
|
|
1670
|
+
uniffiFutureCallback: @escaping UniffiForeignFutureCompleteVoid,
|
|
1671
|
+
uniffiCallbackData: UInt64,
|
|
1672
|
+
uniffiOutReturn: UnsafeMutablePointer<UniffiForeignFuture>
|
|
1673
|
+
) in
|
|
1674
|
+
let makeCall = {
|
|
1675
|
+
() async throws in
|
|
1676
|
+
guard let uniffiObj = try? FfiConverterTypeTransport.handleMap.get(handle: uniffiHandle) else {
|
|
1677
|
+
throw UniffiInternalError.unexpectedStaleHandle
|
|
1678
|
+
}
|
|
1679
|
+
return try await uniffiObj.send(
|
|
1680
|
+
envelope: FfiConverterTypeMessageEnvelope.lift(envelope)
|
|
1681
|
+
)
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
let uniffiHandleSuccess = { (_: ()) in
|
|
1685
|
+
uniffiFutureCallback(
|
|
1686
|
+
uniffiCallbackData,
|
|
1687
|
+
UniffiForeignFutureStructVoid(
|
|
1688
|
+
callStatus: RustCallStatus()
|
|
1689
|
+
)
|
|
1690
|
+
)
|
|
1691
|
+
}
|
|
1692
|
+
let uniffiHandleError = { statusCode, errorBuf in
|
|
1693
|
+
uniffiFutureCallback(
|
|
1694
|
+
uniffiCallbackData,
|
|
1695
|
+
UniffiForeignFutureStructVoid(
|
|
1696
|
+
callStatus: RustCallStatus(code: statusCode, errorBuf: errorBuf)
|
|
1697
|
+
)
|
|
1698
|
+
)
|
|
1699
|
+
}
|
|
1700
|
+
let uniffiForeignFuture = uniffiTraitInterfaceCallAsyncWithError(
|
|
1701
|
+
makeCall: makeCall,
|
|
1702
|
+
handleSuccess: uniffiHandleSuccess,
|
|
1703
|
+
handleError: uniffiHandleError,
|
|
1704
|
+
lowerError: FfiConverterTypePingError.lower
|
|
1705
|
+
)
|
|
1706
|
+
uniffiOutReturn.pointee = uniffiForeignFuture
|
|
1707
|
+
},
|
|
1708
|
+
uniffiFree: { (uniffiHandle: UInt64) in
|
|
1709
|
+
let result = try? FfiConverterTypeTransport.handleMap.remove(handle: uniffiHandle)
|
|
1710
|
+
if result == nil {
|
|
1711
|
+
print("Uniffi callback interface Transport: handle missing in uniffiFree")
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
)
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
private func uniffiCallbackInitTransport() {
|
|
1718
|
+
uniffi_ping_ffi_fn_init_callback_vtable_transport(&UniffiCallbackInterfaceTransport.vtable)
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
#if swift(>=5.8)
|
|
1722
|
+
@_documentation(visibility: private)
|
|
1723
|
+
#endif
|
|
1724
|
+
public struct FfiConverterTypeTransport: FfiConverter {
|
|
1725
|
+
fileprivate static var handleMap = UniffiHandleMap<Transport>()
|
|
1726
|
+
|
|
1727
|
+
typealias FfiType = UnsafeMutableRawPointer
|
|
1728
|
+
typealias SwiftType = Transport
|
|
1729
|
+
|
|
1730
|
+
public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Transport {
|
|
1731
|
+
return TransportImpl(unsafeFromRawPointer: pointer)
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
public static func lower(_ value: Transport) -> UnsafeMutableRawPointer {
|
|
1735
|
+
guard let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: handleMap.insert(obj: value))) else {
|
|
1736
|
+
fatalError("Cast to UnsafeMutableRawPointer failed")
|
|
1737
|
+
}
|
|
1738
|
+
return ptr
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Transport {
|
|
1742
|
+
let v: UInt64 = try readInt(&buf)
|
|
1743
|
+
// The Rust code won't compile if a pointer won't fit in a UInt64.
|
|
1744
|
+
// We have to go via `UInt` because that's the thing that's the size of a pointer.
|
|
1745
|
+
let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
|
|
1746
|
+
if ptr == nil {
|
|
1747
|
+
throw UniffiInternalError.unexpectedNullPointer
|
|
1748
|
+
}
|
|
1749
|
+
return try lift(ptr!)
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
public static func write(_ value: Transport, into buf: inout [UInt8]) {
|
|
1753
|
+
// This fiddling is because `Int` is the thing that's the same size as a pointer.
|
|
1754
|
+
// The Rust code won't compile if a pointer won't fit in a `UInt64`.
|
|
1755
|
+
writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
#if swift(>=5.8)
|
|
1760
|
+
@_documentation(visibility: private)
|
|
1761
|
+
#endif
|
|
1762
|
+
public func FfiConverterTypeTransport_lift(_ pointer: UnsafeMutableRawPointer) throws -> Transport {
|
|
1763
|
+
return try FfiConverterTypeTransport.lift(pointer)
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
#if swift(>=5.8)
|
|
1767
|
+
@_documentation(visibility: private)
|
|
1768
|
+
#endif
|
|
1769
|
+
public func FfiConverterTypeTransport_lower(_ value: Transport) -> UnsafeMutableRawPointer {
|
|
1770
|
+
return FfiConverterTypeTransport.lower(value)
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
public struct ConversationId {
|
|
1774
|
+
public var value: Data
|
|
1775
|
+
|
|
1776
|
+
/// Default memberwise initializers are never public by default, so we
|
|
1777
|
+
/// declare one manually.
|
|
1778
|
+
public init(value: Data) {
|
|
1779
|
+
self.value = value
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
extension ConversationId: Equatable, Hashable {
|
|
1784
|
+
public static func == (lhs: ConversationId, rhs: ConversationId) -> Bool {
|
|
1785
|
+
if lhs.value != rhs.value {
|
|
1786
|
+
return false
|
|
1787
|
+
}
|
|
1788
|
+
return true
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
public func hash(into hasher: inout Hasher) {
|
|
1792
|
+
hasher.combine(value)
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
#if swift(>=5.8)
|
|
1797
|
+
@_documentation(visibility: private)
|
|
1798
|
+
#endif
|
|
1799
|
+
public struct FfiConverterTypeConversationId: FfiConverterRustBuffer {
|
|
1800
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ConversationId {
|
|
1801
|
+
return
|
|
1802
|
+
try ConversationId(
|
|
1803
|
+
value: FfiConverterData.read(from: &buf)
|
|
1804
|
+
)
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
public static func write(_ value: ConversationId, into buf: inout [UInt8]) {
|
|
1808
|
+
FfiConverterData.write(value.value, into: &buf)
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
#if swift(>=5.8)
|
|
1813
|
+
@_documentation(visibility: private)
|
|
1814
|
+
#endif
|
|
1815
|
+
public func FfiConverterTypeConversationId_lift(_ buf: RustBuffer) throws -> ConversationId {
|
|
1816
|
+
return try FfiConverterTypeConversationId.lift(buf)
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
#if swift(>=5.8)
|
|
1820
|
+
@_documentation(visibility: private)
|
|
1821
|
+
#endif
|
|
1822
|
+
public func FfiConverterTypeConversationId_lower(_ value: ConversationId) -> RustBuffer {
|
|
1823
|
+
return FfiConverterTypeConversationId.lower(value)
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
public struct ConversationMeta {
|
|
1827
|
+
public var id: ConversationId
|
|
1828
|
+
public var name: String?
|
|
1829
|
+
public var epoch: UInt64
|
|
1830
|
+
public var memberCount: UInt32
|
|
1831
|
+
public var isDeviceGroup: Bool
|
|
1832
|
+
public var createdAtMs: UInt64
|
|
1833
|
+
|
|
1834
|
+
/// Default memberwise initializers are never public by default, so we
|
|
1835
|
+
/// declare one manually.
|
|
1836
|
+
public init(id: ConversationId, name: String?, epoch: UInt64, memberCount: UInt32, isDeviceGroup: Bool, createdAtMs: UInt64) {
|
|
1837
|
+
self.id = id
|
|
1838
|
+
self.name = name
|
|
1839
|
+
self.epoch = epoch
|
|
1840
|
+
self.memberCount = memberCount
|
|
1841
|
+
self.isDeviceGroup = isDeviceGroup
|
|
1842
|
+
self.createdAtMs = createdAtMs
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
extension ConversationMeta: Equatable, Hashable {
|
|
1847
|
+
public static func == (lhs: ConversationMeta, rhs: ConversationMeta) -> Bool {
|
|
1848
|
+
if lhs.id != rhs.id {
|
|
1849
|
+
return false
|
|
1850
|
+
}
|
|
1851
|
+
if lhs.name != rhs.name {
|
|
1852
|
+
return false
|
|
1853
|
+
}
|
|
1854
|
+
if lhs.epoch != rhs.epoch {
|
|
1855
|
+
return false
|
|
1856
|
+
}
|
|
1857
|
+
if lhs.memberCount != rhs.memberCount {
|
|
1858
|
+
return false
|
|
1859
|
+
}
|
|
1860
|
+
if lhs.isDeviceGroup != rhs.isDeviceGroup {
|
|
1861
|
+
return false
|
|
1862
|
+
}
|
|
1863
|
+
if lhs.createdAtMs != rhs.createdAtMs {
|
|
1864
|
+
return false
|
|
1865
|
+
}
|
|
1866
|
+
return true
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
public func hash(into hasher: inout Hasher) {
|
|
1870
|
+
hasher.combine(id)
|
|
1871
|
+
hasher.combine(name)
|
|
1872
|
+
hasher.combine(epoch)
|
|
1873
|
+
hasher.combine(memberCount)
|
|
1874
|
+
hasher.combine(isDeviceGroup)
|
|
1875
|
+
hasher.combine(createdAtMs)
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
#if swift(>=5.8)
|
|
1880
|
+
@_documentation(visibility: private)
|
|
1881
|
+
#endif
|
|
1882
|
+
public struct FfiConverterTypeConversationMeta: FfiConverterRustBuffer {
|
|
1883
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ConversationMeta {
|
|
1884
|
+
return
|
|
1885
|
+
try ConversationMeta(
|
|
1886
|
+
id: FfiConverterTypeConversationId.read(from: &buf),
|
|
1887
|
+
name: FfiConverterOptionString.read(from: &buf),
|
|
1888
|
+
epoch: FfiConverterUInt64.read(from: &buf),
|
|
1889
|
+
memberCount: FfiConverterUInt32.read(from: &buf),
|
|
1890
|
+
isDeviceGroup: FfiConverterBool.read(from: &buf),
|
|
1891
|
+
createdAtMs: FfiConverterUInt64.read(from: &buf)
|
|
1892
|
+
)
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
public static func write(_ value: ConversationMeta, into buf: inout [UInt8]) {
|
|
1896
|
+
FfiConverterTypeConversationId.write(value.id, into: &buf)
|
|
1897
|
+
FfiConverterOptionString.write(value.name, into: &buf)
|
|
1898
|
+
FfiConverterUInt64.write(value.epoch, into: &buf)
|
|
1899
|
+
FfiConverterUInt32.write(value.memberCount, into: &buf)
|
|
1900
|
+
FfiConverterBool.write(value.isDeviceGroup, into: &buf)
|
|
1901
|
+
FfiConverterUInt64.write(value.createdAtMs, into: &buf)
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
#if swift(>=5.8)
|
|
1906
|
+
@_documentation(visibility: private)
|
|
1907
|
+
#endif
|
|
1908
|
+
public func FfiConverterTypeConversationMeta_lift(_ buf: RustBuffer) throws -> ConversationMeta {
|
|
1909
|
+
return try FfiConverterTypeConversationMeta.lift(buf)
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
#if swift(>=5.8)
|
|
1913
|
+
@_documentation(visibility: private)
|
|
1914
|
+
#endif
|
|
1915
|
+
public func FfiConverterTypeConversationMeta_lower(_ value: ConversationMeta) -> RustBuffer {
|
|
1916
|
+
return FfiConverterTypeConversationMeta.lower(value)
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
public struct DeviceId {
|
|
1920
|
+
public var value: Data
|
|
1921
|
+
|
|
1922
|
+
/// Default memberwise initializers are never public by default, so we
|
|
1923
|
+
/// declare one manually.
|
|
1924
|
+
public init(value: Data) {
|
|
1925
|
+
self.value = value
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
extension DeviceId: Equatable, Hashable {
|
|
1930
|
+
public static func == (lhs: DeviceId, rhs: DeviceId) -> Bool {
|
|
1931
|
+
if lhs.value != rhs.value {
|
|
1932
|
+
return false
|
|
1933
|
+
}
|
|
1934
|
+
return true
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
public func hash(into hasher: inout Hasher) {
|
|
1938
|
+
hasher.combine(value)
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
#if swift(>=5.8)
|
|
1943
|
+
@_documentation(visibility: private)
|
|
1944
|
+
#endif
|
|
1945
|
+
public struct FfiConverterTypeDeviceId: FfiConverterRustBuffer {
|
|
1946
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DeviceId {
|
|
1947
|
+
return
|
|
1948
|
+
try DeviceId(
|
|
1949
|
+
value: FfiConverterData.read(from: &buf)
|
|
1950
|
+
)
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
public static func write(_ value: DeviceId, into buf: inout [UInt8]) {
|
|
1954
|
+
FfiConverterData.write(value.value, into: &buf)
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
#if swift(>=5.8)
|
|
1959
|
+
@_documentation(visibility: private)
|
|
1960
|
+
#endif
|
|
1961
|
+
public func FfiConverterTypeDeviceId_lift(_ buf: RustBuffer) throws -> DeviceId {
|
|
1962
|
+
return try FfiConverterTypeDeviceId.lift(buf)
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
#if swift(>=5.8)
|
|
1966
|
+
@_documentation(visibility: private)
|
|
1967
|
+
#endif
|
|
1968
|
+
public func FfiConverterTypeDeviceId_lower(_ value: DeviceId) -> RustBuffer {
|
|
1969
|
+
return FfiConverterTypeDeviceId.lower(value)
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
public struct DeviceInfo {
|
|
1973
|
+
public var deviceId: DeviceId
|
|
1974
|
+
public var userId: UserId
|
|
1975
|
+
public var label: String
|
|
1976
|
+
public var createdAtMs: UInt64
|
|
1977
|
+
public var lastSeenMs: UInt64
|
|
1978
|
+
public var revoked: Bool
|
|
1979
|
+
|
|
1980
|
+
/// Default memberwise initializers are never public by default, so we
|
|
1981
|
+
/// declare one manually.
|
|
1982
|
+
public init(deviceId: DeviceId, userId: UserId, label: String, createdAtMs: UInt64, lastSeenMs: UInt64, revoked: Bool) {
|
|
1983
|
+
self.deviceId = deviceId
|
|
1984
|
+
self.userId = userId
|
|
1985
|
+
self.label = label
|
|
1986
|
+
self.createdAtMs = createdAtMs
|
|
1987
|
+
self.lastSeenMs = lastSeenMs
|
|
1988
|
+
self.revoked = revoked
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
extension DeviceInfo: Equatable, Hashable {
|
|
1993
|
+
public static func == (lhs: DeviceInfo, rhs: DeviceInfo) -> Bool {
|
|
1994
|
+
if lhs.deviceId != rhs.deviceId {
|
|
1995
|
+
return false
|
|
1996
|
+
}
|
|
1997
|
+
if lhs.userId != rhs.userId {
|
|
1998
|
+
return false
|
|
1999
|
+
}
|
|
2000
|
+
if lhs.label != rhs.label {
|
|
2001
|
+
return false
|
|
2002
|
+
}
|
|
2003
|
+
if lhs.createdAtMs != rhs.createdAtMs {
|
|
2004
|
+
return false
|
|
2005
|
+
}
|
|
2006
|
+
if lhs.lastSeenMs != rhs.lastSeenMs {
|
|
2007
|
+
return false
|
|
2008
|
+
}
|
|
2009
|
+
if lhs.revoked != rhs.revoked {
|
|
2010
|
+
return false
|
|
2011
|
+
}
|
|
2012
|
+
return true
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
public func hash(into hasher: inout Hasher) {
|
|
2016
|
+
hasher.combine(deviceId)
|
|
2017
|
+
hasher.combine(userId)
|
|
2018
|
+
hasher.combine(label)
|
|
2019
|
+
hasher.combine(createdAtMs)
|
|
2020
|
+
hasher.combine(lastSeenMs)
|
|
2021
|
+
hasher.combine(revoked)
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
#if swift(>=5.8)
|
|
2026
|
+
@_documentation(visibility: private)
|
|
2027
|
+
#endif
|
|
2028
|
+
public struct FfiConverterTypeDeviceInfo: FfiConverterRustBuffer {
|
|
2029
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DeviceInfo {
|
|
2030
|
+
return
|
|
2031
|
+
try DeviceInfo(
|
|
2032
|
+
deviceId: FfiConverterTypeDeviceId.read(from: &buf),
|
|
2033
|
+
userId: FfiConverterTypeUserId.read(from: &buf),
|
|
2034
|
+
label: FfiConverterString.read(from: &buf),
|
|
2035
|
+
createdAtMs: FfiConverterUInt64.read(from: &buf),
|
|
2036
|
+
lastSeenMs: FfiConverterUInt64.read(from: &buf),
|
|
2037
|
+
revoked: FfiConverterBool.read(from: &buf)
|
|
2038
|
+
)
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
public static func write(_ value: DeviceInfo, into buf: inout [UInt8]) {
|
|
2042
|
+
FfiConverterTypeDeviceId.write(value.deviceId, into: &buf)
|
|
2043
|
+
FfiConverterTypeUserId.write(value.userId, into: &buf)
|
|
2044
|
+
FfiConverterString.write(value.label, into: &buf)
|
|
2045
|
+
FfiConverterUInt64.write(value.createdAtMs, into: &buf)
|
|
2046
|
+
FfiConverterUInt64.write(value.lastSeenMs, into: &buf)
|
|
2047
|
+
FfiConverterBool.write(value.revoked, into: &buf)
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
#if swift(>=5.8)
|
|
2052
|
+
@_documentation(visibility: private)
|
|
2053
|
+
#endif
|
|
2054
|
+
public func FfiConverterTypeDeviceInfo_lift(_ buf: RustBuffer) throws -> DeviceInfo {
|
|
2055
|
+
return try FfiConverterTypeDeviceInfo.lift(buf)
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
#if swift(>=5.8)
|
|
2059
|
+
@_documentation(visibility: private)
|
|
2060
|
+
#endif
|
|
2061
|
+
public func FfiConverterTypeDeviceInfo_lower(_ value: DeviceInfo) -> RustBuffer {
|
|
2062
|
+
return FfiConverterTypeDeviceInfo.lower(value)
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
public struct DiscoveredDevice {
|
|
2066
|
+
public var deviceId: DeviceId
|
|
2067
|
+
public var keyPackage: Data
|
|
2068
|
+
|
|
2069
|
+
/// Default memberwise initializers are never public by default, so we
|
|
2070
|
+
/// declare one manually.
|
|
2071
|
+
public init(deviceId: DeviceId, keyPackage: Data) {
|
|
2072
|
+
self.deviceId = deviceId
|
|
2073
|
+
self.keyPackage = keyPackage
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
extension DiscoveredDevice: Equatable, Hashable {
|
|
2078
|
+
public static func == (lhs: DiscoveredDevice, rhs: DiscoveredDevice) -> Bool {
|
|
2079
|
+
if lhs.deviceId != rhs.deviceId {
|
|
2080
|
+
return false
|
|
2081
|
+
}
|
|
2082
|
+
if lhs.keyPackage != rhs.keyPackage {
|
|
2083
|
+
return false
|
|
2084
|
+
}
|
|
2085
|
+
return true
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
public func hash(into hasher: inout Hasher) {
|
|
2089
|
+
hasher.combine(deviceId)
|
|
2090
|
+
hasher.combine(keyPackage)
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
#if swift(>=5.8)
|
|
2095
|
+
@_documentation(visibility: private)
|
|
2096
|
+
#endif
|
|
2097
|
+
public struct FfiConverterTypeDiscoveredDevice: FfiConverterRustBuffer {
|
|
2098
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DiscoveredDevice {
|
|
2099
|
+
return
|
|
2100
|
+
try DiscoveredDevice(
|
|
2101
|
+
deviceId: FfiConverterTypeDeviceId.read(from: &buf),
|
|
2102
|
+
keyPackage: FfiConverterData.read(from: &buf)
|
|
2103
|
+
)
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
public static func write(_ value: DiscoveredDevice, into buf: inout [UInt8]) {
|
|
2107
|
+
FfiConverterTypeDeviceId.write(value.deviceId, into: &buf)
|
|
2108
|
+
FfiConverterData.write(value.keyPackage, into: &buf)
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
#if swift(>=5.8)
|
|
2113
|
+
@_documentation(visibility: private)
|
|
2114
|
+
#endif
|
|
2115
|
+
public func FfiConverterTypeDiscoveredDevice_lift(_ buf: RustBuffer) throws -> DiscoveredDevice {
|
|
2116
|
+
return try FfiConverterTypeDiscoveredDevice.lift(buf)
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
#if swift(>=5.8)
|
|
2120
|
+
@_documentation(visibility: private)
|
|
2121
|
+
#endif
|
|
2122
|
+
public func FfiConverterTypeDiscoveredDevice_lower(_ value: DiscoveredDevice) -> RustBuffer {
|
|
2123
|
+
return FfiConverterTypeDiscoveredDevice.lower(value)
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
public struct Hlc {
|
|
2127
|
+
public var wallMs: UInt64
|
|
2128
|
+
public var logical: UInt32
|
|
2129
|
+
|
|
2130
|
+
/// Default memberwise initializers are never public by default, so we
|
|
2131
|
+
/// declare one manually.
|
|
2132
|
+
public init(wallMs: UInt64, logical: UInt32) {
|
|
2133
|
+
self.wallMs = wallMs
|
|
2134
|
+
self.logical = logical
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
extension Hlc: Equatable, Hashable {
|
|
2139
|
+
public static func == (lhs: Hlc, rhs: Hlc) -> Bool {
|
|
2140
|
+
if lhs.wallMs != rhs.wallMs {
|
|
2141
|
+
return false
|
|
2142
|
+
}
|
|
2143
|
+
if lhs.logical != rhs.logical {
|
|
2144
|
+
return false
|
|
2145
|
+
}
|
|
2146
|
+
return true
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
public func hash(into hasher: inout Hasher) {
|
|
2150
|
+
hasher.combine(wallMs)
|
|
2151
|
+
hasher.combine(logical)
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
#if swift(>=5.8)
|
|
2156
|
+
@_documentation(visibility: private)
|
|
2157
|
+
#endif
|
|
2158
|
+
public struct FfiConverterTypeHlc: FfiConverterRustBuffer {
|
|
2159
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Hlc {
|
|
2160
|
+
return
|
|
2161
|
+
try Hlc(
|
|
2162
|
+
wallMs: FfiConverterUInt64.read(from: &buf),
|
|
2163
|
+
logical: FfiConverterUInt32.read(from: &buf)
|
|
2164
|
+
)
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
public static func write(_ value: Hlc, into buf: inout [UInt8]) {
|
|
2168
|
+
FfiConverterUInt64.write(value.wallMs, into: &buf)
|
|
2169
|
+
FfiConverterUInt32.write(value.logical, into: &buf)
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
#if swift(>=5.8)
|
|
2174
|
+
@_documentation(visibility: private)
|
|
2175
|
+
#endif
|
|
2176
|
+
public func FfiConverterTypeHlc_lift(_ buf: RustBuffer) throws -> Hlc {
|
|
2177
|
+
return try FfiConverterTypeHlc.lift(buf)
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
#if swift(>=5.8)
|
|
2181
|
+
@_documentation(visibility: private)
|
|
2182
|
+
#endif
|
|
2183
|
+
public func FfiConverterTypeHlc_lower(_ value: Hlc) -> RustBuffer {
|
|
2184
|
+
return FfiConverterTypeHlc.lower(value)
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
public struct IncomingMessage {
|
|
2188
|
+
public var conversationId: ConversationId
|
|
2189
|
+
public var senderDevice: DeviceId
|
|
2190
|
+
public var epoch: UInt64
|
|
2191
|
+
public var hlc: Hlc
|
|
2192
|
+
public var plaintext: Data
|
|
2193
|
+
public var contentHash: Data
|
|
2194
|
+
|
|
2195
|
+
/// Default memberwise initializers are never public by default, so we
|
|
2196
|
+
/// declare one manually.
|
|
2197
|
+
public init(conversationId: ConversationId, senderDevice: DeviceId, epoch: UInt64, hlc: Hlc, plaintext: Data, contentHash: Data) {
|
|
2198
|
+
self.conversationId = conversationId
|
|
2199
|
+
self.senderDevice = senderDevice
|
|
2200
|
+
self.epoch = epoch
|
|
2201
|
+
self.hlc = hlc
|
|
2202
|
+
self.plaintext = plaintext
|
|
2203
|
+
self.contentHash = contentHash
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
extension IncomingMessage: Equatable, Hashable {
|
|
2208
|
+
public static func == (lhs: IncomingMessage, rhs: IncomingMessage) -> Bool {
|
|
2209
|
+
if lhs.conversationId != rhs.conversationId {
|
|
2210
|
+
return false
|
|
2211
|
+
}
|
|
2212
|
+
if lhs.senderDevice != rhs.senderDevice {
|
|
2213
|
+
return false
|
|
2214
|
+
}
|
|
2215
|
+
if lhs.epoch != rhs.epoch {
|
|
2216
|
+
return false
|
|
2217
|
+
}
|
|
2218
|
+
if lhs.hlc != rhs.hlc {
|
|
2219
|
+
return false
|
|
2220
|
+
}
|
|
2221
|
+
if lhs.plaintext != rhs.plaintext {
|
|
2222
|
+
return false
|
|
2223
|
+
}
|
|
2224
|
+
if lhs.contentHash != rhs.contentHash {
|
|
2225
|
+
return false
|
|
2226
|
+
}
|
|
2227
|
+
return true
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
public func hash(into hasher: inout Hasher) {
|
|
2231
|
+
hasher.combine(conversationId)
|
|
2232
|
+
hasher.combine(senderDevice)
|
|
2233
|
+
hasher.combine(epoch)
|
|
2234
|
+
hasher.combine(hlc)
|
|
2235
|
+
hasher.combine(plaintext)
|
|
2236
|
+
hasher.combine(contentHash)
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
#if swift(>=5.8)
|
|
2241
|
+
@_documentation(visibility: private)
|
|
2242
|
+
#endif
|
|
2243
|
+
public struct FfiConverterTypeIncomingMessage: FfiConverterRustBuffer {
|
|
2244
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> IncomingMessage {
|
|
2245
|
+
return
|
|
2246
|
+
try IncomingMessage(
|
|
2247
|
+
conversationId: FfiConverterTypeConversationId.read(from: &buf),
|
|
2248
|
+
senderDevice: FfiConverterTypeDeviceId.read(from: &buf),
|
|
2249
|
+
epoch: FfiConverterUInt64.read(from: &buf),
|
|
2250
|
+
hlc: FfiConverterTypeHlc.read(from: &buf),
|
|
2251
|
+
plaintext: FfiConverterData.read(from: &buf),
|
|
2252
|
+
contentHash: FfiConverterData.read(from: &buf)
|
|
2253
|
+
)
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
public static func write(_ value: IncomingMessage, into buf: inout [UInt8]) {
|
|
2257
|
+
FfiConverterTypeConversationId.write(value.conversationId, into: &buf)
|
|
2258
|
+
FfiConverterTypeDeviceId.write(value.senderDevice, into: &buf)
|
|
2259
|
+
FfiConverterUInt64.write(value.epoch, into: &buf)
|
|
2260
|
+
FfiConverterTypeHlc.write(value.hlc, into: &buf)
|
|
2261
|
+
FfiConverterData.write(value.plaintext, into: &buf)
|
|
2262
|
+
FfiConverterData.write(value.contentHash, into: &buf)
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
#if swift(>=5.8)
|
|
2267
|
+
@_documentation(visibility: private)
|
|
2268
|
+
#endif
|
|
2269
|
+
public func FfiConverterTypeIncomingMessage_lift(_ buf: RustBuffer) throws -> IncomingMessage {
|
|
2270
|
+
return try FfiConverterTypeIncomingMessage.lift(buf)
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
#if swift(>=5.8)
|
|
2274
|
+
@_documentation(visibility: private)
|
|
2275
|
+
#endif
|
|
2276
|
+
public func FfiConverterTypeIncomingMessage_lower(_ value: IncomingMessage) -> RustBuffer {
|
|
2277
|
+
return FfiConverterTypeIncomingMessage.lower(value)
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
public struct LinkingTicket {
|
|
2281
|
+
public var v: UInt8
|
|
2282
|
+
public var userId: UserId
|
|
2283
|
+
public var userPubkey: Data
|
|
2284
|
+
public var newDeviceId: DeviceId
|
|
2285
|
+
public var deviceBindingSig: Data
|
|
2286
|
+
public var deviceGroupWelcome: Data
|
|
2287
|
+
public var catchupSnapshot: Data
|
|
2288
|
+
|
|
2289
|
+
/// Default memberwise initializers are never public by default, so we
|
|
2290
|
+
/// declare one manually.
|
|
2291
|
+
public init(v: UInt8, userId: UserId, userPubkey: Data, newDeviceId: DeviceId, deviceBindingSig: Data, deviceGroupWelcome: Data, catchupSnapshot: Data) {
|
|
2292
|
+
self.v = v
|
|
2293
|
+
self.userId = userId
|
|
2294
|
+
self.userPubkey = userPubkey
|
|
2295
|
+
self.newDeviceId = newDeviceId
|
|
2296
|
+
self.deviceBindingSig = deviceBindingSig
|
|
2297
|
+
self.deviceGroupWelcome = deviceGroupWelcome
|
|
2298
|
+
self.catchupSnapshot = catchupSnapshot
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
extension LinkingTicket: Equatable, Hashable {
|
|
2303
|
+
public static func == (lhs: LinkingTicket, rhs: LinkingTicket) -> Bool {
|
|
2304
|
+
if lhs.v != rhs.v {
|
|
2305
|
+
return false
|
|
2306
|
+
}
|
|
2307
|
+
if lhs.userId != rhs.userId {
|
|
2308
|
+
return false
|
|
2309
|
+
}
|
|
2310
|
+
if lhs.userPubkey != rhs.userPubkey {
|
|
2311
|
+
return false
|
|
2312
|
+
}
|
|
2313
|
+
if lhs.newDeviceId != rhs.newDeviceId {
|
|
2314
|
+
return false
|
|
2315
|
+
}
|
|
2316
|
+
if lhs.deviceBindingSig != rhs.deviceBindingSig {
|
|
2317
|
+
return false
|
|
2318
|
+
}
|
|
2319
|
+
if lhs.deviceGroupWelcome != rhs.deviceGroupWelcome {
|
|
2320
|
+
return false
|
|
2321
|
+
}
|
|
2322
|
+
if lhs.catchupSnapshot != rhs.catchupSnapshot {
|
|
2323
|
+
return false
|
|
2324
|
+
}
|
|
2325
|
+
return true
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
public func hash(into hasher: inout Hasher) {
|
|
2329
|
+
hasher.combine(v)
|
|
2330
|
+
hasher.combine(userId)
|
|
2331
|
+
hasher.combine(userPubkey)
|
|
2332
|
+
hasher.combine(newDeviceId)
|
|
2333
|
+
hasher.combine(deviceBindingSig)
|
|
2334
|
+
hasher.combine(deviceGroupWelcome)
|
|
2335
|
+
hasher.combine(catchupSnapshot)
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
#if swift(>=5.8)
|
|
2340
|
+
@_documentation(visibility: private)
|
|
2341
|
+
#endif
|
|
2342
|
+
public struct FfiConverterTypeLinkingTicket: FfiConverterRustBuffer {
|
|
2343
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> LinkingTicket {
|
|
2344
|
+
return
|
|
2345
|
+
try LinkingTicket(
|
|
2346
|
+
v: FfiConverterUInt8.read(from: &buf),
|
|
2347
|
+
userId: FfiConverterTypeUserId.read(from: &buf),
|
|
2348
|
+
userPubkey: FfiConverterData.read(from: &buf),
|
|
2349
|
+
newDeviceId: FfiConverterTypeDeviceId.read(from: &buf),
|
|
2350
|
+
deviceBindingSig: FfiConverterData.read(from: &buf),
|
|
2351
|
+
deviceGroupWelcome: FfiConverterData.read(from: &buf),
|
|
2352
|
+
catchupSnapshot: FfiConverterData.read(from: &buf)
|
|
2353
|
+
)
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
public static func write(_ value: LinkingTicket, into buf: inout [UInt8]) {
|
|
2357
|
+
FfiConverterUInt8.write(value.v, into: &buf)
|
|
2358
|
+
FfiConverterTypeUserId.write(value.userId, into: &buf)
|
|
2359
|
+
FfiConverterData.write(value.userPubkey, into: &buf)
|
|
2360
|
+
FfiConverterTypeDeviceId.write(value.newDeviceId, into: &buf)
|
|
2361
|
+
FfiConverterData.write(value.deviceBindingSig, into: &buf)
|
|
2362
|
+
FfiConverterData.write(value.deviceGroupWelcome, into: &buf)
|
|
2363
|
+
FfiConverterData.write(value.catchupSnapshot, into: &buf)
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
#if swift(>=5.8)
|
|
2368
|
+
@_documentation(visibility: private)
|
|
2369
|
+
#endif
|
|
2370
|
+
public func FfiConverterTypeLinkingTicket_lift(_ buf: RustBuffer) throws -> LinkingTicket {
|
|
2371
|
+
return try FfiConverterTypeLinkingTicket.lift(buf)
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
#if swift(>=5.8)
|
|
2375
|
+
@_documentation(visibility: private)
|
|
2376
|
+
#endif
|
|
2377
|
+
public func FfiConverterTypeLinkingTicket_lower(_ value: LinkingTicket) -> RustBuffer {
|
|
2378
|
+
return FfiConverterTypeLinkingTicket.lower(value)
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
public struct MessageEnvelope {
|
|
2382
|
+
public var v: UInt8
|
|
2383
|
+
public var conversationId: ConversationId
|
|
2384
|
+
public var epoch: UInt64
|
|
2385
|
+
public var kind: MessageKind
|
|
2386
|
+
public var senderDevice: DeviceId
|
|
2387
|
+
public var seq: UInt64
|
|
2388
|
+
public var hlc: Hlc
|
|
2389
|
+
public var payload: Data
|
|
2390
|
+
public var contentHash: Data
|
|
2391
|
+
|
|
2392
|
+
/// Default memberwise initializers are never public by default, so we
|
|
2393
|
+
/// declare one manually.
|
|
2394
|
+
public init(v: UInt8, conversationId: ConversationId, epoch: UInt64, kind: MessageKind, senderDevice: DeviceId, seq: UInt64, hlc: Hlc, payload: Data, contentHash: Data) {
|
|
2395
|
+
self.v = v
|
|
2396
|
+
self.conversationId = conversationId
|
|
2397
|
+
self.epoch = epoch
|
|
2398
|
+
self.kind = kind
|
|
2399
|
+
self.senderDevice = senderDevice
|
|
2400
|
+
self.seq = seq
|
|
2401
|
+
self.hlc = hlc
|
|
2402
|
+
self.payload = payload
|
|
2403
|
+
self.contentHash = contentHash
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
extension MessageEnvelope: Equatable, Hashable {
|
|
2408
|
+
public static func == (lhs: MessageEnvelope, rhs: MessageEnvelope) -> Bool {
|
|
2409
|
+
if lhs.v != rhs.v {
|
|
2410
|
+
return false
|
|
2411
|
+
}
|
|
2412
|
+
if lhs.conversationId != rhs.conversationId {
|
|
2413
|
+
return false
|
|
2414
|
+
}
|
|
2415
|
+
if lhs.epoch != rhs.epoch {
|
|
2416
|
+
return false
|
|
2417
|
+
}
|
|
2418
|
+
if lhs.kind != rhs.kind {
|
|
2419
|
+
return false
|
|
2420
|
+
}
|
|
2421
|
+
if lhs.senderDevice != rhs.senderDevice {
|
|
2422
|
+
return false
|
|
2423
|
+
}
|
|
2424
|
+
if lhs.seq != rhs.seq {
|
|
2425
|
+
return false
|
|
2426
|
+
}
|
|
2427
|
+
if lhs.hlc != rhs.hlc {
|
|
2428
|
+
return false
|
|
2429
|
+
}
|
|
2430
|
+
if lhs.payload != rhs.payload {
|
|
2431
|
+
return false
|
|
2432
|
+
}
|
|
2433
|
+
if lhs.contentHash != rhs.contentHash {
|
|
2434
|
+
return false
|
|
2435
|
+
}
|
|
2436
|
+
return true
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
public func hash(into hasher: inout Hasher) {
|
|
2440
|
+
hasher.combine(v)
|
|
2441
|
+
hasher.combine(conversationId)
|
|
2442
|
+
hasher.combine(epoch)
|
|
2443
|
+
hasher.combine(kind)
|
|
2444
|
+
hasher.combine(senderDevice)
|
|
2445
|
+
hasher.combine(seq)
|
|
2446
|
+
hasher.combine(hlc)
|
|
2447
|
+
hasher.combine(payload)
|
|
2448
|
+
hasher.combine(contentHash)
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
#if swift(>=5.8)
|
|
2453
|
+
@_documentation(visibility: private)
|
|
2454
|
+
#endif
|
|
2455
|
+
public struct FfiConverterTypeMessageEnvelope: FfiConverterRustBuffer {
|
|
2456
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MessageEnvelope {
|
|
2457
|
+
return
|
|
2458
|
+
try MessageEnvelope(
|
|
2459
|
+
v: FfiConverterUInt8.read(from: &buf),
|
|
2460
|
+
conversationId: FfiConverterTypeConversationId.read(from: &buf),
|
|
2461
|
+
epoch: FfiConverterUInt64.read(from: &buf),
|
|
2462
|
+
kind: FfiConverterTypeMessageKind.read(from: &buf),
|
|
2463
|
+
senderDevice: FfiConverterTypeDeviceId.read(from: &buf),
|
|
2464
|
+
seq: FfiConverterUInt64.read(from: &buf),
|
|
2465
|
+
hlc: FfiConverterTypeHlc.read(from: &buf),
|
|
2466
|
+
payload: FfiConverterData.read(from: &buf),
|
|
2467
|
+
contentHash: FfiConverterData.read(from: &buf)
|
|
2468
|
+
)
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
public static func write(_ value: MessageEnvelope, into buf: inout [UInt8]) {
|
|
2472
|
+
FfiConverterUInt8.write(value.v, into: &buf)
|
|
2473
|
+
FfiConverterTypeConversationId.write(value.conversationId, into: &buf)
|
|
2474
|
+
FfiConverterUInt64.write(value.epoch, into: &buf)
|
|
2475
|
+
FfiConverterTypeMessageKind.write(value.kind, into: &buf)
|
|
2476
|
+
FfiConverterTypeDeviceId.write(value.senderDevice, into: &buf)
|
|
2477
|
+
FfiConverterUInt64.write(value.seq, into: &buf)
|
|
2478
|
+
FfiConverterTypeHlc.write(value.hlc, into: &buf)
|
|
2479
|
+
FfiConverterData.write(value.payload, into: &buf)
|
|
2480
|
+
FfiConverterData.write(value.contentHash, into: &buf)
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
#if swift(>=5.8)
|
|
2485
|
+
@_documentation(visibility: private)
|
|
2486
|
+
#endif
|
|
2487
|
+
public func FfiConverterTypeMessageEnvelope_lift(_ buf: RustBuffer) throws -> MessageEnvelope {
|
|
2488
|
+
return try FfiConverterTypeMessageEnvelope.lift(buf)
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
#if swift(>=5.8)
|
|
2492
|
+
@_documentation(visibility: private)
|
|
2493
|
+
#endif
|
|
2494
|
+
public func FfiConverterTypeMessageEnvelope_lower(_ value: MessageEnvelope) -> RustBuffer {
|
|
2495
|
+
return FfiConverterTypeMessageEnvelope.lower(value)
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
public struct UserId {
|
|
2499
|
+
public var value: Data
|
|
2500
|
+
|
|
2501
|
+
/// Default memberwise initializers are never public by default, so we
|
|
2502
|
+
/// declare one manually.
|
|
2503
|
+
public init(value: Data) {
|
|
2504
|
+
self.value = value
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
extension UserId: Equatable, Hashable {
|
|
2509
|
+
public static func == (lhs: UserId, rhs: UserId) -> Bool {
|
|
2510
|
+
if lhs.value != rhs.value {
|
|
2511
|
+
return false
|
|
2512
|
+
}
|
|
2513
|
+
return true
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
public func hash(into hasher: inout Hasher) {
|
|
2517
|
+
hasher.combine(value)
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
#if swift(>=5.8)
|
|
2522
|
+
@_documentation(visibility: private)
|
|
2523
|
+
#endif
|
|
2524
|
+
public struct FfiConverterTypeUserId: FfiConverterRustBuffer {
|
|
2525
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UserId {
|
|
2526
|
+
return
|
|
2527
|
+
try UserId(
|
|
2528
|
+
value: FfiConverterData.read(from: &buf)
|
|
2529
|
+
)
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
public static func write(_ value: UserId, into buf: inout [UInt8]) {
|
|
2533
|
+
FfiConverterData.write(value.value, into: &buf)
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
#if swift(>=5.8)
|
|
2538
|
+
@_documentation(visibility: private)
|
|
2539
|
+
#endif
|
|
2540
|
+
public func FfiConverterTypeUserId_lift(_ buf: RustBuffer) throws -> UserId {
|
|
2541
|
+
return try FfiConverterTypeUserId.lift(buf)
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
#if swift(>=5.8)
|
|
2545
|
+
@_documentation(visibility: private)
|
|
2546
|
+
#endif
|
|
2547
|
+
public func FfiConverterTypeUserId_lower(_ value: UserId) -> RustBuffer {
|
|
2548
|
+
return FfiConverterTypeUserId.lower(value)
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
// Note that we don't yet support `indirect` for enums.
|
|
2552
|
+
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
|
|
2553
|
+
|
|
2554
|
+
public enum MessageKind {
|
|
2555
|
+
case application
|
|
2556
|
+
case commit
|
|
2557
|
+
case welcome
|
|
2558
|
+
case proposal
|
|
2559
|
+
case keyPackage
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2562
|
+
#if swift(>=5.8)
|
|
2563
|
+
@_documentation(visibility: private)
|
|
2564
|
+
#endif
|
|
2565
|
+
public struct FfiConverterTypeMessageKind: FfiConverterRustBuffer {
|
|
2566
|
+
typealias SwiftType = MessageKind
|
|
2567
|
+
|
|
2568
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MessageKind {
|
|
2569
|
+
let variant: Int32 = try readInt(&buf)
|
|
2570
|
+
switch variant {
|
|
2571
|
+
case 1: return .application
|
|
2572
|
+
|
|
2573
|
+
case 2: return .commit
|
|
2574
|
+
|
|
2575
|
+
case 3: return .welcome
|
|
2576
|
+
|
|
2577
|
+
case 4: return .proposal
|
|
2578
|
+
|
|
2579
|
+
case 5: return .keyPackage
|
|
2580
|
+
|
|
2581
|
+
default: throw UniffiInternalError.unexpectedEnumCase
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
public static func write(_ value: MessageKind, into buf: inout [UInt8]) {
|
|
2586
|
+
switch value {
|
|
2587
|
+
case .application:
|
|
2588
|
+
writeInt(&buf, Int32(1))
|
|
2589
|
+
|
|
2590
|
+
case .commit:
|
|
2591
|
+
writeInt(&buf, Int32(2))
|
|
2592
|
+
|
|
2593
|
+
case .welcome:
|
|
2594
|
+
writeInt(&buf, Int32(3))
|
|
2595
|
+
|
|
2596
|
+
case .proposal:
|
|
2597
|
+
writeInt(&buf, Int32(4))
|
|
2598
|
+
|
|
2599
|
+
case .keyPackage:
|
|
2600
|
+
writeInt(&buf, Int32(5))
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
#if swift(>=5.8)
|
|
2606
|
+
@_documentation(visibility: private)
|
|
2607
|
+
#endif
|
|
2608
|
+
public func FfiConverterTypeMessageKind_lift(_ buf: RustBuffer) throws -> MessageKind {
|
|
2609
|
+
return try FfiConverterTypeMessageKind.lift(buf)
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
#if swift(>=5.8)
|
|
2613
|
+
@_documentation(visibility: private)
|
|
2614
|
+
#endif
|
|
2615
|
+
public func FfiConverterTypeMessageKind_lower(_ value: MessageKind) -> RustBuffer {
|
|
2616
|
+
return FfiConverterTypeMessageKind.lower(value)
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
extension MessageKind: Equatable, Hashable {}
|
|
2620
|
+
|
|
2621
|
+
public enum PingError {
|
|
2622
|
+
case Storage(message: String)
|
|
2623
|
+
|
|
2624
|
+
case Transport(message: String)
|
|
2625
|
+
|
|
2626
|
+
case Mls(message: String)
|
|
2627
|
+
|
|
2628
|
+
case Identity(message: String)
|
|
2629
|
+
|
|
2630
|
+
case UnknownConversation(message: String)
|
|
2631
|
+
|
|
2632
|
+
case UnknownDevice(message: String)
|
|
2633
|
+
|
|
2634
|
+
case EpochOccupied(message: String)
|
|
2635
|
+
|
|
2636
|
+
case Codec(message: String)
|
|
2637
|
+
|
|
2638
|
+
case Invalid(message: String)
|
|
2639
|
+
|
|
2640
|
+
case NotInitialised(message: String)
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
#if swift(>=5.8)
|
|
2644
|
+
@_documentation(visibility: private)
|
|
2645
|
+
#endif
|
|
2646
|
+
public struct FfiConverterTypePingError: FfiConverterRustBuffer {
|
|
2647
|
+
typealias SwiftType = PingError
|
|
2648
|
+
|
|
2649
|
+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PingError {
|
|
2650
|
+
let variant: Int32 = try readInt(&buf)
|
|
2651
|
+
switch variant {
|
|
2652
|
+
case 1: return try .Storage(
|
|
2653
|
+
message: FfiConverterString.read(from: &buf)
|
|
2654
|
+
)
|
|
2655
|
+
|
|
2656
|
+
case 2: return try .Transport(
|
|
2657
|
+
message: FfiConverterString.read(from: &buf)
|
|
2658
|
+
)
|
|
2659
|
+
|
|
2660
|
+
case 3: return try .Mls(
|
|
2661
|
+
message: FfiConverterString.read(from: &buf)
|
|
2662
|
+
)
|
|
2663
|
+
|
|
2664
|
+
case 4: return try .Identity(
|
|
2665
|
+
message: FfiConverterString.read(from: &buf)
|
|
2666
|
+
)
|
|
2667
|
+
|
|
2668
|
+
case 5: return try .UnknownConversation(
|
|
2669
|
+
message: FfiConverterString.read(from: &buf)
|
|
2670
|
+
)
|
|
2671
|
+
|
|
2672
|
+
case 6: return try .UnknownDevice(
|
|
2673
|
+
message: FfiConverterString.read(from: &buf)
|
|
2674
|
+
)
|
|
2675
|
+
|
|
2676
|
+
case 7: return try .EpochOccupied(
|
|
2677
|
+
message: FfiConverterString.read(from: &buf)
|
|
2678
|
+
)
|
|
2679
|
+
|
|
2680
|
+
case 8: return try .Codec(
|
|
2681
|
+
message: FfiConverterString.read(from: &buf)
|
|
2682
|
+
)
|
|
2683
|
+
|
|
2684
|
+
case 9: return try .Invalid(
|
|
2685
|
+
message: FfiConverterString.read(from: &buf)
|
|
2686
|
+
)
|
|
2687
|
+
|
|
2688
|
+
case 10: return try .NotInitialised(
|
|
2689
|
+
message: FfiConverterString.read(from: &buf)
|
|
2690
|
+
)
|
|
2691
|
+
|
|
2692
|
+
default: throw UniffiInternalError.unexpectedEnumCase
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
public static func write(_ value: PingError, into buf: inout [UInt8]) {
|
|
2697
|
+
switch value {
|
|
2698
|
+
case .Storage(_ /* message is ignored*/ ):
|
|
2699
|
+
writeInt(&buf, Int32(1))
|
|
2700
|
+
case .Transport(_ /* message is ignored*/ ):
|
|
2701
|
+
writeInt(&buf, Int32(2))
|
|
2702
|
+
case .Mls(_ /* message is ignored*/ ):
|
|
2703
|
+
writeInt(&buf, Int32(3))
|
|
2704
|
+
case .Identity(_ /* message is ignored*/ ):
|
|
2705
|
+
writeInt(&buf, Int32(4))
|
|
2706
|
+
case .UnknownConversation(_ /* message is ignored*/ ):
|
|
2707
|
+
writeInt(&buf, Int32(5))
|
|
2708
|
+
case .UnknownDevice(_ /* message is ignored*/ ):
|
|
2709
|
+
writeInt(&buf, Int32(6))
|
|
2710
|
+
case .EpochOccupied(_ /* message is ignored*/ ):
|
|
2711
|
+
writeInt(&buf, Int32(7))
|
|
2712
|
+
case .Codec(_ /* message is ignored*/ ):
|
|
2713
|
+
writeInt(&buf, Int32(8))
|
|
2714
|
+
case .Invalid(_ /* message is ignored*/ ):
|
|
2715
|
+
writeInt(&buf, Int32(9))
|
|
2716
|
+
case .NotInitialised(_ /* message is ignored*/ ):
|
|
2717
|
+
writeInt(&buf, Int32(10))
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2722
|
+
extension PingError: Equatable, Hashable {}
|
|
2723
|
+
|
|
2724
|
+
extension PingError: Foundation.LocalizedError {
|
|
2725
|
+
public var errorDescription: String? {
|
|
2726
|
+
String(reflecting: self)
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
#if swift(>=5.8)
|
|
2731
|
+
@_documentation(visibility: private)
|
|
2732
|
+
#endif
|
|
2733
|
+
private struct FfiConverterOptionString: FfiConverterRustBuffer {
|
|
2734
|
+
typealias SwiftType = String?
|
|
2735
|
+
|
|
2736
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
2737
|
+
guard let value = value else {
|
|
2738
|
+
writeInt(&buf, Int8(0))
|
|
2739
|
+
return
|
|
2740
|
+
}
|
|
2741
|
+
writeInt(&buf, Int8(1))
|
|
2742
|
+
FfiConverterString.write(value, into: &buf)
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
2746
|
+
switch try readInt(&buf) as Int8 {
|
|
2747
|
+
case 0: return nil
|
|
2748
|
+
case 1: return try FfiConverterString.read(from: &buf)
|
|
2749
|
+
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
#if swift(>=5.8)
|
|
2755
|
+
@_documentation(visibility: private)
|
|
2756
|
+
#endif
|
|
2757
|
+
private struct FfiConverterOptionData: FfiConverterRustBuffer {
|
|
2758
|
+
typealias SwiftType = Data?
|
|
2759
|
+
|
|
2760
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
2761
|
+
guard let value = value else {
|
|
2762
|
+
writeInt(&buf, Int8(0))
|
|
2763
|
+
return
|
|
2764
|
+
}
|
|
2765
|
+
writeInt(&buf, Int8(1))
|
|
2766
|
+
FfiConverterData.write(value, into: &buf)
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
2770
|
+
switch try readInt(&buf) as Int8 {
|
|
2771
|
+
case 0: return nil
|
|
2772
|
+
case 1: return try FfiConverterData.read(from: &buf)
|
|
2773
|
+
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
#if swift(>=5.8)
|
|
2779
|
+
@_documentation(visibility: private)
|
|
2780
|
+
#endif
|
|
2781
|
+
private struct FfiConverterOptionTypeIncomingMessage: FfiConverterRustBuffer {
|
|
2782
|
+
typealias SwiftType = IncomingMessage?
|
|
2783
|
+
|
|
2784
|
+
static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
|
2785
|
+
guard let value = value else {
|
|
2786
|
+
writeInt(&buf, Int8(0))
|
|
2787
|
+
return
|
|
2788
|
+
}
|
|
2789
|
+
writeInt(&buf, Int8(1))
|
|
2790
|
+
FfiConverterTypeIncomingMessage.write(value, into: &buf)
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
|
2794
|
+
switch try readInt(&buf) as Int8 {
|
|
2795
|
+
case 0: return nil
|
|
2796
|
+
case 1: return try FfiConverterTypeIncomingMessage.read(from: &buf)
|
|
2797
|
+
default: throw UniffiInternalError.unexpectedOptionalTag
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
#if swift(>=5.8)
|
|
2803
|
+
@_documentation(visibility: private)
|
|
2804
|
+
#endif
|
|
2805
|
+
private struct FfiConverterSequenceUInt32: FfiConverterRustBuffer {
|
|
2806
|
+
typealias SwiftType = [UInt32]
|
|
2807
|
+
|
|
2808
|
+
static func write(_ value: [UInt32], into buf: inout [UInt8]) {
|
|
2809
|
+
let len = Int32(value.count)
|
|
2810
|
+
writeInt(&buf, len)
|
|
2811
|
+
for item in value {
|
|
2812
|
+
FfiConverterUInt32.write(item, into: &buf)
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [UInt32] {
|
|
2817
|
+
let len: Int32 = try readInt(&buf)
|
|
2818
|
+
var seq = [UInt32]()
|
|
2819
|
+
seq.reserveCapacity(Int(len))
|
|
2820
|
+
for _ in 0 ..< len {
|
|
2821
|
+
try seq.append(FfiConverterUInt32.read(from: &buf))
|
|
2822
|
+
}
|
|
2823
|
+
return seq
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
#if swift(>=5.8)
|
|
2828
|
+
@_documentation(visibility: private)
|
|
2829
|
+
#endif
|
|
2830
|
+
private struct FfiConverterSequenceString: FfiConverterRustBuffer {
|
|
2831
|
+
typealias SwiftType = [String]
|
|
2832
|
+
|
|
2833
|
+
static func write(_ value: [String], into buf: inout [UInt8]) {
|
|
2834
|
+
let len = Int32(value.count)
|
|
2835
|
+
writeInt(&buf, len)
|
|
2836
|
+
for item in value {
|
|
2837
|
+
FfiConverterString.write(item, into: &buf)
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] {
|
|
2842
|
+
let len: Int32 = try readInt(&buf)
|
|
2843
|
+
var seq = [String]()
|
|
2844
|
+
seq.reserveCapacity(Int(len))
|
|
2845
|
+
for _ in 0 ..< len {
|
|
2846
|
+
try seq.append(FfiConverterString.read(from: &buf))
|
|
2847
|
+
}
|
|
2848
|
+
return seq
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
|
|
2852
|
+
#if swift(>=5.8)
|
|
2853
|
+
@_documentation(visibility: private)
|
|
2854
|
+
#endif
|
|
2855
|
+
private struct FfiConverterSequenceData: FfiConverterRustBuffer {
|
|
2856
|
+
typealias SwiftType = [Data]
|
|
2857
|
+
|
|
2858
|
+
static func write(_ value: [Data], into buf: inout [UInt8]) {
|
|
2859
|
+
let len = Int32(value.count)
|
|
2860
|
+
writeInt(&buf, len)
|
|
2861
|
+
for item in value {
|
|
2862
|
+
FfiConverterData.write(item, into: &buf)
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Data] {
|
|
2867
|
+
let len: Int32 = try readInt(&buf)
|
|
2868
|
+
var seq = [Data]()
|
|
2869
|
+
seq.reserveCapacity(Int(len))
|
|
2870
|
+
for _ in 0 ..< len {
|
|
2871
|
+
try seq.append(FfiConverterData.read(from: &buf))
|
|
2872
|
+
}
|
|
2873
|
+
return seq
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
#if swift(>=5.8)
|
|
2878
|
+
@_documentation(visibility: private)
|
|
2879
|
+
#endif
|
|
2880
|
+
private struct FfiConverterSequenceTypeConversationMeta: FfiConverterRustBuffer {
|
|
2881
|
+
typealias SwiftType = [ConversationMeta]
|
|
2882
|
+
|
|
2883
|
+
static func write(_ value: [ConversationMeta], into buf: inout [UInt8]) {
|
|
2884
|
+
let len = Int32(value.count)
|
|
2885
|
+
writeInt(&buf, len)
|
|
2886
|
+
for item in value {
|
|
2887
|
+
FfiConverterTypeConversationMeta.write(item, into: &buf)
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [ConversationMeta] {
|
|
2892
|
+
let len: Int32 = try readInt(&buf)
|
|
2893
|
+
var seq = [ConversationMeta]()
|
|
2894
|
+
seq.reserveCapacity(Int(len))
|
|
2895
|
+
for _ in 0 ..< len {
|
|
2896
|
+
try seq.append(FfiConverterTypeConversationMeta.read(from: &buf))
|
|
2897
|
+
}
|
|
2898
|
+
return seq
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
#if swift(>=5.8)
|
|
2903
|
+
@_documentation(visibility: private)
|
|
2904
|
+
#endif
|
|
2905
|
+
private struct FfiConverterSequenceTypeDeviceInfo: FfiConverterRustBuffer {
|
|
2906
|
+
typealias SwiftType = [DeviceInfo]
|
|
2907
|
+
|
|
2908
|
+
static func write(_ value: [DeviceInfo], into buf: inout [UInt8]) {
|
|
2909
|
+
let len = Int32(value.count)
|
|
2910
|
+
writeInt(&buf, len)
|
|
2911
|
+
for item in value {
|
|
2912
|
+
FfiConverterTypeDeviceInfo.write(item, into: &buf)
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [DeviceInfo] {
|
|
2917
|
+
let len: Int32 = try readInt(&buf)
|
|
2918
|
+
var seq = [DeviceInfo]()
|
|
2919
|
+
seq.reserveCapacity(Int(len))
|
|
2920
|
+
for _ in 0 ..< len {
|
|
2921
|
+
try seq.append(FfiConverterTypeDeviceInfo.read(from: &buf))
|
|
2922
|
+
}
|
|
2923
|
+
return seq
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
#if swift(>=5.8)
|
|
2928
|
+
@_documentation(visibility: private)
|
|
2929
|
+
#endif
|
|
2930
|
+
private struct FfiConverterSequenceTypeDiscoveredDevice: FfiConverterRustBuffer {
|
|
2931
|
+
typealias SwiftType = [DiscoveredDevice]
|
|
2932
|
+
|
|
2933
|
+
static func write(_ value: [DiscoveredDevice], into buf: inout [UInt8]) {
|
|
2934
|
+
let len = Int32(value.count)
|
|
2935
|
+
writeInt(&buf, len)
|
|
2936
|
+
for item in value {
|
|
2937
|
+
FfiConverterTypeDiscoveredDevice.write(item, into: &buf)
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2941
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [DiscoveredDevice] {
|
|
2942
|
+
let len: Int32 = try readInt(&buf)
|
|
2943
|
+
var seq = [DiscoveredDevice]()
|
|
2944
|
+
seq.reserveCapacity(Int(len))
|
|
2945
|
+
for _ in 0 ..< len {
|
|
2946
|
+
try seq.append(FfiConverterTypeDiscoveredDevice.read(from: &buf))
|
|
2947
|
+
}
|
|
2948
|
+
return seq
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
|
|
2952
|
+
#if swift(>=5.8)
|
|
2953
|
+
@_documentation(visibility: private)
|
|
2954
|
+
#endif
|
|
2955
|
+
private struct FfiConverterSequenceTypeIncomingMessage: FfiConverterRustBuffer {
|
|
2956
|
+
typealias SwiftType = [IncomingMessage]
|
|
2957
|
+
|
|
2958
|
+
static func write(_ value: [IncomingMessage], into buf: inout [UInt8]) {
|
|
2959
|
+
let len = Int32(value.count)
|
|
2960
|
+
writeInt(&buf, len)
|
|
2961
|
+
for item in value {
|
|
2962
|
+
FfiConverterTypeIncomingMessage.write(item, into: &buf)
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [IncomingMessage] {
|
|
2967
|
+
let len: Int32 = try readInt(&buf)
|
|
2968
|
+
var seq = [IncomingMessage]()
|
|
2969
|
+
seq.reserveCapacity(Int(len))
|
|
2970
|
+
for _ in 0 ..< len {
|
|
2971
|
+
try seq.append(FfiConverterTypeIncomingMessage.read(from: &buf))
|
|
2972
|
+
}
|
|
2973
|
+
return seq
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2977
|
+
#if swift(>=5.8)
|
|
2978
|
+
@_documentation(visibility: private)
|
|
2979
|
+
#endif
|
|
2980
|
+
private struct FfiConverterSequenceTypeMessageEnvelope: FfiConverterRustBuffer {
|
|
2981
|
+
typealias SwiftType = [MessageEnvelope]
|
|
2982
|
+
|
|
2983
|
+
static func write(_ value: [MessageEnvelope], into buf: inout [UInt8]) {
|
|
2984
|
+
let len = Int32(value.count)
|
|
2985
|
+
writeInt(&buf, len)
|
|
2986
|
+
for item in value {
|
|
2987
|
+
FfiConverterTypeMessageEnvelope.write(item, into: &buf)
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MessageEnvelope] {
|
|
2992
|
+
let len: Int32 = try readInt(&buf)
|
|
2993
|
+
var seq = [MessageEnvelope]()
|
|
2994
|
+
seq.reserveCapacity(Int(len))
|
|
2995
|
+
for _ in 0 ..< len {
|
|
2996
|
+
try seq.append(FfiConverterTypeMessageEnvelope.read(from: &buf))
|
|
2997
|
+
}
|
|
2998
|
+
return seq
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0
|
|
3003
|
+
private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1
|
|
3004
|
+
|
|
3005
|
+
private let uniffiContinuationHandleMap = UniffiHandleMap<UnsafeContinuation<Int8, Never>>()
|
|
3006
|
+
|
|
3007
|
+
private func uniffiRustCallAsync<F, T>(
|
|
3008
|
+
rustFutureFunc: () -> UInt64,
|
|
3009
|
+
pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> Void,
|
|
3010
|
+
completeFunc: (UInt64, UnsafeMutablePointer<RustCallStatus>) -> F,
|
|
3011
|
+
freeFunc: (UInt64) -> Void,
|
|
3012
|
+
liftFunc: (F) throws -> T,
|
|
3013
|
+
errorHandler: ((RustBuffer) throws -> Swift.Error)?
|
|
3014
|
+
) async throws -> T {
|
|
3015
|
+
// Make sure to call uniffiEnsureInitialized() since future creation doesn't have a
|
|
3016
|
+
// RustCallStatus param, so doesn't use makeRustCall()
|
|
3017
|
+
uniffiEnsureInitialized()
|
|
3018
|
+
let rustFuture = rustFutureFunc()
|
|
3019
|
+
defer {
|
|
3020
|
+
freeFunc(rustFuture)
|
|
3021
|
+
}
|
|
3022
|
+
var pollResult: Int8
|
|
3023
|
+
repeat {
|
|
3024
|
+
pollResult = await withUnsafeContinuation {
|
|
3025
|
+
pollFunc(
|
|
3026
|
+
rustFuture,
|
|
3027
|
+
uniffiFutureContinuationCallback,
|
|
3028
|
+
uniffiContinuationHandleMap.insert(obj: $0)
|
|
3029
|
+
)
|
|
3030
|
+
}
|
|
3031
|
+
} while pollResult != UNIFFI_RUST_FUTURE_POLL_READY
|
|
3032
|
+
|
|
3033
|
+
return try liftFunc(makeRustCall(
|
|
3034
|
+
{ completeFunc(rustFuture, $0) },
|
|
3035
|
+
errorHandler: errorHandler
|
|
3036
|
+
))
|
|
3037
|
+
}
|
|
3038
|
+
|
|
3039
|
+
/// Callback handlers for an async calls. These are invoked by Rust when the future is ready. They
|
|
3040
|
+
/// lift the return value or error and resume the suspended function.
|
|
3041
|
+
private func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) {
|
|
3042
|
+
if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) {
|
|
3043
|
+
continuation.resume(returning: pollResult)
|
|
3044
|
+
} else {
|
|
3045
|
+
print("uniffiFutureContinuationCallback invalid handle")
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
private func uniffiTraitInterfaceCallAsync<T>(
|
|
3050
|
+
makeCall: @escaping () async throws -> T,
|
|
3051
|
+
handleSuccess: @escaping (T) -> Void,
|
|
3052
|
+
handleError: @escaping (Int8, RustBuffer) -> Void
|
|
3053
|
+
) -> UniffiForeignFuture {
|
|
3054
|
+
let task = Task {
|
|
3055
|
+
do {
|
|
3056
|
+
try handleSuccess(await makeCall())
|
|
3057
|
+
} catch {
|
|
3058
|
+
handleError(CALL_UNEXPECTED_ERROR, FfiConverterString.lower(String(describing: error)))
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
let handle = UNIFFI_FOREIGN_FUTURE_HANDLE_MAP.insert(obj: task)
|
|
3062
|
+
return UniffiForeignFuture(handle: handle, free: uniffiForeignFutureFree)
|
|
3063
|
+
}
|
|
3064
|
+
|
|
3065
|
+
private func uniffiTraitInterfaceCallAsyncWithError<T, E>(
|
|
3066
|
+
makeCall: @escaping () async throws -> T,
|
|
3067
|
+
handleSuccess: @escaping (T) -> Void,
|
|
3068
|
+
handleError: @escaping (Int8, RustBuffer) -> Void,
|
|
3069
|
+
lowerError: @escaping (E) -> RustBuffer
|
|
3070
|
+
) -> UniffiForeignFuture {
|
|
3071
|
+
let task = Task {
|
|
3072
|
+
do {
|
|
3073
|
+
try handleSuccess(await makeCall())
|
|
3074
|
+
} catch let error as E {
|
|
3075
|
+
handleError(CALL_ERROR, lowerError(error))
|
|
3076
|
+
} catch {
|
|
3077
|
+
handleError(CALL_UNEXPECTED_ERROR, FfiConverterString.lower(String(describing: error)))
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
let handle = UNIFFI_FOREIGN_FUTURE_HANDLE_MAP.insert(obj: task)
|
|
3081
|
+
return UniffiForeignFuture(handle: handle, free: uniffiForeignFutureFree)
|
|
3082
|
+
}
|
|
3083
|
+
|
|
3084
|
+
// Borrow the callback handle map implementation to store foreign future handles
|
|
3085
|
+
// TODO: consolidate the handle-map code (https://github.com/mozilla/uniffi-rs/pull/1823)
|
|
3086
|
+
private var UNIFFI_FOREIGN_FUTURE_HANDLE_MAP = UniffiHandleMap<UniffiForeignFutureTask>()
|
|
3087
|
+
|
|
3088
|
+
/// Protocol for tasks that handle foreign futures.
|
|
3089
|
+
///
|
|
3090
|
+
/// Defining a protocol allows all tasks to be stored in the same handle map. This can't be done
|
|
3091
|
+
/// with the task object itself, since has generic parameters.
|
|
3092
|
+
protocol UniffiForeignFutureTask {
|
|
3093
|
+
func cancel()
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
extension Task: UniffiForeignFutureTask {}
|
|
3097
|
+
|
|
3098
|
+
private func uniffiForeignFutureFree(handle: UInt64) {
|
|
3099
|
+
do {
|
|
3100
|
+
let task = try UNIFFI_FOREIGN_FUTURE_HANDLE_MAP.remove(handle: handle)
|
|
3101
|
+
// Set the cancellation flag on the task. If it's still running, the code can check the
|
|
3102
|
+
// cancellation flag or call `Task.checkCancellation()`. If the task has completed, this is
|
|
3103
|
+
// a no-op.
|
|
3104
|
+
task.cancel()
|
|
3105
|
+
} catch {
|
|
3106
|
+
print("uniffiForeignFutureFree: handle missing from handlemap")
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
|
|
3110
|
+
/// For testing
|
|
3111
|
+
public func uniffiForeignFutureHandleCountPing() -> Int {
|
|
3112
|
+
UNIFFI_FOREIGN_FUTURE_HANDLE_MAP.count
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
public func generateIdentityExport() -> Data {
|
|
3116
|
+
return try! FfiConverterData.lift(try! rustCall {
|
|
3117
|
+
uniffi_ping_ffi_fn_func_generate_identity_export($0)
|
|
3118
|
+
})
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
private enum InitializationResult {
|
|
3122
|
+
case ok
|
|
3123
|
+
case contractVersionMismatch
|
|
3124
|
+
case apiChecksumMismatch
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
/// Use a global variable to perform the versioning checks. Swift ensures that
|
|
3128
|
+
/// the code inside is only computed once.
|
|
3129
|
+
private var initializationResult: InitializationResult = {
|
|
3130
|
+
// Get the bindings contract version from our ComponentInterface
|
|
3131
|
+
let bindings_contract_version = 26
|
|
3132
|
+
// Get the scaffolding contract version by calling the into the dylib
|
|
3133
|
+
let scaffolding_contract_version = ffi_ping_ffi_uniffi_contract_version()
|
|
3134
|
+
if bindings_contract_version != scaffolding_contract_version {
|
|
3135
|
+
return InitializationResult.contractVersionMismatch
|
|
3136
|
+
}
|
|
3137
|
+
if uniffi_ping_ffi_checksum_func_generate_identity_export() != 15026 {
|
|
3138
|
+
return InitializationResult.apiChecksumMismatch
|
|
3139
|
+
}
|
|
3140
|
+
if uniffi_ping_ffi_checksum_method_messageobserver_on_application_message() != 7190 {
|
|
3141
|
+
return InitializationResult.apiChecksumMismatch
|
|
3142
|
+
}
|
|
3143
|
+
if uniffi_ping_ffi_checksum_method_messageobserver_on_conversation_updated() != 50154 {
|
|
3144
|
+
return InitializationResult.apiChecksumMismatch
|
|
3145
|
+
}
|
|
3146
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_add_members() != 59894 {
|
|
3147
|
+
return InitializationResult.apiChecksumMismatch
|
|
3148
|
+
}
|
|
3149
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_build_linking_ticket() != 54304 {
|
|
3150
|
+
return InitializationResult.apiChecksumMismatch
|
|
3151
|
+
}
|
|
3152
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_consume_linking_ticket() != 11953 {
|
|
3153
|
+
return InitializationResult.apiChecksumMismatch
|
|
3154
|
+
}
|
|
3155
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_create_conversation() != 49429 {
|
|
3156
|
+
return InitializationResult.apiChecksumMismatch
|
|
3157
|
+
}
|
|
3158
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_device_id() != 45433 {
|
|
3159
|
+
return InitializationResult.apiChecksumMismatch
|
|
3160
|
+
}
|
|
3161
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_device_info() != 51623 {
|
|
3162
|
+
return InitializationResult.apiChecksumMismatch
|
|
3163
|
+
}
|
|
3164
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_fresh_key_package() != 54233 {
|
|
3165
|
+
return InitializationResult.apiChecksumMismatch
|
|
3166
|
+
}
|
|
3167
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_join_conversation() != 48291 {
|
|
3168
|
+
return InitializationResult.apiChecksumMismatch
|
|
3169
|
+
}
|
|
3170
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_list_conversations() != 15788 {
|
|
3171
|
+
return InitializationResult.apiChecksumMismatch
|
|
3172
|
+
}
|
|
3173
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_list_devices() != 10141 {
|
|
3174
|
+
return InitializationResult.apiChecksumMismatch
|
|
3175
|
+
}
|
|
3176
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_process_envelope() != 11247 {
|
|
3177
|
+
return InitializationResult.apiChecksumMismatch
|
|
3178
|
+
}
|
|
3179
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_remove_members() != 62054 {
|
|
3180
|
+
return InitializationResult.apiChecksumMismatch
|
|
3181
|
+
}
|
|
3182
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_revoke_device() != 63664 {
|
|
3183
|
+
return InitializationResult.apiChecksumMismatch
|
|
3184
|
+
}
|
|
3185
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_send() != 11574 {
|
|
3186
|
+
return InitializationResult.apiChecksumMismatch
|
|
3187
|
+
}
|
|
3188
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_set_observer() != 43381 {
|
|
3189
|
+
return InitializationResult.apiChecksumMismatch
|
|
3190
|
+
}
|
|
3191
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_sync_conversations() != 21737 {
|
|
3192
|
+
return InitializationResult.apiChecksumMismatch
|
|
3193
|
+
}
|
|
3194
|
+
if uniffi_ping_ffi_checksum_method_messagingclient_user_id() != 53867 {
|
|
3195
|
+
return InitializationResult.apiChecksumMismatch
|
|
3196
|
+
}
|
|
3197
|
+
if uniffi_ping_ffi_checksum_method_storage_delete() != 26596 {
|
|
3198
|
+
return InitializationResult.apiChecksumMismatch
|
|
3199
|
+
}
|
|
3200
|
+
if uniffi_ping_ffi_checksum_method_storage_get() != 24556 {
|
|
3201
|
+
return InitializationResult.apiChecksumMismatch
|
|
3202
|
+
}
|
|
3203
|
+
if uniffi_ping_ffi_checksum_method_storage_list_keys() != 3905 {
|
|
3204
|
+
return InitializationResult.apiChecksumMismatch
|
|
3205
|
+
}
|
|
3206
|
+
if uniffi_ping_ffi_checksum_method_storage_put() != 24542 {
|
|
3207
|
+
return InitializationResult.apiChecksumMismatch
|
|
3208
|
+
}
|
|
3209
|
+
if uniffi_ping_ffi_checksum_method_transport_discover_devices() != 6136 {
|
|
3210
|
+
return InitializationResult.apiChecksumMismatch
|
|
3211
|
+
}
|
|
3212
|
+
if uniffi_ping_ffi_checksum_method_transport_fetch_since() != 1677 {
|
|
3213
|
+
return InitializationResult.apiChecksumMismatch
|
|
3214
|
+
}
|
|
3215
|
+
if uniffi_ping_ffi_checksum_method_transport_send() != 46493 {
|
|
3216
|
+
return InitializationResult.apiChecksumMismatch
|
|
3217
|
+
}
|
|
3218
|
+
if uniffi_ping_ffi_checksum_constructor_messagingclient_init() != 38981 {
|
|
3219
|
+
return InitializationResult.apiChecksumMismatch
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
uniffiCallbackInitMessageObserver()
|
|
3223
|
+
uniffiCallbackInitStorage()
|
|
3224
|
+
uniffiCallbackInitTransport()
|
|
3225
|
+
return InitializationResult.ok
|
|
3226
|
+
}()
|
|
3227
|
+
|
|
3228
|
+
private func uniffiEnsureInitialized() {
|
|
3229
|
+
switch initializationResult {
|
|
3230
|
+
case .ok:
|
|
3231
|
+
break
|
|
3232
|
+
case .contractVersionMismatch:
|
|
3233
|
+
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
|
|
3234
|
+
case .apiChecksumMismatch:
|
|
3235
|
+
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3239
|
+
// swiftlint:enable all
|