From 23b2aaf2e050fb0bbd5598afa5826720baceeafb Mon Sep 17 00:00:00 2001 From: William Yang Date: Wed, 15 Apr 2026 10:20:51 +0200 Subject: [PATCH 1/5] feat(ffi): add Swift support --- .github/workflows/ci.yml | 26 + .gitignore | 9 + scripts/build_swift_bindings.sh | 111 + swift/Examples/QuicClientExample/main.swift | 216 ++ swift/Examples/TcpClientExample/main.swift | 200 ++ swift/Package.swift | 52 + swift/README.md | 46 + swift/Sources/FlowSDK/flowsdk_ffi.swift | 2537 +++++++++++++++++++ swift/Sources/flowsdk_ffi/flowsdk_ffi.h | 1042 ++++++++ 9 files changed, 4239 insertions(+) create mode 100755 scripts/build_swift_bindings.sh create mode 100644 swift/Examples/QuicClientExample/main.swift create mode 100644 swift/Examples/TcpClientExample/main.swift create mode 100644 swift/Package.swift create mode 100644 swift/README.md create mode 100644 swift/Sources/FlowSDK/flowsdk_ffi.swift create mode 100644 swift/Sources/flowsdk_ffi/flowsdk_ffi.h diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f69ca4a7..dd4fac72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -198,6 +198,30 @@ jobs: ./gradlew :examples:simple_client:build ./gradlew :examples:quic_client:build + swift-bindings: + name: Swift Bindings + runs-on: macos-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 + + - name: Cache Cargo dependencies + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-swift-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-swift- + + - name: Build Rust, Generate Swift Bindings, and Verify swift build + run: ./scripts/build_swift_bindings.sh --test + coverage: name: Code Coverage runs-on: ubuntu-latest @@ -286,6 +310,8 @@ jobs: os: ubuntu-latest - target: x86_64-apple-darwin os: macos-latest + - target: aarch64-apple-darwin + os: macos-latest - target: x86_64-pc-windows-msvc os: windows-latest diff --git a/.gitignore b/.gitignore index 07eff542..fc1e4478 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,14 @@ Cargo.lock *.profraw *.profdata +# Swift: runtime library copies and XCFramework build artifacts (populated by build_swift_bindings.sh) +swift/.build/ +swift/.swiftpm/ +swift/lib/ +swift/Generated/ +swift/xcframework-intermediates/ +swift/FlowSDK.xcframework/ + # FFI generated code python/package/flowsdk/flowsdk_ffi.py @@ -22,6 +30,7 @@ python/examples/*.so python/examples/*.dll python/**/*.pyc +python/package/flowsdk.egg-info/ # Kotlin Examples (generated files) kotlin/package/src/main/resources/libflowsdk_ffi.dylib diff --git a/scripts/build_swift_bindings.sh b/scripts/build_swift_bindings.sh new file mode 100755 index 00000000..f8695ce2 --- /dev/null +++ b/scripts/build_swift_bindings.sh @@ -0,0 +1,111 @@ +#!/bin/bash +set -e + +# Default to debug build +PROFILE="debug" +CARGO_PROFILE="dev" +TARGET_DIR="target/debug" + +if [[ "$1" == "--release" ]]; then + PROFILE="release" + CARGO_PROFILE="release" + TARGET_DIR="target/release" + shift +fi + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$REPO_ROOT" + +# Temporary generation dir; final files are distributed below +SWIFT_GEN_DIR="swift/Generated" +# SPM target paths (must stay in sync with Package.swift) +SWIFT_C_TARGET="swift/Sources/flowsdk_ffi" +SWIFT_TARGET="swift/Sources/FlowSDK" +SWIFT_LIB_DIR="swift/lib" + +echo "Building flowsdk_ffi ($PROFILE)..." +cargo build -p flowsdk_ffi --profile "$CARGO_PROFILE" --features quic + +echo "Generating Swift bindings..." +mkdir -p "$SWIFT_GEN_DIR" +cargo run -p flowsdk_ffi --features=uniffi/cli,quic --bin uniffi-bindgen generate \ + --library "$TARGET_DIR/libflowsdk_ffi.dylib" \ + --language swift \ + --out-dir "$SWIFT_GEN_DIR" + +echo "Distributing generated files to SPM target directories..." +# C module target: only the header (SPM auto-generates the module map) +mkdir -p "$SWIFT_C_TARGET" +cp "$SWIFT_GEN_DIR/flowsdk_ffiFFI.h" "$SWIFT_C_TARGET/flowsdk_ffi.h" +# Swift target: the generated Swift bindings +mkdir -p "$SWIFT_TARGET" +cp "$SWIFT_GEN_DIR/flowsdk_ffi.swift" "$SWIFT_TARGET/" +# Normalize the SPM module name so consumers import `flowsdk_ffi` instead of `flowsdk_ffiFFI`. +perl -0pi -e 's/canImport\(flowsdk_ffiFFI\)/canImport(flowsdk_ffi)/g; s/import flowsdk_ffiFFI/import flowsdk_ffi/g' "$SWIFT_TARGET/flowsdk_ffi.swift" +# Clean up temp dir +rm -rf "$SWIFT_GEN_DIR" + +echo "Copying library for Swift package..." +mkdir -p "$SWIFT_LIB_DIR" +cp "$TARGET_DIR/libflowsdk_ffi.dylib" "$SWIFT_LIB_DIR/" + +if [[ "$1" == "--xcframework" ]]; then + echo "Building multi-arch XCFramework..." + + # Ensure required targets are installed + rustup target add aarch64-apple-darwin x86_64-apple-darwin aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios 2>/dev/null || true + + # Build macOS slices + echo " Building aarch64-apple-darwin..." + cargo build -p flowsdk_ffi --profile "$CARGO_PROFILE" --features quic --target aarch64-apple-darwin + echo " Building x86_64-apple-darwin..." + cargo build -p flowsdk_ffi --profile "$CARGO_PROFILE" --features quic --target x86_64-apple-darwin + + # Build iOS device + echo " Building aarch64-apple-ios..." + cargo build -p flowsdk_ffi --profile "$CARGO_PROFILE" --features quic --target aarch64-apple-ios + + # Build iOS simulator (universal: arm64 sim + x86_64 sim) + echo " Building aarch64-apple-ios-sim..." + cargo build -p flowsdk_ffi --profile "$CARGO_PROFILE" --features quic --target aarch64-apple-ios-sim + echo " Building x86_64-apple-ios (simulator)..." + cargo build -p flowsdk_ffi --profile "$CARGO_PROFILE" --features quic --target x86_64-apple-ios + + MACOS_ARM="target/aarch64-apple-darwin/$PROFILE/libflowsdk_ffi.a" + MACOS_X86="target/x86_64-apple-darwin/$PROFILE/libflowsdk_ffi.a" + IOS_ARM="target/aarch64-apple-ios/$PROFILE/libflowsdk_ffi.a" + IOS_SIM_ARM="target/aarch64-apple-ios-sim/$PROFILE/libflowsdk_ffi.a" + IOS_SIM_X86="target/x86_64-apple-ios/$PROFILE/libflowsdk_ffi.a" + + mkdir -p swift/xcframework-intermediates + + # Universal macOS .a + echo " Lipo-ing macOS slices..." + lipo -create "$MACOS_ARM" "$MACOS_X86" \ + -output swift/xcframework-intermediates/libflowsdk_ffi-macos.a + + # Universal iOS simulator .a + echo " Lipo-ing iOS simulator slices..." + lipo -create "$IOS_SIM_ARM" "$IOS_SIM_X86" \ + -output swift/xcframework-intermediates/libflowsdk_ffi-ios-sim.a + + echo " Creating XCFramework..." + rm -rf swift/FlowSDK.xcframework + xcodebuild -create-xcframework \ + -library swift/xcframework-intermediates/libflowsdk_ffi-macos.a \ + -headers "$SWIFT_C_TARGET" \ + -library "$IOS_ARM" \ + -headers "$SWIFT_C_TARGET" \ + -library swift/xcframework-intermediates/libflowsdk_ffi-ios-sim.a \ + -headers "$SWIFT_C_TARGET" \ + -output swift/FlowSDK.xcframework + + echo " XCFramework created at swift/FlowSDK.xcframework" +fi + +if [[ "$1" == "--test" ]]; then + echo "Running Swift build verification..." + LIBRARY_PATH="$PWD/$SWIFT_LIB_DIR" swift build --package-path swift +fi + +echo "Done!" diff --git a/swift/Examples/QuicClientExample/main.swift b/swift/Examples/QuicClientExample/main.swift new file mode 100644 index 00000000..311bf936 --- /dev/null +++ b/swift/Examples/QuicClientExample/main.swift @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: MPL-2.0 +// FlowSDK QUIC MQTT client example (macOS / Linux) +// +// Usage: +// LIBRARY_PATH=swift/lib swift run QuicClientExample [host] [port] +// +// For Wireshark key logging: +// SSLKEYLOGFILE=~/tmp/sslkeylog.txt LIBRARY_PATH=swift/lib swift run QuicClientExample +// +// Default broker: broker.emqx.io:14567 + +import Foundation +import FlowSDK + +#if canImport(Darwin) +import Darwin +#elseif canImport(Glibc) +import Glibc +#endif + +// MARK: - Configuration + +private let brokerHost = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "broker.emqx.io" +private let brokerPort = CommandLine.arguments.count > 2 ? Int(CommandLine.arguments[2])! : 14567 +private let runDurationMs: UInt64 = 10_000 +private let tickIntervalMs: UInt64 = 10 +private let recvBufSize = 65536 + +// MARK: - POSIX UDP helpers + +private func resolveHostAddr(_ host: String, port: Int) -> sockaddr_in { + var hints = addrinfo() + hints.ai_family = AF_INET + hints.ai_socktype = SOCK_DGRAM + var res: UnsafeMutablePointer? + guard getaddrinfo(host, String(port), &hints, &res) == 0, let ai = res else { + fatalError("getaddrinfo failed for \(host):\(port)") + } + defer { freeaddrinfo(res) } + var addr = sockaddr_in() + withUnsafeMutableBytes(of: &addr) { + $0.copyMemory(from: UnsafeRawBufferPointer(start: ai.pointee.ai_addr, + count: Int(ai.pointee.ai_addrlen))) + } + return addr +} + +private func makeNonBlockingUdpSocket() -> Int32 { + let fd = socket(AF_INET, SOCK_DGRAM, 0) + guard fd >= 0 else { fatalError("socket() failed") } + let flags = fcntl(fd, F_GETFL) + _ = fcntl(fd, F_SETFL, flags | O_NONBLOCK) + return fd +} + +private func sendDatagram(_ fd: Int32, data: Data, to addr: inout sockaddr_in) { + guard !data.isEmpty else { return } + data.withUnsafeBytes { ptr in + withUnsafeBytes(of: &addr) { addrPtr in + _ = sendto(fd, ptr.baseAddress!, data.count, 0, + addrPtr.baseAddress!.assumingMemoryBound(to: sockaddr.self), + socklen_t(MemoryLayout.size)) + } + } +} + +private func recvDatagram(_ fd: Int32, buf: inout [UInt8]) -> Data? { + var src = sockaddr_in() + var srcLen = socklen_t(MemoryLayout.size) + let n = withUnsafeMutableBytes(of: &src) { srcPtr in + recvfrom(fd, &buf, buf.count, 0, + srcPtr.baseAddress!.assumingMemoryBound(to: sockaddr.self), + &srcLen) + } + guard n > 0 else { return nil } + return Data(buf[0.. Bool { + var pfd = pollfd(fd: fd, events: Int16(POLLIN), revents: 0) + return poll(&pfd, 1, Int32(timeoutMs)) > 0 +} + +// MARK: - Engine helpers + +func nowMs(since startMs: UInt64) -> UInt64 { + return UInt64(Date().timeIntervalSince1970 * 1000) - startMs +} + +/// Addr string expected by the FFI engine: "1.2.3.4:14567" +func addrString(addr: sockaddr_in, port: Int) -> String { + var a = addr.sin_addr + var buf = [CChar](repeating: 0, count: Int(INET_ADDRSTRLEN)) + inet_ntop(AF_INET, &a, &buf, socklen_t(INET_ADDRSTRLEN)) + return "\(String(cString: buf)):\(port)" +} + +func sendOutgoing(_ engine: QuicMqttEngineFfi, fd: Int32, to addr: inout sockaddr_in) { + for dgram in engine.takeOutgoingDatagrams() { + sendDatagram(fd, data: dgram.data, to: &addr) + } +} + +// MARK: - Entry point + +print("Initializing FlowSDK QUIC Swift Example...") + +let opts = MqttOptionsFfi( + clientId: "swift_quic_\(Int(Date().timeIntervalSince1970) % 100_000)", + mqttVersion: 5, + cleanStart: true, + keepAlive: 30, // Must match QUIC idle timeout (30 s) + username: nil, + password: nil, + reconnectBaseDelayMs: 1_000, + reconnectMaxDelayMs: 10_000, + maxReconnectAttempts: 3 +) + +let engine = QuicMqttEngineFfi(opts: opts) +print("QUIC Engine created.") + +// Enable TLS key logging when SSLKEYLOGFILE is set (for Wireshark) +let enableKeyLog = ProcessInfo.processInfo.environment["SSLKEYLOGFILE"] != nil +let tlsOpts = MqttTlsOptionsFfi( + caCertFile: nil, + clientCertFile: nil, + clientKeyFile: nil, + insecureSkipVerify: true, // Demo broker only — do not use in production + alpnProtocols: [], + enableKeyLog: enableKeyLog +) + +// Open non-blocking UDP socket and resolve broker +var brokerAddr = resolveHostAddr(brokerHost, port: brokerPort) +let fd = makeNonBlockingUdpSocket() +let serverAddrStr = addrString(addr: brokerAddr, port: brokerPort) + +// Track relative time from engine creation (required by tick API) +let engineStartMs = UInt64(Date().timeIntervalSince1970 * 1000) + +print("Connecting to QUIC broker at \(serverAddrStr) (host: \(brokerHost))...") +engine.connect(serverAddr: serverAddrStr, serverName: brokerHost, + tlsOpts: tlsOpts, nowMs: nowMs(since: engineStartMs)) +// Tick immediately to generate initial QUIC handshake packets +_ = engine.handleTick(nowMs: nowMs(since: engineStartMs)) +sendOutgoing(engine, fd: fd, to: &brokerAddr) + +// Main event loop +var recvBuf = [UInt8](repeating: 0, count: recvBufSize) +var subscribed = false +var published = false + +while nowMs(since: engineStartMs) < runDurationMs { + // Drain all received datagrams + if waitReadable(fd, timeoutMs: Int(tickIntervalMs)) { + while let data = recvDatagram(fd, buf: &recvBuf) { + engine.handleDatagram(data: data, remoteAddr: serverAddrStr, + nowMs: nowMs(since: engineStartMs)) + } + } + + // Tick the engine (drives QUIC timers + MQTT keepalive) + let events = engine.handleTick(nowMs: nowMs(since: engineStartMs)) + + for event in events { + switch event { + case .connected(let r): + print("Connected! sessionPresent=\(r.sessionPresent)") + if !subscribed { + let pid = engine.subscribe(topicFilter: "test/swift/quic", qos: 1) + print("Subscribed to 'test/swift/quic' (PID \(pid))") + subscribed = true + sendOutgoing(engine, fd: fd, to: &brokerAddr) + } + case .subscribed(let r): + print("Subscribe ack PID \(r.packetId)") + if !published { + let payload = Data("Hello from Swift QUIC!".utf8) + let pid = engine.publish(topic: "test/swift/quic", payload: payload, qos: 1) + print("Published to 'test/swift/quic' (PID \(pid))") + published = true + // Tick immediately so QUIC frames are generated before the next sendOutgoing + _ = engine.handleTick(nowMs: nowMs(since: engineStartMs)) + sendOutgoing(engine, fd: fd, to: &brokerAddr) + } + case .messageReceived(let m): + let msg = String(data: m.payload, encoding: .utf8) ?? "" + print("✅ Message on '\(m.topic)': \(msg)") + case .published(let r): + print("✅ Publish ack PID \(r.packetId.map(String.init) ?? "none")") + case .disconnected(let reasonCode): + print("⚠️ Disconnected. reasonCode=\(String(describing: reasonCode))") + case .error(let message): + print("❌ Error: \(message)") + case .reconnectNeeded: + print("ℹ Reconnect needed") + case .reconnectScheduled(let attempt, let delayMs): + print("ℹ Reconnect attempt \(attempt) in \(delayMs)ms") + case .pingResponse(let success): + print("ℹ Ping response: success=\(success)") + case .unsubscribed(_): + break + } + } + + // Forward engine-generated outgoing datagrams + sendOutgoing(engine, fd: fd, to: &brokerAddr) +} + +// Graceful disconnect +print("Run time elapsed, disconnecting...") +engine.disconnect() +sendOutgoing(engine, fd: fd, to: &brokerAddr) +Darwin.close(fd) +print("Done.") diff --git a/swift/Examples/TcpClientExample/main.swift b/swift/Examples/TcpClientExample/main.swift new file mode 100644 index 00000000..7b790c9a --- /dev/null +++ b/swift/Examples/TcpClientExample/main.swift @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: MPL-2.0 +// FlowSDK TCP MQTT client example (macOS / Linux) +// +// Usage: +// LIBRARY_PATH=swift/lib swift run TcpClientExample [host] [port] +// +// Default broker: broker.emqx.io:1883 + +import Foundation +import FlowSDK + +#if canImport(Darwin) +import Darwin +#elseif canImport(Glibc) +import Glibc +#endif + +// MARK: - Configuration + +private let brokerHost = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "broker.emqx.io" +private let brokerPort = CommandLine.arguments.count > 2 ? Int(CommandLine.arguments[2])! : 1883 +private let runDurationMs: UInt64 = 15_000 +private let tickIntervalMs: UInt64 = 10 +private let recvBufSize = 65536 + +// MARK: - POSIX TCP helpers + +private func makeNonBlockingTcpSocket(host: String, port: Int) -> Int32 { + var hints = addrinfo() + hints.ai_family = AF_UNSPEC + hints.ai_socktype = SOCK_STREAM + var res: UnsafeMutablePointer? + guard getaddrinfo(host, String(port), &hints, &res) == 0, let ai = res else { + fatalError("getaddrinfo failed for \(host):\(port)") + } + defer { freeaddrinfo(res) } + + let fd = socket(ai.pointee.ai_family, ai.pointee.ai_socktype, ai.pointee.ai_protocol) + guard fd >= 0 else { fatalError("socket() failed") } + + // Non-blocking + let flags = fcntl(fd, F_GETFL) + _ = fcntl(fd, F_SETFL, flags | O_NONBLOCK) + + let rc = Darwin.connect(fd, ai.pointee.ai_addr, ai.pointee.ai_addrlen) + if rc < 0 && errno != EINPROGRESS { + fatalError("connect() failed: \(String(cString: strerror(errno)))") + } + return fd +} + +private func waitWritable(_ fd: Int32, timeoutMs: Int) -> Bool { + var pfd = pollfd(fd: fd, events: Int16(POLLOUT), revents: 0) + return poll(&pfd, 1, Int32(timeoutMs)) > 0 +} + +private func waitReadable(_ fd: Int32, timeoutMs: Int) -> Bool { + var pfd = pollfd(fd: fd, events: Int16(POLLIN), revents: 0) + return poll(&pfd, 1, Int32(timeoutMs)) > 0 +} + +private func sendAll(_ fd: Int32, data: Data) { + guard !data.isEmpty else { return } + data.withUnsafeBytes { ptr in + var sent = 0 + while sent < data.count { + let n = send(fd, ptr.baseAddress!.advanced(by: sent), data.count - sent, 0) + if n <= 0 { return } + sent += n + } + } +} + +// MARK: - Entry point + +func nowMs(since startMs: UInt64) -> UInt64 { + return UInt64(Date().timeIntervalSince1970 * 1000) - startMs +} + +func handleEvent(_ event: MqttEventFfi, engine: MqttEngineFfi, fd: Int32, + subscribed: inout Bool, published: inout Bool, startMs: UInt64) { + switch event { + case .connected(let r): + print("Connected! sessionPresent=\(r.sessionPresent)") + if !subscribed { + let pid = engine.subscribe(topicFilter: "test/swift/tcp", qos: 1) + print("Subscribed to 'test/swift/tcp' (PID \(pid))") + subscribed = true + sendAll(fd, data: engine.takeOutgoing()) + } + case .subscribed(let r): + print("Subscribe ack PID \(r.packetId)") + if !published { + let payload = Data("Hello from Swift TCP!".utf8) + let pid = engine.publish(topic: "test/swift/tcp", payload: payload, qos: 1, priority: nil) + print("Published to 'test/swift/tcp' (PID \(pid))") + published = true + sendAll(fd, data: engine.takeOutgoing()) + } + case .messageReceived(let m): + let msg = String(data: m.payload, encoding: .utf8) ?? "" + print("✅ Message on '\(m.topic)': \(msg)") + case .published(let r): + print("✅ Publish ack PID \(r.packetId.map(String.init) ?? "none")") + case .disconnected(let reasonCode): + print("⚠️ Disconnected. reasonCode=\(String(describing: reasonCode))") + case .error(let message): + print("❌ Error: \(message)") + case .reconnectNeeded: + print("ℹ Reconnect needed") + case .reconnectScheduled(let attempt, let delayMs): + print("ℹ Reconnect attempt \(attempt) in \(delayMs)ms") + case .pingResponse(let success): + print("ℹ Ping response: success=\(success)") + case .unsubscribed(_): + break + } +} + +print("Initializing FlowSDK TCP Swift Example...") + +let opts = MqttOptionsFfi( + clientId: "swift_tcp_\(Int(Date().timeIntervalSince1970) % 100_000)", + mqttVersion: 5, + cleanStart: true, + keepAlive: 60, + username: nil, + password: nil, + reconnectBaseDelayMs: 1_000, + reconnectMaxDelayMs: 10_000, + maxReconnectAttempts: 3 +) + +let engine = MqttEngineFfi.newWithOpts(opts: opts) +print("Engine created.") + +// Track relative time from engine creation (required by tick API) +let engineStartMs = UInt64(Date().timeIntervalSince1970 * 1000) + +// Trigger MQTT CONNECT packet generation +engine.connect() + +// Open TCP socket +print("Connecting to TCP broker at \(brokerHost):\(brokerPort)...") +let fd = makeNonBlockingTcpSocket(host: brokerHost, port: brokerPort) + +// Complete async TCP connect +if !waitWritable(fd, timeoutMs: 5000) { + fatalError("TCP connect timed out") +} +var err: Int32 = 0 +var errLen = socklen_t(MemoryLayout.size) +getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errLen) +guard err == 0 else { fatalError("TCP connect error: \(err)") } +print("TCP connected.") + +// Flush initial CONNECT packet +sendAll(fd, data: engine.takeOutgoing()) + +// Main event loop +var recvBuf = [UInt8](repeating: 0, count: recvBufSize) +var subscribed = false +var published = false + +while nowMs(since: engineStartMs) < runDurationMs { + // Wait up to one tick interval for readable data + if waitReadable(fd, timeoutMs: Int(tickIntervalMs)) { + let n = recv(fd, &recvBuf, recvBufSize, 0) + if n > 0 { + let inData = Data(recvBuf[0.. RustBuffer { + RustBuffer(capacity: 0, len:0, data: nil) + } + + static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { + try! rustCall { ffi_flowsdk_ffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + } + + // Frees the buffer in place. + // The buffer must not be used after this is called. + func deallocate() { + try! rustCall { ffi_flowsdk_ffi_rustbuffer_free(self, $0) } + } +} + +fileprivate extension ForeignBytes { + init(bufferPointer: UnsafeBufferPointer) { + self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) + } +} + +// For every type used in the interface, we provide helper methods for conveniently +// lifting and lowering that type from C-compatible data, and for reading and writing +// values of that type in a buffer. + +// Helper classes/extensions that don't change. +// Someday, this will be in a library of its own. + +fileprivate extension Data { + init(rustBuffer: RustBuffer) { + self.init( + bytesNoCopy: rustBuffer.data!, + count: Int(rustBuffer.len), + deallocator: .none + ) + } +} + +// Define reader functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. +// +// With external types, one swift source file needs to be able to call the read +// method on another source file's FfiConverter, but then what visibility +// should Reader have? +// - If Reader is fileprivate, then this means the read() must also +// be fileprivate, which doesn't work with external types. +// - If Reader is internal/public, we'll get compile errors since both source +// files will try define the same type. +// +// Instead, the read() method and these helper functions input a tuple of data + +fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) { + (data: data, offset: 0) +} + +// Reads an integer at the current offset, in big-endian order, and advances +// the offset on success. Throws if reading the integer would move the +// offset past the end of the buffer. +fileprivate func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { + let range = reader.offset...size + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + if T.self == UInt8.self { + let value = reader.data[reader.offset] + reader.offset += 1 + return value as! T + } + var value: T = 0 + let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)}) + reader.offset = range.upperBound + return value.bigEndian +} + +// Reads an arbitrary number of bytes, to be used to read +// raw bytes, this is useful when lifting strings +fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array { + let range = reader.offset..<(reader.offset+count) + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + var value = [UInt8](repeating: 0, count: count) + value.withUnsafeMutableBufferPointer({ buffer in + reader.data.copyBytes(to: buffer, from: range) + }) + reader.offset = range.upperBound + return value +} + +// Reads a float at the current offset. +fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { + return Float(bitPattern: try readInt(&reader)) +} + +// Reads a float at the current offset. +fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { + return Double(bitPattern: try readInt(&reader)) +} + +// Indicates if the offset has reached the end of the buffer. +fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { + return reader.offset < reader.data.count +} + +// Define writer functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. See the above discussion on Readers for details. + +fileprivate func createWriter() -> [UInt8] { + return [] +} + +fileprivate func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { + writer.append(contentsOf: byteArr) +} + +// Writes an integer in big-endian order. +// +// Warning: make sure what you are trying to write +// is in the correct type! +fileprivate func writeInt(_ writer: inout [UInt8], _ value: T) { + var value = value.bigEndian + withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } +} + +fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) { + writeInt(&writer, value.bitPattern) +} + +fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) { + writeInt(&writer, value.bitPattern) +} + +// Protocol for types that transfer other types across the FFI. This is +// analogous to the Rust trait of the same name. +fileprivate protocol FfiConverter { + associatedtype FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType + static func write(_ value: SwiftType, into buf: inout [UInt8]) +} + +// Types conforming to `Primitive` pass themselves directly over the FFI. +fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { } + +extension FfiConverterPrimitive { +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public static func lift(_ value: FfiType) throws -> SwiftType { + return value + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public static func lower(_ value: SwiftType) -> FfiType { + return value + } +} + +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} + +extension FfiConverterRustBuffer { +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public static func lift(_ buf: RustBuffer) throws -> SwiftType { + var reader = createReader(data: Data(rustBuffer: buf)) + let value = try read(from: &reader) + if hasRemaining(reader) { + throw UniffiInternalError.incompleteData + } + buf.deallocate() + return value + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public static func lower(_ value: SwiftType) -> RustBuffer { + var writer = createWriter() + write(value, into: &writer) + return RustBuffer(bytes: writer) + } +} +// An error type for FFI errors. These errors occur at the UniFFI level, not +// the library level. +fileprivate enum UniffiInternalError: LocalizedError { + case bufferOverflow + case incompleteData + case unexpectedOptionalTag + case unexpectedEnumCase + case unexpectedNullPointer + case unexpectedRustCallStatusCode + case unexpectedRustCallError + case unexpectedStaleHandle + case rustPanic(_ message: String) + + public var errorDescription: String? { + switch self { + case .bufferOverflow: return "Reading the requested value would read past the end of the buffer" + case .incompleteData: return "The buffer still has data after lifting its containing value" + case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1" + case .unexpectedEnumCase: return "Raw enum value doesn't match any cases" + case .unexpectedNullPointer: return "Raw pointer value was null" + case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code" + case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified" + case .unexpectedStaleHandle: return "The object in the handle map has been dropped already" + case let .rustPanic(message): return message + } + } +} + +fileprivate extension NSLock { + func withLock(f: () throws -> T) rethrows -> T { + self.lock() + defer { self.unlock() } + return try f() + } +} + +fileprivate let CALL_SUCCESS: Int8 = 0 +fileprivate let CALL_ERROR: Int8 = 1 +fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2 +fileprivate let CALL_CANCELLED: Int8 = 3 + +fileprivate extension RustCallStatus { + init() { + self.init( + code: CALL_SUCCESS, + errorBuf: RustBuffer.init( + capacity: 0, + len: 0, + data: nil + ) + ) + } +} + +private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { + let neverThrow: ((RustBuffer) throws -> Never)? = nil + return try makeRustCall(callback, errorHandler: neverThrow) +} + +private func rustCallWithError( + _ errorHandler: @escaping (RustBuffer) throws -> E, + _ callback: (UnsafeMutablePointer) -> T) throws -> T { + try makeRustCall(callback, errorHandler: errorHandler) +} + +private func makeRustCall( + _ callback: (UnsafeMutablePointer) -> T, + errorHandler: ((RustBuffer) throws -> E)? +) throws -> T { + uniffiEnsureInitialized() + var callStatus = RustCallStatus.init() + let returnedVal = callback(&callStatus) + try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) + return returnedVal +} + +private func uniffiCheckCallStatus( + callStatus: RustCallStatus, + errorHandler: ((RustBuffer) throws -> E)? +) throws { + switch callStatus.code { + case CALL_SUCCESS: + return + + case CALL_ERROR: + if let errorHandler = errorHandler { + throw try errorHandler(callStatus.errorBuf) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.unexpectedRustCallError + } + + case CALL_UNEXPECTED_ERROR: + // When the rust code sees a panic, it tries to construct a RustBuffer + // with the message. But if that code panics, then it just sends back + // an empty buffer. + if callStatus.errorBuf.len > 0 { + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.rustPanic("Rust panic") + } + + case CALL_CANCELLED: + fatalError("Cancellation not supported yet") + + default: + throw UniffiInternalError.unexpectedRustCallStatusCode + } +} + +private func uniffiTraitInterfaceCall( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> () +) { + do { + try writeReturn(makeCall()) + } catch let error { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private func uniffiTraitInterfaceCallWithError( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> (), + lowerError: (E) -> RustBuffer +) { + do { + try writeReturn(makeCall()) + } catch let error as E { + callStatus.pointee.code = CALL_ERROR + callStatus.pointee.errorBuf = lowerError(error) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} +fileprivate class UniffiHandleMap { + private var map: [UInt64: T] = [:] + private let lock = NSLock() + private var currentHandle: UInt64 = 1 + + func insert(obj: T) -> UInt64 { + lock.withLock { + let handle = currentHandle + currentHandle += 1 + map[handle] = obj + return handle + } + } + + func get(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map[handle] else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + @discardableResult + func remove(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map.removeValue(forKey: handle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + var count: Int { + get { + map.count + } + } +} + + +// Public interface members begin here. + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterUInt8: FfiConverterPrimitive { + typealias FfiType = UInt8 + typealias SwiftType = UInt8 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: UInt8, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterUInt16: FfiConverterPrimitive { + typealias FfiType = UInt16 + typealias SwiftType = UInt16 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt16 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterUInt32: FfiConverterPrimitive { + typealias FfiType = UInt32 + typealias SwiftType = UInt32 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterInt32: FfiConverterPrimitive { + typealias FfiType = Int32 + typealias SwiftType = Int32 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int32 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: Int32, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { + typealias FfiType = UInt64 + typealias SwiftType = UInt64 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterInt64: FfiConverterPrimitive { + typealias FfiType = Int64 + typealias SwiftType = Int64 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int64 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: Int64, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterBool : FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool + + public static func lift(_ value: Int8) throws -> Bool { + return value != 0 + } + + public static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { + return try lift(readInt(&buf)) + } + + public static func write(_ value: Bool, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer + + public static func lift(_ value: RustBuffer) throws -> String { + defer { + value.deallocate() + } + if value.data == nil { + return String() + } + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) + return String(bytes: bytes, encoding: String.Encoding.utf8)! + } + + public static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in + // The swift string gives us int8_t, we want uint8_t. + ptr.withMemoryRebound(to: UInt8.self) { ptr in + // The swift string gives us a trailing null byte, we don't want it. + let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) + return RustBuffer.from(buf) + } + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { + let len: Int32 = try readInt(&buf) + return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! + } + + public static func write(_ value: String, into buf: inout [UInt8]) { + let len = Int32(value.utf8.count) + writeInt(&buf, len) + writeBytes(&buf, value.utf8) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterData: FfiConverterRustBuffer { + typealias SwiftType = Data + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data { + let len: Int32 = try readInt(&buf) + return Data(try readBytes(&buf, count: Int(len))) + } + + public static func write(_ value: Data, into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + writeBytes(&buf, value) + } +} + + + + +public protocol MqttEngineFfiProtocol : AnyObject { + + func auth(reasonCode: UInt8) + + func connect() + + func disconnect() + + func getVersion() -> UInt8 + + func handleConnectionLost() + + func handleIncoming(data: Data) -> [MqttEventFfi] + + func handleTick(nowMs: UInt64) -> [MqttEventFfi] + + func isConnected() -> Bool + + func nextTickMs() -> Int64 + + func publish(topic: String, payload: Data, qos: UInt8, priority: UInt8?) -> Int32 + + func pushEventFfi(event: MqttEventFfi) + + func subscribe(topicFilter: String, qos: UInt8) -> Int32 + + func takeEvents() -> [MqttEventFfi] + + func takeOutgoing() -> Data + + func unsubscribe(topicFilter: String) -> Int32 + +} + +open class MqttEngineFfi: + MqttEngineFfiProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // 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. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_flowsdk_ffi_fn_clone_mqttengineffi(self.pointer, $0) } + } +public convenience init(clientId: String?, mqttVersion: UInt8) { + let pointer = + try! rustCall() { + uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new( + FfiConverterOptionString.lower(clientId), + FfiConverterUInt8.lower(mqttVersion),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_flowsdk_ffi_fn_free_mqttengineffi(pointer, $0) } + } + + +public static func newWithOpts(opts: MqttOptionsFfi) -> MqttEngineFfi { + return try! FfiConverterTypeMqttEngineFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new_with_opts( + FfiConverterTypeMqttOptionsFFI.lower(opts),$0 + ) +}) +} + + + +open func auth(reasonCode: UInt8) {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_auth(self.uniffiClonePointer(), + FfiConverterUInt8.lower(reasonCode),$0 + ) +} +} + +open func connect() {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_connect(self.uniffiClonePointer(),$0 + ) +} +} + +open func disconnect() {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_disconnect(self.uniffiClonePointer(),$0 + ) +} +} + +open func getVersion() -> UInt8 { + return try! FfiConverterUInt8.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_get_version(self.uniffiClonePointer(),$0 + ) +}) +} + +open func handleConnectionLost() {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_connection_lost(self.uniffiClonePointer(),$0 + ) +} +} + +open func handleIncoming(data: Data) -> [MqttEventFfi] { + return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_incoming(self.uniffiClonePointer(), + FfiConverterData.lower(data),$0 + ) +}) +} + +open func handleTick(nowMs: UInt64) -> [MqttEventFfi] { + return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_tick(self.uniffiClonePointer(), + FfiConverterUInt64.lower(nowMs),$0 + ) +}) +} + +open func isConnected() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_is_connected(self.uniffiClonePointer(),$0 + ) +}) +} + +open func nextTickMs() -> Int64 { + return try! FfiConverterInt64.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_next_tick_ms(self.uniffiClonePointer(),$0 + ) +}) +} + +open func publish(topic: String, payload: Data, qos: UInt8, priority: UInt8?) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_publish(self.uniffiClonePointer(), + FfiConverterString.lower(topic), + FfiConverterData.lower(payload), + FfiConverterUInt8.lower(qos), + FfiConverterOptionUInt8.lower(priority),$0 + ) +}) +} + +open func pushEventFfi(event: MqttEventFfi) {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_push_event_ffi(self.uniffiClonePointer(), + FfiConverterTypeMqttEventFFI.lower(event),$0 + ) +} +} + +open func subscribe(topicFilter: String, qos: UInt8) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_subscribe(self.uniffiClonePointer(), + FfiConverterString.lower(topicFilter), + FfiConverterUInt8.lower(qos),$0 + ) +}) +} + +open func takeEvents() -> [MqttEventFfi] { + return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_events(self.uniffiClonePointer(),$0 + ) +}) +} + +open func takeOutgoing() -> Data { + return try! FfiConverterData.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_outgoing(self.uniffiClonePointer(),$0 + ) +}) +} + +open func unsubscribe(topicFilter: String) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqttengineffi_unsubscribe(self.uniffiClonePointer(), + FfiConverterString.lower(topicFilter),$0 + ) +}) +} + + +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeMqttEngineFFI: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = MqttEngineFfi + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MqttEngineFfi { + return MqttEngineFfi(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: MqttEngineFfi) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttEngineFfi { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: MqttEngineFfi, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttEngineFFI_lift(_ pointer: UnsafeMutableRawPointer) throws -> MqttEngineFfi { + return try FfiConverterTypeMqttEngineFFI.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttEngineFFI_lower(_ value: MqttEngineFfi) -> UnsafeMutableRawPointer { + return FfiConverterTypeMqttEngineFFI.lower(value) +} + + + + +public protocol MqttEventListFfiProtocol : AnyObject { + + func get(index: UInt32) -> MqttEventFfi? + + func isEmpty() -> Bool + + func len() -> UInt32 + +} + +open class MqttEventListFfi: + MqttEventListFfiProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // 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. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_flowsdk_ffi_fn_clone_mqtteventlistffi(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_flowsdk_ffi_fn_free_mqtteventlistffi(pointer, $0) } + } + + + + +open func get(index: UInt32) -> MqttEventFfi? { + return try! FfiConverterOptionTypeMqttEventFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_get(self.uniffiClonePointer(), + FfiConverterUInt32.lower(index),$0 + ) +}) +} + +open func isEmpty() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_is_empty(self.uniffiClonePointer(),$0 + ) +}) +} + +open func len() -> UInt32 { + return try! FfiConverterUInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_len(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeMqttEventListFFI: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = MqttEventListFfi + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MqttEventListFfi { + return MqttEventListFfi(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: MqttEventListFfi) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttEventListFfi { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: MqttEventListFfi, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttEventListFFI_lift(_ pointer: UnsafeMutableRawPointer) throws -> MqttEventListFfi { + return try FfiConverterTypeMqttEventListFFI.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttEventListFFI_lower(_ value: MqttEventListFfi) -> UnsafeMutableRawPointer { + return FfiConverterTypeMqttEventListFFI.lower(value) +} + + + + +public protocol QuicMqttEngineFfiProtocol : AnyObject { + + func connect(serverAddr: String, serverName: String, tlsOpts: MqttTlsOptionsFfi, nowMs: UInt64) + + func disconnect() + + func handleDatagram(data: Data, remoteAddr: String, nowMs: UInt64) + + func handleTick(nowMs: UInt64) -> [MqttEventFfi] + + func isConnected() -> Bool + + func publish(topic: String, payload: Data, qos: UInt8) -> Int32 + + func subscribe(topicFilter: String, qos: UInt8) -> Int32 + + func takeEvents() -> [MqttEventFfi] + + func takeOutgoingDatagrams() -> [MqttDatagramFfi] + + func unsubscribe(topicFilter: String) -> Int32 + +} + +open class QuicMqttEngineFfi: + QuicMqttEngineFfiProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // 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. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_flowsdk_ffi_fn_clone_quicmqttengineffi(self.pointer, $0) } + } +public convenience init(opts: MqttOptionsFfi) { + let pointer = + try! rustCall() { + uniffi_flowsdk_ffi_fn_constructor_quicmqttengineffi_new( + FfiConverterTypeMqttOptionsFFI.lower(opts),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_flowsdk_ffi_fn_free_quicmqttengineffi(pointer, $0) } + } + + + + +open func connect(serverAddr: String, serverName: String, tlsOpts: MqttTlsOptionsFfi, nowMs: UInt64) {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_connect(self.uniffiClonePointer(), + FfiConverterString.lower(serverAddr), + FfiConverterString.lower(serverName), + FfiConverterTypeMqttTlsOptionsFFI.lower(tlsOpts), + FfiConverterUInt64.lower(nowMs),$0 + ) +} +} + +open func disconnect() {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_disconnect(self.uniffiClonePointer(),$0 + ) +} +} + +open func handleDatagram(data: Data, remoteAddr: String, nowMs: UInt64) {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_datagram(self.uniffiClonePointer(), + FfiConverterData.lower(data), + FfiConverterString.lower(remoteAddr), + FfiConverterUInt64.lower(nowMs),$0 + ) +} +} + +open func handleTick(nowMs: UInt64) -> [MqttEventFfi] { + return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_tick(self.uniffiClonePointer(), + FfiConverterUInt64.lower(nowMs),$0 + ) +}) +} + +open func isConnected() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_is_connected(self.uniffiClonePointer(),$0 + ) +}) +} + +open func publish(topic: String, payload: Data, qos: UInt8) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_publish(self.uniffiClonePointer(), + FfiConverterString.lower(topic), + FfiConverterData.lower(payload), + FfiConverterUInt8.lower(qos),$0 + ) +}) +} + +open func subscribe(topicFilter: String, qos: UInt8) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_subscribe(self.uniffiClonePointer(), + FfiConverterString.lower(topicFilter), + FfiConverterUInt8.lower(qos),$0 + ) +}) +} + +open func takeEvents() -> [MqttEventFfi] { + return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_events(self.uniffiClonePointer(),$0 + ) +}) +} + +open func takeOutgoingDatagrams() -> [MqttDatagramFfi] { + return try! FfiConverterSequenceTypeMqttDatagramFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_outgoing_datagrams(self.uniffiClonePointer(),$0 + ) +}) +} + +open func unsubscribe(topicFilter: String) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_unsubscribe(self.uniffiClonePointer(), + FfiConverterString.lower(topicFilter),$0 + ) +}) +} + + +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeQuicMqttEngineFFI: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = QuicMqttEngineFfi + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> QuicMqttEngineFfi { + return QuicMqttEngineFfi(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: QuicMqttEngineFfi) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> QuicMqttEngineFfi { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: QuicMqttEngineFfi, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeQuicMqttEngineFFI_lift(_ pointer: UnsafeMutableRawPointer) throws -> QuicMqttEngineFfi { + return try FfiConverterTypeQuicMqttEngineFFI.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeQuicMqttEngineFFI_lower(_ value: QuicMqttEngineFfi) -> UnsafeMutableRawPointer { + return FfiConverterTypeQuicMqttEngineFFI.lower(value) +} + + + + +public protocol TlsMqttEngineFfiProtocol : AnyObject { + + func connect() + + func disconnect() + + func handleSocketData(data: Data) + + func handleTick(nowMs: UInt64) -> [MqttEventFfi] + + func isConnected() -> Bool + + func publish(topic: String, payload: Data, qos: UInt8) -> Int32 + + func subscribe(topicFilter: String, qos: UInt8) -> Int32 + + func takeEvents() -> [MqttEventFfi] + + func takeSocketData() -> Data + + func unsubscribe(topicFilter: String) -> Int32 + +} + +open class TlsMqttEngineFfi: + TlsMqttEngineFfiProtocol { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // 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. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_flowsdk_ffi_fn_clone_tlsmqttengineffi(self.pointer, $0) } + } +public convenience init(opts: MqttOptionsFfi, tlsOpts: MqttTlsOptionsFfi, serverName: String) { + let pointer = + try! rustCall() { + uniffi_flowsdk_ffi_fn_constructor_tlsmqttengineffi_new( + FfiConverterTypeMqttOptionsFFI.lower(opts), + FfiConverterTypeMqttTlsOptionsFFI.lower(tlsOpts), + FfiConverterString.lower(serverName),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_flowsdk_ffi_fn_free_tlsmqttengineffi(pointer, $0) } + } + + + + +open func connect() {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_connect(self.uniffiClonePointer(),$0 + ) +} +} + +open func disconnect() {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_disconnect(self.uniffiClonePointer(),$0 + ) +} +} + +open func handleSocketData(data: Data) {try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_socket_data(self.uniffiClonePointer(), + FfiConverterData.lower(data),$0 + ) +} +} + +open func handleTick(nowMs: UInt64) -> [MqttEventFfi] { + return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_tick(self.uniffiClonePointer(), + FfiConverterUInt64.lower(nowMs),$0 + ) +}) +} + +open func isConnected() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_is_connected(self.uniffiClonePointer(),$0 + ) +}) +} + +open func publish(topic: String, payload: Data, qos: UInt8) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_publish(self.uniffiClonePointer(), + FfiConverterString.lower(topic), + FfiConverterData.lower(payload), + FfiConverterUInt8.lower(qos),$0 + ) +}) +} + +open func subscribe(topicFilter: String, qos: UInt8) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_subscribe(self.uniffiClonePointer(), + FfiConverterString.lower(topicFilter), + FfiConverterUInt8.lower(qos),$0 + ) +}) +} + +open func takeEvents() -> [MqttEventFfi] { + return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_events(self.uniffiClonePointer(),$0 + ) +}) +} + +open func takeSocketData() -> Data { + return try! FfiConverterData.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_socket_data(self.uniffiClonePointer(),$0 + ) +}) +} + +open func unsubscribe(topicFilter: String) -> Int32 { + return try! FfiConverterInt32.lift(try! rustCall() { + uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_unsubscribe(self.uniffiClonePointer(), + FfiConverterString.lower(topicFilter),$0 + ) +}) +} + + +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeTlsMqttEngineFFI: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = TlsMqttEngineFfi + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> TlsMqttEngineFfi { + return TlsMqttEngineFfi(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: TlsMqttEngineFfi) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TlsMqttEngineFfi { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: TlsMqttEngineFfi, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeTlsMqttEngineFFI_lift(_ pointer: UnsafeMutableRawPointer) throws -> TlsMqttEngineFfi { + return try FfiConverterTypeTlsMqttEngineFFI.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeTlsMqttEngineFFI_lower(_ value: TlsMqttEngineFfi) -> UnsafeMutableRawPointer { + return FfiConverterTypeTlsMqttEngineFFI.lower(value) +} + + +public struct ConnectionResultFfi { + public var reasonCode: UInt8 + public var sessionPresent: Bool + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(reasonCode: UInt8, sessionPresent: Bool) { + self.reasonCode = reasonCode + self.sessionPresent = sessionPresent + } +} + + + +extension ConnectionResultFfi: Equatable, Hashable { + public static func ==(lhs: ConnectionResultFfi, rhs: ConnectionResultFfi) -> Bool { + if lhs.reasonCode != rhs.reasonCode { + return false + } + if lhs.sessionPresent != rhs.sessionPresent { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(reasonCode) + hasher.combine(sessionPresent) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeConnectionResultFFI: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ConnectionResultFfi { + return + try ConnectionResultFfi( + reasonCode: FfiConverterUInt8.read(from: &buf), + sessionPresent: FfiConverterBool.read(from: &buf) + ) + } + + public static func write(_ value: ConnectionResultFfi, into buf: inout [UInt8]) { + FfiConverterUInt8.write(value.reasonCode, into: &buf) + FfiConverterBool.write(value.sessionPresent, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeConnectionResultFFI_lift(_ buf: RustBuffer) throws -> ConnectionResultFfi { + return try FfiConverterTypeConnectionResultFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeConnectionResultFFI_lower(_ value: ConnectionResultFfi) -> RustBuffer { + return FfiConverterTypeConnectionResultFFI.lower(value) +} + + +public struct MqttDatagramFfi { + public var addr: String + public var data: Data + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(addr: String, data: Data) { + self.addr = addr + self.data = data + } +} + + + +extension MqttDatagramFfi: Equatable, Hashable { + public static func ==(lhs: MqttDatagramFfi, rhs: MqttDatagramFfi) -> Bool { + if lhs.addr != rhs.addr { + return false + } + if lhs.data != rhs.data { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(addr) + hasher.combine(data) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeMqttDatagramFFI: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttDatagramFfi { + return + try MqttDatagramFfi( + addr: FfiConverterString.read(from: &buf), + data: FfiConverterData.read(from: &buf) + ) + } + + public static func write(_ value: MqttDatagramFfi, into buf: inout [UInt8]) { + FfiConverterString.write(value.addr, into: &buf) + FfiConverterData.write(value.data, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttDatagramFFI_lift(_ buf: RustBuffer) throws -> MqttDatagramFfi { + return try FfiConverterTypeMqttDatagramFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttDatagramFFI_lower(_ value: MqttDatagramFfi) -> RustBuffer { + return FfiConverterTypeMqttDatagramFFI.lower(value) +} + + +public struct MqttMessageFfi { + public var topic: String + public var payload: Data + public var qos: UInt8 + public var retain: Bool + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(topic: String, payload: Data, qos: UInt8, retain: Bool) { + self.topic = topic + self.payload = payload + self.qos = qos + self.retain = retain + } +} + + + +extension MqttMessageFfi: Equatable, Hashable { + public static func ==(lhs: MqttMessageFfi, rhs: MqttMessageFfi) -> Bool { + if lhs.topic != rhs.topic { + return false + } + if lhs.payload != rhs.payload { + return false + } + if lhs.qos != rhs.qos { + return false + } + if lhs.retain != rhs.retain { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(topic) + hasher.combine(payload) + hasher.combine(qos) + hasher.combine(retain) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeMqttMessageFFI: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttMessageFfi { + return + try MqttMessageFfi( + topic: FfiConverterString.read(from: &buf), + payload: FfiConverterData.read(from: &buf), + qos: FfiConverterUInt8.read(from: &buf), + retain: FfiConverterBool.read(from: &buf) + ) + } + + public static func write(_ value: MqttMessageFfi, into buf: inout [UInt8]) { + FfiConverterString.write(value.topic, into: &buf) + FfiConverterData.write(value.payload, into: &buf) + FfiConverterUInt8.write(value.qos, into: &buf) + FfiConverterBool.write(value.retain, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttMessageFFI_lift(_ buf: RustBuffer) throws -> MqttMessageFfi { + return try FfiConverterTypeMqttMessageFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttMessageFFI_lower(_ value: MqttMessageFfi) -> RustBuffer { + return FfiConverterTypeMqttMessageFFI.lower(value) +} + + +public struct MqttOptionsFfi { + public var clientId: String + public var mqttVersion: UInt8 + public var cleanStart: Bool + public var keepAlive: UInt16 + public var username: String? + public var password: String? + public var reconnectBaseDelayMs: UInt64 + public var reconnectMaxDelayMs: UInt64 + public var maxReconnectAttempts: UInt32 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(clientId: String, mqttVersion: UInt8, cleanStart: Bool, keepAlive: UInt16, username: String?, password: String?, reconnectBaseDelayMs: UInt64, reconnectMaxDelayMs: UInt64, maxReconnectAttempts: UInt32) { + self.clientId = clientId + self.mqttVersion = mqttVersion + self.cleanStart = cleanStart + self.keepAlive = keepAlive + self.username = username + self.password = password + self.reconnectBaseDelayMs = reconnectBaseDelayMs + self.reconnectMaxDelayMs = reconnectMaxDelayMs + self.maxReconnectAttempts = maxReconnectAttempts + } +} + + + +extension MqttOptionsFfi: Equatable, Hashable { + public static func ==(lhs: MqttOptionsFfi, rhs: MqttOptionsFfi) -> Bool { + if lhs.clientId != rhs.clientId { + return false + } + if lhs.mqttVersion != rhs.mqttVersion { + return false + } + if lhs.cleanStart != rhs.cleanStart { + return false + } + if lhs.keepAlive != rhs.keepAlive { + return false + } + if lhs.username != rhs.username { + return false + } + if lhs.password != rhs.password { + return false + } + if lhs.reconnectBaseDelayMs != rhs.reconnectBaseDelayMs { + return false + } + if lhs.reconnectMaxDelayMs != rhs.reconnectMaxDelayMs { + return false + } + if lhs.maxReconnectAttempts != rhs.maxReconnectAttempts { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(clientId) + hasher.combine(mqttVersion) + hasher.combine(cleanStart) + hasher.combine(keepAlive) + hasher.combine(username) + hasher.combine(password) + hasher.combine(reconnectBaseDelayMs) + hasher.combine(reconnectMaxDelayMs) + hasher.combine(maxReconnectAttempts) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeMqttOptionsFFI: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttOptionsFfi { + return + try MqttOptionsFfi( + clientId: FfiConverterString.read(from: &buf), + mqttVersion: FfiConverterUInt8.read(from: &buf), + cleanStart: FfiConverterBool.read(from: &buf), + keepAlive: FfiConverterUInt16.read(from: &buf), + username: FfiConverterOptionString.read(from: &buf), + password: FfiConverterOptionString.read(from: &buf), + reconnectBaseDelayMs: FfiConverterUInt64.read(from: &buf), + reconnectMaxDelayMs: FfiConverterUInt64.read(from: &buf), + maxReconnectAttempts: FfiConverterUInt32.read(from: &buf) + ) + } + + public static func write(_ value: MqttOptionsFfi, into buf: inout [UInt8]) { + FfiConverterString.write(value.clientId, into: &buf) + FfiConverterUInt8.write(value.mqttVersion, into: &buf) + FfiConverterBool.write(value.cleanStart, into: &buf) + FfiConverterUInt16.write(value.keepAlive, into: &buf) + FfiConverterOptionString.write(value.username, into: &buf) + FfiConverterOptionString.write(value.password, into: &buf) + FfiConverterUInt64.write(value.reconnectBaseDelayMs, into: &buf) + FfiConverterUInt64.write(value.reconnectMaxDelayMs, into: &buf) + FfiConverterUInt32.write(value.maxReconnectAttempts, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttOptionsFFI_lift(_ buf: RustBuffer) throws -> MqttOptionsFfi { + return try FfiConverterTypeMqttOptionsFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttOptionsFFI_lower(_ value: MqttOptionsFfi) -> RustBuffer { + return FfiConverterTypeMqttOptionsFFI.lower(value) +} + + +public struct MqttTlsOptionsFfi { + public var caCertFile: String? + public var clientCertFile: String? + public var clientKeyFile: String? + public var insecureSkipVerify: Bool + public var alpnProtocols: [String] + public var enableKeyLog: Bool + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(caCertFile: String?, clientCertFile: String?, clientKeyFile: String?, insecureSkipVerify: Bool, alpnProtocols: [String], enableKeyLog: Bool) { + self.caCertFile = caCertFile + self.clientCertFile = clientCertFile + self.clientKeyFile = clientKeyFile + self.insecureSkipVerify = insecureSkipVerify + self.alpnProtocols = alpnProtocols + self.enableKeyLog = enableKeyLog + } +} + + + +extension MqttTlsOptionsFfi: Equatable, Hashable { + public static func ==(lhs: MqttTlsOptionsFfi, rhs: MqttTlsOptionsFfi) -> Bool { + if lhs.caCertFile != rhs.caCertFile { + return false + } + if lhs.clientCertFile != rhs.clientCertFile { + return false + } + if lhs.clientKeyFile != rhs.clientKeyFile { + return false + } + if lhs.insecureSkipVerify != rhs.insecureSkipVerify { + return false + } + if lhs.alpnProtocols != rhs.alpnProtocols { + return false + } + if lhs.enableKeyLog != rhs.enableKeyLog { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(caCertFile) + hasher.combine(clientCertFile) + hasher.combine(clientKeyFile) + hasher.combine(insecureSkipVerify) + hasher.combine(alpnProtocols) + hasher.combine(enableKeyLog) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeMqttTlsOptionsFFI: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttTlsOptionsFfi { + return + try MqttTlsOptionsFfi( + caCertFile: FfiConverterOptionString.read(from: &buf), + clientCertFile: FfiConverterOptionString.read(from: &buf), + clientKeyFile: FfiConverterOptionString.read(from: &buf), + insecureSkipVerify: FfiConverterBool.read(from: &buf), + alpnProtocols: FfiConverterSequenceString.read(from: &buf), + enableKeyLog: FfiConverterBool.read(from: &buf) + ) + } + + public static func write(_ value: MqttTlsOptionsFfi, into buf: inout [UInt8]) { + FfiConverterOptionString.write(value.caCertFile, into: &buf) + FfiConverterOptionString.write(value.clientCertFile, into: &buf) + FfiConverterOptionString.write(value.clientKeyFile, into: &buf) + FfiConverterBool.write(value.insecureSkipVerify, into: &buf) + FfiConverterSequenceString.write(value.alpnProtocols, into: &buf) + FfiConverterBool.write(value.enableKeyLog, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttTlsOptionsFFI_lift(_ buf: RustBuffer) throws -> MqttTlsOptionsFfi { + return try FfiConverterTypeMqttTlsOptionsFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttTlsOptionsFFI_lower(_ value: MqttTlsOptionsFfi) -> RustBuffer { + return FfiConverterTypeMqttTlsOptionsFFI.lower(value) +} + + +public struct PublishResultFfi { + public var packetId: UInt16? + public var reasonCode: UInt8? + public var qos: UInt8 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(packetId: UInt16?, reasonCode: UInt8?, qos: UInt8) { + self.packetId = packetId + self.reasonCode = reasonCode + self.qos = qos + } +} + + + +extension PublishResultFfi: Equatable, Hashable { + public static func ==(lhs: PublishResultFfi, rhs: PublishResultFfi) -> Bool { + if lhs.packetId != rhs.packetId { + return false + } + if lhs.reasonCode != rhs.reasonCode { + return false + } + if lhs.qos != rhs.qos { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(packetId) + hasher.combine(reasonCode) + hasher.combine(qos) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypePublishResultFFI: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PublishResultFfi { + return + try PublishResultFfi( + packetId: FfiConverterOptionUInt16.read(from: &buf), + reasonCode: FfiConverterOptionUInt8.read(from: &buf), + qos: FfiConverterUInt8.read(from: &buf) + ) + } + + public static func write(_ value: PublishResultFfi, into buf: inout [UInt8]) { + FfiConverterOptionUInt16.write(value.packetId, into: &buf) + FfiConverterOptionUInt8.write(value.reasonCode, into: &buf) + FfiConverterUInt8.write(value.qos, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePublishResultFFI_lift(_ buf: RustBuffer) throws -> PublishResultFfi { + return try FfiConverterTypePublishResultFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePublishResultFFI_lower(_ value: PublishResultFfi) -> RustBuffer { + return FfiConverterTypePublishResultFFI.lower(value) +} + + +public struct SubscribeResultFfi { + public var packetId: UInt16 + public var reasonCodes: Data + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(packetId: UInt16, reasonCodes: Data) { + self.packetId = packetId + self.reasonCodes = reasonCodes + } +} + + + +extension SubscribeResultFfi: Equatable, Hashable { + public static func ==(lhs: SubscribeResultFfi, rhs: SubscribeResultFfi) -> Bool { + if lhs.packetId != rhs.packetId { + return false + } + if lhs.reasonCodes != rhs.reasonCodes { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(packetId) + hasher.combine(reasonCodes) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeSubscribeResultFFI: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SubscribeResultFfi { + return + try SubscribeResultFfi( + packetId: FfiConverterUInt16.read(from: &buf), + reasonCodes: FfiConverterData.read(from: &buf) + ) + } + + public static func write(_ value: SubscribeResultFfi, into buf: inout [UInt8]) { + FfiConverterUInt16.write(value.packetId, into: &buf) + FfiConverterData.write(value.reasonCodes, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeSubscribeResultFFI_lift(_ buf: RustBuffer) throws -> SubscribeResultFfi { + return try FfiConverterTypeSubscribeResultFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeSubscribeResultFFI_lower(_ value: SubscribeResultFfi) -> RustBuffer { + return FfiConverterTypeSubscribeResultFFI.lower(value) +} + + +public struct UnsubscribeResultFfi { + public var packetId: UInt16 + public var reasonCodes: Data + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(packetId: UInt16, reasonCodes: Data) { + self.packetId = packetId + self.reasonCodes = reasonCodes + } +} + + + +extension UnsubscribeResultFfi: Equatable, Hashable { + public static func ==(lhs: UnsubscribeResultFfi, rhs: UnsubscribeResultFfi) -> Bool { + if lhs.packetId != rhs.packetId { + return false + } + if lhs.reasonCodes != rhs.reasonCodes { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(packetId) + hasher.combine(reasonCodes) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeUnsubscribeResultFFI: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UnsubscribeResultFfi { + return + try UnsubscribeResultFfi( + packetId: FfiConverterUInt16.read(from: &buf), + reasonCodes: FfiConverterData.read(from: &buf) + ) + } + + public static func write(_ value: UnsubscribeResultFfi, into buf: inout [UInt8]) { + FfiConverterUInt16.write(value.packetId, into: &buf) + FfiConverterData.write(value.reasonCodes, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeUnsubscribeResultFFI_lift(_ buf: RustBuffer) throws -> UnsubscribeResultFfi { + return try FfiConverterTypeUnsubscribeResultFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeUnsubscribeResultFFI_lower(_ value: UnsubscribeResultFfi) -> RustBuffer { + return FfiConverterTypeUnsubscribeResultFFI.lower(value) +} + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum MqttEventFfi { + + case connected(ConnectionResultFfi + ) + case disconnected(reasonCode: UInt8? + ) + case messageReceived(MqttMessageFfi + ) + case published(PublishResultFfi + ) + case subscribed(SubscribeResultFfi + ) + case unsubscribed(UnsubscribeResultFfi + ) + case pingResponse(success: Bool + ) + case error(message: String + ) + case reconnectNeeded + case reconnectScheduled(attempt: UInt32, delayMs: UInt64 + ) +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeMqttEventFFI: FfiConverterRustBuffer { + typealias SwiftType = MqttEventFfi + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttEventFfi { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .connected(try FfiConverterTypeConnectionResultFFI.read(from: &buf) + ) + + case 2: return .disconnected(reasonCode: try FfiConverterOptionUInt8.read(from: &buf) + ) + + case 3: return .messageReceived(try FfiConverterTypeMqttMessageFFI.read(from: &buf) + ) + + case 4: return .published(try FfiConverterTypePublishResultFFI.read(from: &buf) + ) + + case 5: return .subscribed(try FfiConverterTypeSubscribeResultFFI.read(from: &buf) + ) + + case 6: return .unsubscribed(try FfiConverterTypeUnsubscribeResultFFI.read(from: &buf) + ) + + case 7: return .pingResponse(success: try FfiConverterBool.read(from: &buf) + ) + + case 8: return .error(message: try FfiConverterString.read(from: &buf) + ) + + case 9: return .reconnectNeeded + + case 10: return .reconnectScheduled(attempt: try FfiConverterUInt32.read(from: &buf), delayMs: try FfiConverterUInt64.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: MqttEventFfi, into buf: inout [UInt8]) { + switch value { + + + case let .connected(v1): + writeInt(&buf, Int32(1)) + FfiConverterTypeConnectionResultFFI.write(v1, into: &buf) + + + case let .disconnected(reasonCode): + writeInt(&buf, Int32(2)) + FfiConverterOptionUInt8.write(reasonCode, into: &buf) + + + case let .messageReceived(v1): + writeInt(&buf, Int32(3)) + FfiConverterTypeMqttMessageFFI.write(v1, into: &buf) + + + case let .published(v1): + writeInt(&buf, Int32(4)) + FfiConverterTypePublishResultFFI.write(v1, into: &buf) + + + case let .subscribed(v1): + writeInt(&buf, Int32(5)) + FfiConverterTypeSubscribeResultFFI.write(v1, into: &buf) + + + case let .unsubscribed(v1): + writeInt(&buf, Int32(6)) + FfiConverterTypeUnsubscribeResultFFI.write(v1, into: &buf) + + + case let .pingResponse(success): + writeInt(&buf, Int32(7)) + FfiConverterBool.write(success, into: &buf) + + + case let .error(message): + writeInt(&buf, Int32(8)) + FfiConverterString.write(message, into: &buf) + + + case .reconnectNeeded: + writeInt(&buf, Int32(9)) + + + case let .reconnectScheduled(attempt,delayMs): + writeInt(&buf, Int32(10)) + FfiConverterUInt32.write(attempt, into: &buf) + FfiConverterUInt64.write(delayMs, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttEventFFI_lift(_ buf: RustBuffer) throws -> MqttEventFfi { + return try FfiConverterTypeMqttEventFFI.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMqttEventFFI_lower(_ value: MqttEventFfi) -> RustBuffer { + return FfiConverterTypeMqttEventFFI.lower(value) +} + + + +extension MqttEventFfi: Equatable, Hashable {} + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionUInt8: FfiConverterRustBuffer { + typealias SwiftType = UInt8? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterUInt8.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt8.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionUInt16: FfiConverterRustBuffer { + typealias SwiftType = UInt16? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterUInt16.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt16.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { + typealias SwiftType = String? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterString.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionTypeMqttEventFFI: FfiConverterRustBuffer { + typealias SwiftType = MqttEventFfi? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeMqttEventFFI.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeMqttEventFFI.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { + typealias SwiftType = [String] + + public static func write(_ value: [String], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterString.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] { + let len: Int32 = try readInt(&buf) + var seq = [String]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterString.read(from: &buf)) + } + return seq + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeMqttDatagramFFI: FfiConverterRustBuffer { + typealias SwiftType = [MqttDatagramFfi] + + public static func write(_ value: [MqttDatagramFfi], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeMqttDatagramFFI.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MqttDatagramFfi] { + let len: Int32 = try readInt(&buf) + var seq = [MqttDatagramFfi]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeMqttDatagramFFI.read(from: &buf)) + } + return seq + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeMqttEventFFI: FfiConverterRustBuffer { + typealias SwiftType = [MqttEventFfi] + + public static func write(_ value: [MqttEventFfi], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeMqttEventFFI.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MqttEventFfi] { + let len: Int32 = try readInt(&buf) + var seq = [MqttEventFfi]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeMqttEventFFI.read(from: &buf)) + } + return seq + } +} + +private enum InitializationResult { + case ok + case contractVersionMismatch + case apiChecksumMismatch +} +// Use a global variable to perform the versioning checks. Swift ensures that +// the code inside is only computed once. +private var initializationResult: InitializationResult = { + // Get the bindings contract version from our ComponentInterface + let bindings_contract_version = 26 + // Get the scaffolding contract version by calling the into the dylib + let scaffolding_contract_version = ffi_flowsdk_ffi_uniffi_contract_version() + if bindings_contract_version != scaffolding_contract_version { + return InitializationResult.contractVersionMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_auth() != 13274) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_connect() != 11843) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_disconnect() != 35275) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_get_version() != 19826) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_connection_lost() != 12358) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_incoming() != 55488) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_tick() != 40864) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_is_connected() != 33756) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_next_tick_ms() != 63992) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_publish() != 44572) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_push_event_ffi() != 16806) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_subscribe() != 31682) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_events() != 17921) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_outgoing() != 12337) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_unsubscribe() != 51097) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_get() != 5088) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_is_empty() != 43194) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_len() != 36035) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_connect() != 39570) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_disconnect() != 54076) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_datagram() != 34322) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_tick() != 39076) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_is_connected() != 53863) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_publish() != 17969) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_subscribe() != 16787) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_events() != 34914) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_outgoing_datagrams() != 32224) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_unsubscribe() != 48) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_connect() != 53946) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_disconnect() != 58642) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_socket_data() != 27993) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_tick() != 57570) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_is_connected() != 11670) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_publish() != 29858) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_subscribe() != 35959) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_events() != 41728) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_socket_data() != 6663) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_unsubscribe() != 21790) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new() != 63280) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new_with_opts() != 49926) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_constructor_quicmqttengineffi_new() != 4296) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_flowsdk_ffi_checksum_constructor_tlsmqttengineffi_new() != 55234) { + return InitializationResult.apiChecksumMismatch + } + + return InitializationResult.ok +}() + +private func uniffiEnsureInitialized() { + switch initializationResult { + case .ok: + break + case .contractVersionMismatch: + fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") + case .apiChecksumMismatch: + fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } +} + +// swiftlint:enable all \ No newline at end of file diff --git a/swift/Sources/flowsdk_ffi/flowsdk_ffi.h b/swift/Sources/flowsdk_ffi/flowsdk_ffi.h new file mode 100644 index 00000000..f93c6761 --- /dev/null +++ b/swift/Sources/flowsdk_ffi/flowsdk_ffi.h @@ -0,0 +1,1042 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +#pragma once + +#include +#include +#include + +// The following structs are used to implement the lowest level +// of the FFI, and thus useful to multiple uniffied crates. +// We ensure they are declared exactly once, with a header guard, UNIFFI_SHARED_H. +#ifdef UNIFFI_SHARED_H + // We also try to prevent mixing versions of shared uniffi header structs. + // If you add anything to the #else block, you must increment the version suffix in UNIFFI_SHARED_HEADER_V4 + #ifndef UNIFFI_SHARED_HEADER_V4 + #error Combining helper code from multiple versions of uniffi is not supported + #endif // ndef UNIFFI_SHARED_HEADER_V4 +#else +#define UNIFFI_SHARED_H +#define UNIFFI_SHARED_HEADER_V4 +// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ +// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ + +typedef struct RustBuffer +{ + uint64_t capacity; + uint64_t len; + uint8_t *_Nullable data; +} RustBuffer; + +typedef struct ForeignBytes +{ + int32_t len; + const uint8_t *_Nullable data; +} ForeignBytes; + +// Error definitions +typedef struct RustCallStatus { + int8_t code; + RustBuffer errorBuf; +} RustCallStatus; + +// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ +// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ +#endif // def UNIFFI_SHARED_H +#ifndef UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK +#define UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK +typedef void (*UniffiRustFutureContinuationCallback)(uint64_t, int8_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE +typedef void (*UniffiForeignFutureFree)(uint64_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE +#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE +typedef void (*UniffiCallbackInterfaceFree)(uint64_t + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE +#define UNIFFI_FFIDEF_FOREIGN_FUTURE +typedef struct UniffiForeignFuture { + uint64_t handle; + UniffiForeignFutureFree _Nonnull free; +} UniffiForeignFuture; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 +typedef struct UniffiForeignFutureStructU8 { + uint8_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU8; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 +typedef void (*UniffiForeignFutureCompleteU8)(uint64_t, UniffiForeignFutureStructU8 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 +typedef struct UniffiForeignFutureStructI8 { + int8_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI8; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 +typedef void (*UniffiForeignFutureCompleteI8)(uint64_t, UniffiForeignFutureStructI8 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 +typedef struct UniffiForeignFutureStructU16 { + uint16_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU16; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 +typedef void (*UniffiForeignFutureCompleteU16)(uint64_t, UniffiForeignFutureStructU16 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 +typedef struct UniffiForeignFutureStructI16 { + int16_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI16; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 +typedef void (*UniffiForeignFutureCompleteI16)(uint64_t, UniffiForeignFutureStructI16 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 +typedef struct UniffiForeignFutureStructU32 { + uint32_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 +typedef void (*UniffiForeignFutureCompleteU32)(uint64_t, UniffiForeignFutureStructU32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 +typedef struct UniffiForeignFutureStructI32 { + int32_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 +typedef void (*UniffiForeignFutureCompleteI32)(uint64_t, UniffiForeignFutureStructI32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 +typedef struct UniffiForeignFutureStructU64 { + uint64_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructU64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 +typedef void (*UniffiForeignFutureCompleteU64)(uint64_t, UniffiForeignFutureStructU64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 +typedef struct UniffiForeignFutureStructI64 { + int64_t returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructI64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 +typedef void (*UniffiForeignFutureCompleteI64)(uint64_t, UniffiForeignFutureStructI64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 +typedef struct UniffiForeignFutureStructF32 { + float returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructF32; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 +typedef void (*UniffiForeignFutureCompleteF32)(uint64_t, UniffiForeignFutureStructF32 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 +typedef struct UniffiForeignFutureStructF64 { + double returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructF64; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 +typedef void (*UniffiForeignFutureCompleteF64)(uint64_t, UniffiForeignFutureStructF64 + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER +typedef struct UniffiForeignFutureStructPointer { + void*_Nonnull returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructPointer; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER +typedef void (*UniffiForeignFutureCompletePointer)(uint64_t, UniffiForeignFutureStructPointer + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER +typedef struct UniffiForeignFutureStructRustBuffer { + RustBuffer returnValue; + RustCallStatus callStatus; +} UniffiForeignFutureStructRustBuffer; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER +typedef void (*UniffiForeignFutureCompleteRustBuffer)(uint64_t, UniffiForeignFutureStructRustBuffer + ); + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID +typedef struct UniffiForeignFutureStructVoid { + RustCallStatus callStatus; +} UniffiForeignFutureStructVoid; + +#endif +#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID +#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID +typedef void (*UniffiForeignFutureCompleteVoid)(uint64_t, UniffiForeignFutureStructVoid + ); + +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_MQTTENGINEFFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_MQTTENGINEFFI +void*_Nonnull uniffi_flowsdk_ffi_fn_clone_mqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_MQTTENGINEFFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_MQTTENGINEFFI +void uniffi_flowsdk_ffi_fn_free_mqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_MQTTENGINEFFI_NEW +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_MQTTENGINEFFI_NEW +void*_Nonnull uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new(RustBuffer client_id, uint8_t mqtt_version, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_MQTTENGINEFFI_NEW_WITH_OPTS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_MQTTENGINEFFI_NEW_WITH_OPTS +void*_Nonnull uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new_with_opts(RustBuffer opts, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_AUTH +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_AUTH +void uniffi_flowsdk_ffi_fn_method_mqttengineffi_auth(void*_Nonnull ptr, uint8_t reason_code, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_CONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_CONNECT +void uniffi_flowsdk_ffi_fn_method_mqttengineffi_connect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_DISCONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_DISCONNECT +void uniffi_flowsdk_ffi_fn_method_mqttengineffi_disconnect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_GET_VERSION +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_GET_VERSION +uint8_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_get_version(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_CONNECTION_LOST +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_CONNECTION_LOST +void uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_connection_lost(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_INCOMING +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_INCOMING +RustBuffer uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_incoming(void*_Nonnull ptr, RustBuffer data, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_TICK +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_TICK +RustBuffer uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_tick(void*_Nonnull ptr, uint64_t now_ms, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_IS_CONNECTED +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_IS_CONNECTED +int8_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_is_connected(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_NEXT_TICK_MS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_NEXT_TICK_MS +int64_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_next_tick_ms(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_PUBLISH +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_PUBLISH +int32_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_publish(void*_Nonnull ptr, RustBuffer topic, RustBuffer payload, uint8_t qos, RustBuffer priority, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_PUSH_EVENT_FFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_PUSH_EVENT_FFI +void uniffi_flowsdk_ffi_fn_method_mqttengineffi_push_event_ffi(void*_Nonnull ptr, RustBuffer event, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_SUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_SUBSCRIBE +int32_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_subscribe(void*_Nonnull ptr, RustBuffer topic_filter, uint8_t qos, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_TAKE_EVENTS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_TAKE_EVENTS +RustBuffer uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_events(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_TAKE_OUTGOING +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_TAKE_OUTGOING +RustBuffer uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_outgoing(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_UNSUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_UNSUBSCRIBE +int32_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_unsubscribe(void*_Nonnull ptr, RustBuffer topic_filter, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_MQTTEVENTLISTFFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_MQTTEVENTLISTFFI +void*_Nonnull uniffi_flowsdk_ffi_fn_clone_mqtteventlistffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_MQTTEVENTLISTFFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_MQTTEVENTLISTFFI +void uniffi_flowsdk_ffi_fn_free_mqtteventlistffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_GET +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_GET +RustBuffer uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_get(void*_Nonnull ptr, uint32_t index, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_IS_EMPTY +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_IS_EMPTY +int8_t uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_is_empty(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_LEN +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_LEN +uint32_t uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_len(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_QUICMQTTENGINEFFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_QUICMQTTENGINEFFI +void*_Nonnull uniffi_flowsdk_ffi_fn_clone_quicmqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_QUICMQTTENGINEFFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_QUICMQTTENGINEFFI +void uniffi_flowsdk_ffi_fn_free_quicmqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_QUICMQTTENGINEFFI_NEW +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_QUICMQTTENGINEFFI_NEW +void*_Nonnull uniffi_flowsdk_ffi_fn_constructor_quicmqttengineffi_new(RustBuffer opts, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_CONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_CONNECT +void uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_connect(void*_Nonnull ptr, RustBuffer server_addr, RustBuffer server_name, RustBuffer tls_opts, uint64_t now_ms, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_DISCONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_DISCONNECT +void uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_disconnect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_HANDLE_DATAGRAM +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_HANDLE_DATAGRAM +void uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_datagram(void*_Nonnull ptr, RustBuffer data, RustBuffer remote_addr, uint64_t now_ms, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_HANDLE_TICK +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_HANDLE_TICK +RustBuffer uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_tick(void*_Nonnull ptr, uint64_t now_ms, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_IS_CONNECTED +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_IS_CONNECTED +int8_t uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_is_connected(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_PUBLISH +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_PUBLISH +int32_t uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_publish(void*_Nonnull ptr, RustBuffer topic, RustBuffer payload, uint8_t qos, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_SUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_SUBSCRIBE +int32_t uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_subscribe(void*_Nonnull ptr, RustBuffer topic_filter, uint8_t qos, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_TAKE_EVENTS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_TAKE_EVENTS +RustBuffer uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_events(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_TAKE_OUTGOING_DATAGRAMS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_TAKE_OUTGOING_DATAGRAMS +RustBuffer uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_outgoing_datagrams(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_UNSUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_UNSUBSCRIBE +int32_t uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_unsubscribe(void*_Nonnull ptr, RustBuffer topic_filter, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_TLSMQTTENGINEFFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_TLSMQTTENGINEFFI +void*_Nonnull uniffi_flowsdk_ffi_fn_clone_tlsmqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_TLSMQTTENGINEFFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_TLSMQTTENGINEFFI +void uniffi_flowsdk_ffi_fn_free_tlsmqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_TLSMQTTENGINEFFI_NEW +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_TLSMQTTENGINEFFI_NEW +void*_Nonnull uniffi_flowsdk_ffi_fn_constructor_tlsmqttengineffi_new(RustBuffer opts, RustBuffer tls_opts, RustBuffer server_name, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_CONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_CONNECT +void uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_connect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_DISCONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_DISCONNECT +void uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_disconnect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_HANDLE_SOCKET_DATA +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_HANDLE_SOCKET_DATA +void uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_socket_data(void*_Nonnull ptr, RustBuffer data, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_HANDLE_TICK +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_HANDLE_TICK +RustBuffer uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_tick(void*_Nonnull ptr, uint64_t now_ms, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_IS_CONNECTED +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_IS_CONNECTED +int8_t uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_is_connected(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_PUBLISH +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_PUBLISH +int32_t uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_publish(void*_Nonnull ptr, RustBuffer topic, RustBuffer payload, uint8_t qos, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_SUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_SUBSCRIBE +int32_t uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_subscribe(void*_Nonnull ptr, RustBuffer topic_filter, uint8_t qos, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_TAKE_EVENTS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_TAKE_EVENTS +RustBuffer uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_events(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_TAKE_SOCKET_DATA +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_TAKE_SOCKET_DATA +RustBuffer uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_socket_data(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_UNSUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_UNSUBSCRIBE +int32_t uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_unsubscribe(void*_Nonnull ptr, RustBuffer topic_filter, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_ALLOC +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_ALLOC +RustBuffer ffi_flowsdk_ffi_rustbuffer_alloc(uint64_t size, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_FROM_BYTES +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_FROM_BYTES +RustBuffer ffi_flowsdk_ffi_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_FREE +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_FREE +void ffi_flowsdk_ffi_rustbuffer_free(RustBuffer buf, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_RESERVE +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_RESERVE +RustBuffer ffi_flowsdk_ffi_rustbuffer_reserve(RustBuffer buf, uint64_t additional, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U8 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U8 +void ffi_flowsdk_ffi_rust_future_poll_u8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U8 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U8 +void ffi_flowsdk_ffi_rust_future_cancel_u8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U8 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U8 +void ffi_flowsdk_ffi_rust_future_free_u8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U8 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U8 +uint8_t ffi_flowsdk_ffi_rust_future_complete_u8(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I8 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I8 +void ffi_flowsdk_ffi_rust_future_poll_i8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I8 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I8 +void ffi_flowsdk_ffi_rust_future_cancel_i8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I8 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I8 +void ffi_flowsdk_ffi_rust_future_free_i8(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I8 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I8 +int8_t ffi_flowsdk_ffi_rust_future_complete_i8(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U16 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U16 +void ffi_flowsdk_ffi_rust_future_poll_u16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U16 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U16 +void ffi_flowsdk_ffi_rust_future_cancel_u16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U16 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U16 +void ffi_flowsdk_ffi_rust_future_free_u16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U16 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U16 +uint16_t ffi_flowsdk_ffi_rust_future_complete_u16(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I16 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I16 +void ffi_flowsdk_ffi_rust_future_poll_i16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I16 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I16 +void ffi_flowsdk_ffi_rust_future_cancel_i16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I16 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I16 +void ffi_flowsdk_ffi_rust_future_free_i16(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I16 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I16 +int16_t ffi_flowsdk_ffi_rust_future_complete_i16(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U32 +void ffi_flowsdk_ffi_rust_future_poll_u32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U32 +void ffi_flowsdk_ffi_rust_future_cancel_u32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U32 +void ffi_flowsdk_ffi_rust_future_free_u32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U32 +uint32_t ffi_flowsdk_ffi_rust_future_complete_u32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I32 +void ffi_flowsdk_ffi_rust_future_poll_i32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I32 +void ffi_flowsdk_ffi_rust_future_cancel_i32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I32 +void ffi_flowsdk_ffi_rust_future_free_i32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I32 +int32_t ffi_flowsdk_ffi_rust_future_complete_i32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U64 +void ffi_flowsdk_ffi_rust_future_poll_u64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U64 +void ffi_flowsdk_ffi_rust_future_cancel_u64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U64 +void ffi_flowsdk_ffi_rust_future_free_u64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U64 +uint64_t ffi_flowsdk_ffi_rust_future_complete_u64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I64 +void ffi_flowsdk_ffi_rust_future_poll_i64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I64 +void ffi_flowsdk_ffi_rust_future_cancel_i64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I64 +void ffi_flowsdk_ffi_rust_future_free_i64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I64 +int64_t ffi_flowsdk_ffi_rust_future_complete_i64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_F32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_F32 +void ffi_flowsdk_ffi_rust_future_poll_f32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_F32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_F32 +void ffi_flowsdk_ffi_rust_future_cancel_f32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_F32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_F32 +void ffi_flowsdk_ffi_rust_future_free_f32(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_F32 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_F32 +float ffi_flowsdk_ffi_rust_future_complete_f32(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_F64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_F64 +void ffi_flowsdk_ffi_rust_future_poll_f64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_F64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_F64 +void ffi_flowsdk_ffi_rust_future_cancel_f64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_F64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_F64 +void ffi_flowsdk_ffi_rust_future_free_f64(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_F64 +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_F64 +double ffi_flowsdk_ffi_rust_future_complete_f64(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_POINTER +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_POINTER +void ffi_flowsdk_ffi_rust_future_poll_pointer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_POINTER +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_POINTER +void ffi_flowsdk_ffi_rust_future_cancel_pointer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_POINTER +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_POINTER +void ffi_flowsdk_ffi_rust_future_free_pointer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_POINTER +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_POINTER +void*_Nonnull ffi_flowsdk_ffi_rust_future_complete_pointer(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_RUST_BUFFER +void ffi_flowsdk_ffi_rust_future_poll_rust_buffer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_RUST_BUFFER +void ffi_flowsdk_ffi_rust_future_cancel_rust_buffer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_RUST_BUFFER +void ffi_flowsdk_ffi_rust_future_free_rust_buffer(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_RUST_BUFFER +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_RUST_BUFFER +RustBuffer ffi_flowsdk_ffi_rust_future_complete_rust_buffer(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_VOID +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_VOID +void ffi_flowsdk_ffi_rust_future_poll_void(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_VOID +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_VOID +void ffi_flowsdk_ffi_rust_future_cancel_void(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_VOID +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_VOID +void ffi_flowsdk_ffi_rust_future_free_void(uint64_t handle +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_VOID +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_VOID +void ffi_flowsdk_ffi_rust_future_complete_void(uint64_t handle, RustCallStatus *_Nonnull out_status +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_AUTH +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_AUTH +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_auth(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_CONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_CONNECT +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_connect(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_DISCONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_DISCONNECT +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_disconnect(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_GET_VERSION +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_GET_VERSION +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_get_version(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_CONNECTION_LOST +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_CONNECTION_LOST +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_connection_lost(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_INCOMING +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_INCOMING +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_incoming(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_TICK +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_TICK +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_tick(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_IS_CONNECTED +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_IS_CONNECTED +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_is_connected(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_NEXT_TICK_MS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_NEXT_TICK_MS +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_next_tick_ms(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_PUBLISH +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_PUBLISH +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_publish(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_PUSH_EVENT_FFI +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_PUSH_EVENT_FFI +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_push_event_ffi(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_SUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_SUBSCRIBE +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_subscribe(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_TAKE_EVENTS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_TAKE_EVENTS +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_events(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_TAKE_OUTGOING +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_TAKE_OUTGOING +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_outgoing(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_UNSUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_UNSUBSCRIBE +uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_unsubscribe(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_GET +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_GET +uint16_t uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_get(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_IS_EMPTY +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_IS_EMPTY +uint16_t uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_is_empty(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_LEN +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_LEN +uint16_t uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_len(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_CONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_CONNECT +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_connect(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_DISCONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_DISCONNECT +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_disconnect(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_HANDLE_DATAGRAM +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_HANDLE_DATAGRAM +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_datagram(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_HANDLE_TICK +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_HANDLE_TICK +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_tick(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_IS_CONNECTED +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_IS_CONNECTED +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_is_connected(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_PUBLISH +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_PUBLISH +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_publish(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_SUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_SUBSCRIBE +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_subscribe(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_TAKE_EVENTS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_TAKE_EVENTS +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_events(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_TAKE_OUTGOING_DATAGRAMS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_TAKE_OUTGOING_DATAGRAMS +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_outgoing_datagrams(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_UNSUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_UNSUBSCRIBE +uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_unsubscribe(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_CONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_CONNECT +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_connect(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_DISCONNECT +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_DISCONNECT +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_disconnect(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_HANDLE_SOCKET_DATA +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_HANDLE_SOCKET_DATA +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_socket_data(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_HANDLE_TICK +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_HANDLE_TICK +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_tick(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_IS_CONNECTED +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_IS_CONNECTED +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_is_connected(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_PUBLISH +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_PUBLISH +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_publish(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_SUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_SUBSCRIBE +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_subscribe(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_TAKE_EVENTS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_TAKE_EVENTS +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_events(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_TAKE_SOCKET_DATA +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_TAKE_SOCKET_DATA +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_socket_data(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_UNSUBSCRIBE +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_UNSUBSCRIBE +uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_unsubscribe(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_MQTTENGINEFFI_NEW +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_MQTTENGINEFFI_NEW +uint16_t uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_MQTTENGINEFFI_NEW_WITH_OPTS +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_MQTTENGINEFFI_NEW_WITH_OPTS +uint16_t uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new_with_opts(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_QUICMQTTENGINEFFI_NEW +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_QUICMQTTENGINEFFI_NEW +uint16_t uniffi_flowsdk_ffi_checksum_constructor_quicmqttengineffi_new(void + +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_TLSMQTTENGINEFFI_NEW +#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_TLSMQTTENGINEFFI_NEW +uint16_t uniffi_flowsdk_ffi_checksum_constructor_tlsmqttengineffi_new(void + +); +#endif +#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_UNIFFI_CONTRACT_VERSION +#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_UNIFFI_CONTRACT_VERSION +uint32_t ffi_flowsdk_ffi_uniffi_contract_version(void + +); +#endif + From 7ab6f9de3b8844ad7d35f3e4f2f68724f5d49d21 Mon Sep 17 00:00:00 2001 From: William Yang Date: Mon, 20 Apr 2026 11:55:11 +0200 Subject: [PATCH 2/5] chore: fix a clippy warning --- src/mqtt_client/engine.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mqtt_client/engine.rs b/src/mqtt_client/engine.rs index 9843534d..387e4f7c 100644 --- a/src/mqtt_client/engine.rs +++ b/src/mqtt_client/engine.rs @@ -998,13 +998,13 @@ impl QuicMqttEngine { quinn_proto::Event::Stream(_stream_id) => { // Stream event (readable/writable etc) } - quinn_proto::Event::Connected => { + quinn_proto::Event::Connected // QUIC Handshake done. Open a bidirectional stream for MQTT. - if self.mqtt_stream.is_none() { - if let Some(stream_id) = conn.streams().open(quinn_proto::Dir::Bi) { - self.mqtt_stream = Some(stream_id); - self.mqtt_engine.connect(); - } + if self.mqtt_stream.is_none() => + { + if let Some(stream_id) = conn.streams().open(quinn_proto::Dir::Bi) { + self.mqtt_stream = Some(stream_id); + self.mqtt_engine.connect(); } } quinn_proto::Event::ConnectionLost { .. } => { From 9a62c18e26a3134569204d56f783840b230531cb Mon Sep 17 00:00:00 2001 From: William Yang Date: Mon, 20 Apr 2026 16:05:36 +0200 Subject: [PATCH 3/5] fix(example): simplify event handling logic in TokioQuicMqttClient example --- examples/no_io_tokio_quic_client_example.rs | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/no_io_tokio_quic_client_example.rs b/examples/no_io_tokio_quic_client_example.rs index 0bbb828a..dcd2777d 100644 --- a/examples/no_io_tokio_quic_client_example.rs +++ b/examples/no_io_tokio_quic_client_example.rs @@ -44,20 +44,20 @@ async fn run_example() -> Result<(), Box> { event = client.next_event() => { let Some(event) = event else { break; }; match event { - MqttEvent::Connected(_) => { - if !subscribed { - let sub_cmd = SubscribeCommand::builder().add_topic("test/topic/wrapper", 1).build()?; - client.subscribe(sub_cmd).await.map_err(|e| e.to_string())?; - subscribed = true; - } + MqttEvent::Connected(_) + if !subscribed => + { + let sub_cmd = SubscribeCommand::builder().add_topic("test/topic/wrapper", 1).build()?; + client.subscribe(sub_cmd).await.map_err(|e| e.to_string())?; + subscribed = true; } - MqttEvent::Subscribed(res) => { + MqttEvent::Subscribed(res) + if !published => + { println!("Subscribed: ID={:?}", res.packet_id); - if !published { - let pub_cmd = PublishCommand::builder().topic("test/topic/wrapper").payload("Hello!".to_string()).qos(1).build()?; - client.publish(pub_cmd).await.map_err(|e| e.to_string())?; - published = true; - } + let pub_cmd = PublishCommand::builder().topic("test/topic/wrapper").payload("Hello!".to_string()).qos(1).build()?; + client.publish(pub_cmd).await.map_err(|e| e.to_string())?; + published = true; } MqttEvent::Published(res) => { println!("Published: ID={:?}", res.packet_id); From 01b643e758691ed01b719256d1a577cf832f258a Mon Sep 17 00:00:00 2001 From: William Yang Date: Tue, 21 Apr 2026 11:35:28 +0200 Subject: [PATCH 4/5] ci: cover test for swift --- .github/workflows/ci.yml | 45 +- .gitignore | 5 +- .../kotlin/uniffi/flowsdk_ffi/flowsdk_ffi.kt | 3800 ----------------- scripts/build_swift_bindings.sh | 16 + swift/Sources/FlowSDK/flowsdk_ffi.swift | 2537 ----------- swift/Sources/flowsdk_ffi/flowsdk_ffi.h | 1042 ----- 6 files changed, 64 insertions(+), 7381 deletions(-) delete mode 100644 kotlin/package/src/main/kotlin/uniffi/flowsdk_ffi/flowsdk_ffi.kt delete mode 100644 swift/Sources/FlowSDK/flowsdk_ffi.swift delete mode 100644 swift/Sources/flowsdk_ffi/flowsdk_ffi.h diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd4fac72..84a50d0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,6 +207,11 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 + with: + components: llvm-tools-preview + + - name: Install cargo-llvm-cov + run: cargo install cargo-llvm-cov - name: Cache Cargo dependencies uses: actions/cache@v4 @@ -220,7 +225,45 @@ jobs: ${{ runner.os }}-cargo-swift- - name: Build Rust, Generate Swift Bindings, and Verify swift build - run: ./scripts/build_swift_bindings.sh --test + run: ./scripts/build_swift_bindings.sh --coverage --test + + - name: Export coverage to lcov + run: | + PROFDATA_VAR=$(cargo +stable llvm-cov show-env | grep LLVM_PROFDATA) || true + PROFDATA_TOOL=$(echo "$PROFDATA_VAR" | cut -d= -f2- | tr -d '"' | tr -d "'" | xargs) + if [ -z "$PROFDATA_TOOL" ] || [ ! -x "$PROFDATA_TOOL" ]; then + export PATH="$(rustc --print=target-libdir)/../bin:$PATH" + PROFDATA_TOOL=$(which llvm-profdata) + fi + if ls target/llvm-cov-target/*.profraw 2>/dev/null; then + "$PROFDATA_TOOL" merge -sparse target/llvm-cov-target/*.profraw \ + -o target/llvm-cov-target/swift-cov.profdata + llvm-cov export -format=lcov \ + --instr-profile target/llvm-cov-target/swift-cov.profdata \ + -object target/debug/libflowsdk_ffi.dylib \ + > lcov-swift.info + else + echo "No profraw files found; skipping lcov export." + fi + + - name: Upload coverage artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: swift-coverage-data + path: | + lcov-swift.info + target/llvm-cov-target/swift-cov.profdata + target/llvm-cov-target/*.profraw + retention-days: 7 + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: lcov-swift.info + fail_ci_if_error: false + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true coverage: name: Code Coverage diff --git a/.gitignore b/.gitignore index fc1e4478..96e4e019 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,10 @@ swift/xcframework-intermediates/ swift/FlowSDK.xcframework/ -# FFI generated code +# FFI generated code (regenerated by scripts/build_*_bindings.sh; feature-dependent) +swift/Sources/FlowSDK/flowsdk_ffi.swift +swift/Sources/flowsdk_ffi/flowsdk_ffi.h +kotlin/package/src/main/kotlin/uniffi/flowsdk_ffi/flowsdk_ffi.kt python/package/flowsdk/flowsdk_ffi.py python/package/flowsdk/libflowsdk_ffi.dylib python/package/flowsdk/libflowsdk_ffi.so diff --git a/kotlin/package/src/main/kotlin/uniffi/flowsdk_ffi/flowsdk_ffi.kt b/kotlin/package/src/main/kotlin/uniffi/flowsdk_ffi/flowsdk_ffi.kt deleted file mode 100644 index 24344645..00000000 --- a/kotlin/package/src/main/kotlin/uniffi/flowsdk_ffi/flowsdk_ffi.kt +++ /dev/null @@ -1,3800 +0,0 @@ -// This file was autogenerated by some hot garbage in the `uniffi` crate. -// Trust me, you don't want to mess with it! - -@file:Suppress("NAME_SHADOWING") - -package uniffi.flowsdk_ffi - -// Common helper code. -// -// Ideally this would live in a separate .kt file where it can be unittested etc -// in isolation, and perhaps even published as a re-useable package. -// -// However, it's important that the details of how this helper code works (e.g. the -// way that different builtin types are passed across the FFI) exactly match what's -// expected by the Rust code on the other side of the interface. In practice right -// now that means coming from the exact some version of `uniffi` that was used to -// compile the Rust component. The easiest way to ensure this is to bundle the Kotlin -// helpers directly inline like we're doing here. - -import com.sun.jna.Library -import com.sun.jna.IntegerType -import com.sun.jna.Native -import com.sun.jna.Pointer -import com.sun.jna.Structure -import com.sun.jna.Callback -import com.sun.jna.ptr.* -import java.nio.ByteBuffer -import java.nio.ByteOrder -import java.nio.CharBuffer -import java.nio.charset.CodingErrorAction -import java.util.concurrent.atomic.AtomicLong -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.atomic.AtomicBoolean - -// This is a helper for safely working with byte buffers returned from the Rust code. -// A rust-owned buffer is represented by its capacity, its current length, and a -// pointer to the underlying data. - -/** - * @suppress - */ -@Structure.FieldOrder("capacity", "len", "data") -open class RustBuffer : Structure() { - // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values. - // When dealing with these fields, make sure to call `toULong()`. - @JvmField var capacity: Long = 0 - @JvmField var len: Long = 0 - @JvmField var data: Pointer? = null - - class ByValue: RustBuffer(), Structure.ByValue - class ByReference: RustBuffer(), Structure.ByReference - - internal fun setValue(other: RustBuffer) { - capacity = other.capacity - len = other.len - data = other.data - } - - companion object { - internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status -> - // Note: need to convert the size to a `Long` value to make this work with JVM. - UniffiLib.INSTANCE.ffi_flowsdk_ffi_rustbuffer_alloc(size.toLong(), status) - }.also { - if(it.data == null) { - throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})") - } - } - - internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue { - var buf = RustBuffer.ByValue() - buf.capacity = capacity.toLong() - buf.len = len.toLong() - buf.data = data - return buf - } - - internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status -> - UniffiLib.INSTANCE.ffi_flowsdk_ffi_rustbuffer_free(buf, status) - } - } - - @Suppress("TooGenericExceptionThrown") - fun asByteBuffer() = - this.data?.getByteBuffer(0, this.len.toLong())?.also { - it.order(ByteOrder.BIG_ENDIAN) - } -} - -/** - * The equivalent of the `*mut RustBuffer` type. - * Required for callbacks taking in an out pointer. - * - * Size is the sum of all values in the struct. - * - * @suppress - */ -class RustBufferByReference : ByReference(16) { - /** - * Set the pointed-to `RustBuffer` to the given value. - */ - fun setValue(value: RustBuffer.ByValue) { - // NOTE: The offsets are as they are in the C-like struct. - val pointer = getPointer() - pointer.setLong(0, value.capacity) - pointer.setLong(8, value.len) - pointer.setPointer(16, value.data) - } - - /** - * Get a `RustBuffer.ByValue` from this reference. - */ - fun getValue(): RustBuffer.ByValue { - val pointer = getPointer() - val value = RustBuffer.ByValue() - value.writeField("capacity", pointer.getLong(0)) - value.writeField("len", pointer.getLong(8)) - value.writeField("data", pointer.getLong(16)) - - return value - } -} - -// This is a helper for safely passing byte references into the rust code. -// It's not actually used at the moment, because there aren't many things that you -// can take a direct pointer to in the JVM, and if we're going to copy something -// then we might as well copy it into a `RustBuffer`. But it's here for API -// completeness. - -@Structure.FieldOrder("len", "data") -internal open class ForeignBytes : Structure() { - @JvmField var len: Int = 0 - @JvmField var data: Pointer? = null - - class ByValue : ForeignBytes(), Structure.ByValue -} -/** - * The FfiConverter interface handles converter types to and from the FFI - * - * All implementing objects should be public to support external types. When a - * type is external we need to import it's FfiConverter. - * - * @suppress - */ -public interface FfiConverter { - // Convert an FFI type to a Kotlin type - fun lift(value: FfiType): KotlinType - - // Convert an Kotlin type to an FFI type - fun lower(value: KotlinType): FfiType - - // Read a Kotlin type from a `ByteBuffer` - fun read(buf: ByteBuffer): KotlinType - - // Calculate bytes to allocate when creating a `RustBuffer` - // - // This must return at least as many bytes as the write() function will - // write. It can return more bytes than needed, for example when writing - // Strings we can't know the exact bytes needed until we the UTF-8 - // encoding, so we pessimistically allocate the largest size possible (3 - // bytes per codepoint). Allocating extra bytes is not really a big deal - // because the `RustBuffer` is short-lived. - fun allocationSize(value: KotlinType): ULong - - // Write a Kotlin type to a `ByteBuffer` - fun write(value: KotlinType, buf: ByteBuffer) - - // Lower a value into a `RustBuffer` - // - // This method lowers a value into a `RustBuffer` rather than the normal - // FfiType. It's used by the callback interface code. Callback interface - // returns are always serialized into a `RustBuffer` regardless of their - // normal FFI type. - fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue { - val rbuf = RustBuffer.alloc(allocationSize(value)) - try { - val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also { - it.order(ByteOrder.BIG_ENDIAN) - } - write(value, bbuf) - rbuf.writeField("len", bbuf.position().toLong()) - return rbuf - } catch (e: Throwable) { - RustBuffer.free(rbuf) - throw e - } - } - - // Lift a value from a `RustBuffer`. - // - // This here mostly because of the symmetry with `lowerIntoRustBuffer()`. - // It's currently only used by the `FfiConverterRustBuffer` class below. - fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType { - val byteBuf = rbuf.asByteBuffer()!! - try { - val item = read(byteBuf) - if (byteBuf.hasRemaining()) { - throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!") - } - return item - } finally { - RustBuffer.free(rbuf) - } - } -} - -/** - * FfiConverter that uses `RustBuffer` as the FfiType - * - * @suppress - */ -public interface FfiConverterRustBuffer: FfiConverter { - override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value) - override fun lower(value: KotlinType) = lowerIntoRustBuffer(value) -} -// A handful of classes and functions to support the generated data structures. -// This would be a good candidate for isolating in its own ffi-support lib. - -internal const val UNIFFI_CALL_SUCCESS = 0.toByte() -internal const val UNIFFI_CALL_ERROR = 1.toByte() -internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte() - -@Structure.FieldOrder("code", "error_buf") -internal open class UniffiRustCallStatus : Structure() { - @JvmField var code: Byte = 0 - @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue() - - class ByValue: UniffiRustCallStatus(), Structure.ByValue - - fun isSuccess(): Boolean { - return code == UNIFFI_CALL_SUCCESS - } - - fun isError(): Boolean { - return code == UNIFFI_CALL_ERROR - } - - fun isPanic(): Boolean { - return code == UNIFFI_CALL_UNEXPECTED_ERROR - } - - companion object { - fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue { - val callStatus = UniffiRustCallStatus.ByValue() - callStatus.code = code - callStatus.error_buf = errorBuf - return callStatus - } - } -} - -class InternalException(message: String) : kotlin.Exception(message) - -/** - * Each top-level error class has a companion object that can lift the error from the call status's rust buffer - * - * @suppress - */ -interface UniffiRustCallStatusErrorHandler { - fun lift(error_buf: RustBuffer.ByValue): E; -} - -// Helpers for calling Rust -// In practice we usually need to be synchronized to call this safely, so it doesn't -// synchronize itself - -// Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err -private inline fun uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler, callback: (UniffiRustCallStatus) -> U): U { - var status = UniffiRustCallStatus() - val return_value = callback(status) - uniffiCheckCallStatus(errorHandler, status) - return return_value -} - -// Check UniffiRustCallStatus and throw an error if the call wasn't successful -private fun uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler, status: UniffiRustCallStatus) { - if (status.isSuccess()) { - return - } else if (status.isError()) { - throw errorHandler.lift(status.error_buf) - } else if (status.isPanic()) { - // when the rust code sees a panic, it tries to construct a rustbuffer - // with the message. but if that code panics, then it just sends back - // an empty buffer. - if (status.error_buf.len > 0) { - throw InternalException(FfiConverterString.lift(status.error_buf)) - } else { - throw InternalException("Rust panic") - } - } else { - throw InternalException("Unknown rust call status: $status.code") - } -} - -/** - * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR - * - * @suppress - */ -object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler { - override fun lift(error_buf: RustBuffer.ByValue): InternalException { - RustBuffer.free(error_buf) - return InternalException("Unexpected CALL_ERROR") - } -} - -// Call a rust function that returns a plain value -private inline fun uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U { - return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback) -} - -internal inline fun uniffiTraitInterfaceCall( - callStatus: UniffiRustCallStatus, - makeCall: () -> T, - writeReturn: (T) -> Unit, -) { - try { - writeReturn(makeCall()) - } catch(e: kotlin.Exception) { - callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR - callStatus.error_buf = FfiConverterString.lower(e.toString()) - } -} - -internal inline fun uniffiTraitInterfaceCallWithError( - callStatus: UniffiRustCallStatus, - makeCall: () -> T, - writeReturn: (T) -> Unit, - lowerError: (E) -> RustBuffer.ByValue -) { - try { - writeReturn(makeCall()) - } catch(e: kotlin.Exception) { - if (e is E) { - callStatus.code = UNIFFI_CALL_ERROR - callStatus.error_buf = lowerError(e) - } else { - callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR - callStatus.error_buf = FfiConverterString.lower(e.toString()) - } - } -} -// Map handles to objects -// -// This is used pass an opaque 64-bit handle representing a foreign object to the Rust code. -internal class UniffiHandleMap { - private val map = ConcurrentHashMap() - private val counter = java.util.concurrent.atomic.AtomicLong(0) - - val size: Int - get() = map.size - - // Insert a new object into the handle map and get a handle for it - fun insert(obj: T): Long { - val handle = counter.getAndAdd(1) - map.put(handle, obj) - return handle - } - - // Get an object from the handle map - fun get(handle: Long): T { - return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle") - } - - // Remove an entry from the handlemap and get the Kotlin object back - fun remove(handle: Long): T { - return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle") - } -} - -// Contains loading, initialization code, -// and the FFI Function declarations in a com.sun.jna.Library. -@Synchronized -private fun findLibraryName(componentName: String): String { - val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride") - if (libOverride != null) { - return libOverride - } - return "flowsdk_ffi" -} - -private inline fun loadIndirect( - componentName: String -): Lib { - return Native.load(findLibraryName(componentName), Lib::class.java) -} - -// Define FFI callback types -internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback { - fun callback(`data`: Long,`pollResult`: Byte,) -} -internal interface UniffiForeignFutureFree : com.sun.jna.Callback { - fun callback(`handle`: Long,) -} -internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback { - fun callback(`handle`: Long,) -} -@Structure.FieldOrder("handle", "free") -internal open class UniffiForeignFuture( - @JvmField internal var `handle`: Long = 0.toLong(), - @JvmField internal var `free`: UniffiForeignFutureFree? = null, -) : Structure() { - class UniffiByValue( - `handle`: Long = 0.toLong(), - `free`: UniffiForeignFutureFree? = null, - ): UniffiForeignFuture(`handle`,`free`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFuture) { - `handle` = other.`handle` - `free` = other.`free` - } - -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructU8( - @JvmField internal var `returnValue`: Byte = 0.toByte(), - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Byte = 0.toByte(), - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructU8(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructU8) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU8.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructI8( - @JvmField internal var `returnValue`: Byte = 0.toByte(), - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Byte = 0.toByte(), - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructI8(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructI8) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI8.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructU16( - @JvmField internal var `returnValue`: Short = 0.toShort(), - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Short = 0.toShort(), - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructU16(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructU16) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU16.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructI16( - @JvmField internal var `returnValue`: Short = 0.toShort(), - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Short = 0.toShort(), - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructI16(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructI16) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI16.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructU32( - @JvmField internal var `returnValue`: Int = 0, - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Int = 0, - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructU32(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructU32) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU32.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructI32( - @JvmField internal var `returnValue`: Int = 0, - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Int = 0, - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructI32(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructI32) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI32.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructU64( - @JvmField internal var `returnValue`: Long = 0.toLong(), - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Long = 0.toLong(), - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructU64(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructU64) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU64.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructI64( - @JvmField internal var `returnValue`: Long = 0.toLong(), - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Long = 0.toLong(), - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructI64(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructI64) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI64.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructF32( - @JvmField internal var `returnValue`: Float = 0.0f, - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Float = 0.0f, - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructF32(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructF32) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF32.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructF64( - @JvmField internal var `returnValue`: Double = 0.0, - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Double = 0.0, - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructF64(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructF64) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF64.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructPointer( - @JvmField internal var `returnValue`: Pointer = Pointer.NULL, - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: Pointer = Pointer.NULL, - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructPointer(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructPointer) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompletePointer : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructPointer.UniffiByValue,) -} -@Structure.FieldOrder("returnValue", "callStatus") -internal open class UniffiForeignFutureStructRustBuffer( - @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(), - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(), - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructRustBuffer) { - `returnValue` = other.`returnValue` - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructRustBuffer.UniffiByValue,) -} -@Structure.FieldOrder("callStatus") -internal open class UniffiForeignFutureStructVoid( - @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), -) : Structure() { - class UniffiByValue( - `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(), - ): UniffiForeignFutureStructVoid(`callStatus`,), Structure.ByValue - - internal fun uniffiSetValue(other: UniffiForeignFutureStructVoid) { - `callStatus` = other.`callStatus` - } - -} -internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback { - fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,) -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// A JNA Library to expose the extern-C FFI definitions. -// This is an implementation detail which will be called internally by the public API. - -internal interface UniffiLib : Library { - companion object { - internal val INSTANCE: UniffiLib by lazy { - loadIndirect(componentName = "flowsdk_ffi") - .also { lib: UniffiLib -> - uniffiCheckContractApiVersion(lib) - uniffiCheckApiChecksums(lib) - } - } - - // The Cleaner for the whole library - internal val CLEANER: UniffiCleaner by lazy { - UniffiCleaner.create() - } - } - - fun uniffi_flowsdk_ffi_fn_clone_mqttengineffi(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_flowsdk_ffi_fn_free_mqttengineffi(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new(`clientId`: RustBuffer.ByValue,`mqttVersion`: Byte,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new_with_opts(`opts`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_auth(`ptr`: Pointer,`reasonCode`: Byte,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_connect(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_disconnect(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_get_version(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_connection_lost(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_incoming(`ptr`: Pointer,`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_tick(`ptr`: Pointer,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_is_connected(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_next_tick_ms(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Long - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_publish(`ptr`: Pointer,`topic`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`qos`: Byte,`priority`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_push_event_ffi(`ptr`: Pointer,`event`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_subscribe(`ptr`: Pointer,`topicFilter`: RustBuffer.ByValue,`qos`: Byte,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_events(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_outgoing(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_mqttengineffi_unsubscribe(`ptr`: Pointer,`topicFilter`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_clone_mqtteventlistffi(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_flowsdk_ffi_fn_free_mqtteventlistffi(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_get(`ptr`: Pointer,`index`: Int,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_is_empty(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_len(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_clone_quicmqttengineffi(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_flowsdk_ffi_fn_free_quicmqttengineffi(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_constructor_quicmqttengineffi_new(`opts`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_connect(`ptr`: Pointer,`serverAddr`: RustBuffer.ByValue,`serverName`: RustBuffer.ByValue,`tlsOpts`: RustBuffer.ByValue,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_disconnect(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_datagram(`ptr`: Pointer,`data`: RustBuffer.ByValue,`remoteAddr`: RustBuffer.ByValue,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_tick(`ptr`: Pointer,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_is_connected(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_publish(`ptr`: Pointer,`topic`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`qos`: Byte,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_subscribe(`ptr`: Pointer,`topicFilter`: RustBuffer.ByValue,`qos`: Byte,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_events(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_outgoing_datagrams(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_unsubscribe(`ptr`: Pointer,`topicFilter`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_clone_tlsmqttengineffi(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_flowsdk_ffi_fn_free_tlsmqttengineffi(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_constructor_tlsmqttengineffi_new(`opts`: RustBuffer.ByValue,`tlsOpts`: RustBuffer.ByValue,`serverName`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_connect(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_disconnect(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_socket_data(`ptr`: Pointer,`data`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_tick(`ptr`: Pointer,`nowMs`: Long,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_is_connected(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_publish(`ptr`: Pointer,`topic`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`qos`: Byte,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_subscribe(`ptr`: Pointer,`topicFilter`: RustBuffer.ByValue,`qos`: Byte,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_events(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_socket_data(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_unsubscribe(`ptr`: Pointer,`topicFilter`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun ffi_flowsdk_ffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_flowsdk_ffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_flowsdk_ffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun ffi_flowsdk_ffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_flowsdk_ffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_u8(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_u8(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun ffi_flowsdk_ffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_i8(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_i8(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Byte - fun ffi_flowsdk_ffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_u16(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_u16(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Short - fun ffi_flowsdk_ffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_i16(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_i16(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Short - fun ffi_flowsdk_ffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_u32(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_u32(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun ffi_flowsdk_ffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_i32(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_i32(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Int - fun ffi_flowsdk_ffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_u64(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_u64(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Long - fun ffi_flowsdk_ffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_i64(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_i64(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Long - fun ffi_flowsdk_ffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_f32(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_f32(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Float - fun ffi_flowsdk_ffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_f64(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_f64(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Double - fun ffi_flowsdk_ffi_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_pointer(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_pointer(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Pointer - fun ffi_flowsdk_ffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_rust_buffer(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_rust_buffer(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): RustBuffer.ByValue - fun ffi_flowsdk_ffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_cancel_void(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_free_void(`handle`: Long, - ): Unit - fun ffi_flowsdk_ffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus, - ): Unit - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_auth( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_connect( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_disconnect( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_get_version( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_connection_lost( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_incoming( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_tick( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_is_connected( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_next_tick_ms( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_publish( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_push_event_ffi( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_subscribe( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_events( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_outgoing( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqttengineffi_unsubscribe( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_get( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_is_empty( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_len( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_connect( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_disconnect( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_datagram( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_tick( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_is_connected( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_publish( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_subscribe( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_events( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_outgoing_datagrams( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_unsubscribe( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_connect( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_disconnect( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_socket_data( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_tick( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_is_connected( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_publish( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_subscribe( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_events( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_socket_data( - ): Short - fun uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_unsubscribe( - ): Short - fun uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new( - ): Short - fun uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new_with_opts( - ): Short - fun uniffi_flowsdk_ffi_checksum_constructor_quicmqttengineffi_new( - ): Short - fun uniffi_flowsdk_ffi_checksum_constructor_tlsmqttengineffi_new( - ): Short - fun ffi_flowsdk_ffi_uniffi_contract_version( - ): Int - -} - -private fun uniffiCheckContractApiVersion(lib: UniffiLib) { - // Get the bindings contract version from our ComponentInterface - val bindings_contract_version = 26 - // Get the scaffolding contract version by calling the into the dylib - val scaffolding_contract_version = lib.ffi_flowsdk_ffi_uniffi_contract_version() - if (bindings_contract_version != scaffolding_contract_version) { - throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project") - } -} - -@Suppress("UNUSED_PARAMETER") -private fun uniffiCheckApiChecksums(lib: UniffiLib) { - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_auth() != 13274.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_connect() != 11843.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_disconnect() != 35275.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_get_version() != 19826.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_connection_lost() != 12358.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_incoming() != 55488.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_tick() != 40864.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_is_connected() != 33756.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_next_tick_ms() != 63992.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_publish() != 44572.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_push_event_ffi() != 16806.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_subscribe() != 31682.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_events() != 17921.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_outgoing() != 12337.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqttengineffi_unsubscribe() != 51097.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_get() != 5088.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_is_empty() != 43194.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_len() != 36035.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_connect() != 39570.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_disconnect() != 54076.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_datagram() != 34322.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_tick() != 39076.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_is_connected() != 53863.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_publish() != 17969.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_subscribe() != 16787.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_events() != 34914.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_outgoing_datagrams() != 32224.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_unsubscribe() != 48.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_connect() != 53946.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_disconnect() != 58642.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_socket_data() != 27993.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_tick() != 57570.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_is_connected() != 11670.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_publish() != 29858.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_subscribe() != 35959.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_events() != 41728.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_socket_data() != 6663.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_unsubscribe() != 21790.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new() != 63280.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new_with_opts() != 49926.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_constructor_quicmqttengineffi_new() != 4296.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } - if (lib.uniffi_flowsdk_ffi_checksum_constructor_tlsmqttengineffi_new() != 55234.toShort()) { - throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } -} - -// Async support - -// Public interface members begin here. - - -// Interface implemented by anything that can contain an object reference. -// -// Such types expose a `destroy()` method that must be called to cleanly -// dispose of the contained objects. Failure to call this method may result -// in memory leaks. -// -// The easiest way to ensure this method is called is to use the `.use` -// helper method to execute a block and destroy the object at the end. -interface Disposable { - fun destroy() - companion object { - fun destroy(vararg args: Any?) { - args.filterIsInstance() - .forEach(Disposable::destroy) - } - } -} - -/** - * @suppress - */ -inline fun T.use(block: (T) -> R) = - try { - block(this) - } finally { - try { - // N.B. our implementation is on the nullable type `Disposable?`. - this?.destroy() - } catch (e: Throwable) { - // swallow - } - } - -/** - * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly. - * - * @suppress - * */ -object NoPointer - -/** - * @suppress - */ -public object FfiConverterUByte: FfiConverter { - override fun lift(value: Byte): UByte { - return value.toUByte() - } - - override fun read(buf: ByteBuffer): UByte { - return lift(buf.get()) - } - - override fun lower(value: UByte): Byte { - return value.toByte() - } - - override fun allocationSize(value: UByte) = 1UL - - override fun write(value: UByte, buf: ByteBuffer) { - buf.put(value.toByte()) - } -} - -/** - * @suppress - */ -public object FfiConverterUShort: FfiConverter { - override fun lift(value: Short): UShort { - return value.toUShort() - } - - override fun read(buf: ByteBuffer): UShort { - return lift(buf.getShort()) - } - - override fun lower(value: UShort): Short { - return value.toShort() - } - - override fun allocationSize(value: UShort) = 2UL - - override fun write(value: UShort, buf: ByteBuffer) { - buf.putShort(value.toShort()) - } -} - -/** - * @suppress - */ -public object FfiConverterUInt: FfiConverter { - override fun lift(value: Int): UInt { - return value.toUInt() - } - - override fun read(buf: ByteBuffer): UInt { - return lift(buf.getInt()) - } - - override fun lower(value: UInt): Int { - return value.toInt() - } - - override fun allocationSize(value: UInt) = 4UL - - override fun write(value: UInt, buf: ByteBuffer) { - buf.putInt(value.toInt()) - } -} - -/** - * @suppress - */ -public object FfiConverterInt: FfiConverter { - override fun lift(value: Int): Int { - return value - } - - override fun read(buf: ByteBuffer): Int { - return buf.getInt() - } - - override fun lower(value: Int): Int { - return value - } - - override fun allocationSize(value: Int) = 4UL - - override fun write(value: Int, buf: ByteBuffer) { - buf.putInt(value) - } -} - -/** - * @suppress - */ -public object FfiConverterULong: FfiConverter { - override fun lift(value: Long): ULong { - return value.toULong() - } - - override fun read(buf: ByteBuffer): ULong { - return lift(buf.getLong()) - } - - override fun lower(value: ULong): Long { - return value.toLong() - } - - override fun allocationSize(value: ULong) = 8UL - - override fun write(value: ULong, buf: ByteBuffer) { - buf.putLong(value.toLong()) - } -} - -/** - * @suppress - */ -public object FfiConverterLong: FfiConverter { - override fun lift(value: Long): Long { - return value - } - - override fun read(buf: ByteBuffer): Long { - return buf.getLong() - } - - override fun lower(value: Long): Long { - return value - } - - override fun allocationSize(value: Long) = 8UL - - override fun write(value: Long, buf: ByteBuffer) { - buf.putLong(value) - } -} - -/** - * @suppress - */ -public object FfiConverterBoolean: FfiConverter { - override fun lift(value: Byte): Boolean { - return value.toInt() != 0 - } - - override fun read(buf: ByteBuffer): Boolean { - return lift(buf.get()) - } - - override fun lower(value: Boolean): Byte { - return if (value) 1.toByte() else 0.toByte() - } - - override fun allocationSize(value: Boolean) = 1UL - - override fun write(value: Boolean, buf: ByteBuffer) { - buf.put(lower(value)) - } -} - -/** - * @suppress - */ -public object FfiConverterString: FfiConverter { - // Note: we don't inherit from FfiConverterRustBuffer, because we use a - // special encoding when lowering/lifting. We can use `RustBuffer.len` to - // store our length and avoid writing it out to the buffer. - override fun lift(value: RustBuffer.ByValue): String { - try { - val byteArr = ByteArray(value.len.toInt()) - value.asByteBuffer()!!.get(byteArr) - return byteArr.toString(Charsets.UTF_8) - } finally { - RustBuffer.free(value) - } - } - - override fun read(buf: ByteBuffer): String { - val len = buf.getInt() - val byteArr = ByteArray(len) - buf.get(byteArr) - return byteArr.toString(Charsets.UTF_8) - } - - fun toUtf8(value: String): ByteBuffer { - // Make sure we don't have invalid UTF-16, check for lone surrogates. - return Charsets.UTF_8.newEncoder().run { - onMalformedInput(CodingErrorAction.REPORT) - encode(CharBuffer.wrap(value)) - } - } - - override fun lower(value: String): RustBuffer.ByValue { - val byteBuf = toUtf8(value) - // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us - // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`. - val rbuf = RustBuffer.alloc(byteBuf.limit().toULong()) - rbuf.asByteBuffer()!!.put(byteBuf) - return rbuf - } - - // We aren't sure exactly how many bytes our string will be once it's UTF-8 - // encoded. Allocate 3 bytes per UTF-16 code unit which will always be - // enough. - override fun allocationSize(value: String): ULong { - val sizeForLength = 4UL - val sizeForString = value.length.toULong() * 3UL - return sizeForLength + sizeForString - } - - override fun write(value: String, buf: ByteBuffer) { - val byteBuf = toUtf8(value) - buf.putInt(byteBuf.limit()) - buf.put(byteBuf) - } -} - -/** - * @suppress - */ -public object FfiConverterByteArray: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): ByteArray { - val len = buf.getInt() - val byteArr = ByteArray(len) - buf.get(byteArr) - return byteArr - } - override fun allocationSize(value: ByteArray): ULong { - return 4UL + value.size.toULong() - } - override fun write(value: ByteArray, buf: ByteBuffer) { - buf.putInt(value.size) - buf.put(value) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -/** - * The cleaner interface for Object finalization code to run. - * This is the entry point to any implementation that we're using. - * - * The cleaner registers objects and returns cleanables, so now we are - * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the - * different implmentations available at compile time. - * - * @suppress - */ -interface UniffiCleaner { - interface Cleanable { - fun clean() - } - - fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable - - companion object -} - -// The fallback Jna cleaner, which is available for both Android, and the JVM. -private class UniffiJnaCleaner : UniffiCleaner { - private val cleaner = com.sun.jna.internal.Cleaner.getCleaner() - - override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable = - UniffiJnaCleanable(cleaner.register(value, cleanUpTask)) -} - -private class UniffiJnaCleanable( - private val cleanable: com.sun.jna.internal.Cleaner.Cleanable, -) : UniffiCleaner.Cleanable { - override fun clean() = cleanable.clean() -} - -// We decide at uniffi binding generation time whether we were -// using Android or not. -// There are further runtime checks to chose the correct implementation -// of the cleaner. -private fun UniffiCleaner.Companion.create(): UniffiCleaner = - try { - // For safety's sake: if the library hasn't been run in android_cleaner = true - // mode, but is being run on Android, then we still need to think about - // Android API versions. - // So we check if java.lang.ref.Cleaner is there, and use that… - java.lang.Class.forName("java.lang.ref.Cleaner") - JavaLangRefCleaner() - } catch (e: ClassNotFoundException) { - // … otherwise, fallback to the JNA cleaner. - UniffiJnaCleaner() - } - -private class JavaLangRefCleaner : UniffiCleaner { - val cleaner = java.lang.ref.Cleaner.create() - - override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable = - JavaLangRefCleanable(cleaner.register(value, cleanUpTask)) -} - -private class JavaLangRefCleanable( - val cleanable: java.lang.ref.Cleaner.Cleanable -) : UniffiCleaner.Cleanable { - override fun clean() = cleanable.clean() -} -public interface MqttEngineFfiInterface { - - fun `auth`(`reasonCode`: kotlin.UByte) - - fun `connect`() - - fun `disconnect`() - - fun `getVersion`(): kotlin.UByte - - fun `handleConnectionLost`() - - fun `handleIncoming`(`data`: kotlin.ByteArray): List - - fun `handleTick`(`nowMs`: kotlin.ULong): List - - fun `isConnected`(): kotlin.Boolean - - fun `nextTickMs`(): kotlin.Long - - fun `publish`(`topic`: kotlin.String, `payload`: kotlin.ByteArray, `qos`: kotlin.UByte, `priority`: kotlin.UByte?): kotlin.Int - - fun `pushEventFfi`(`event`: MqttEventFfi) - - fun `subscribe`(`topicFilter`: kotlin.String, `qos`: kotlin.UByte): kotlin.Int - - fun `takeEvents`(): List - - fun `takeOutgoing`(): kotlin.ByteArray - - fun `unsubscribe`(`topicFilter`: kotlin.String): kotlin.Int - - companion object -} - -open class MqttEngineFfi: Disposable, AutoCloseable, MqttEngineFfiInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - constructor(`clientId`: kotlin.String?, `mqttVersion`: kotlin.UByte) : - this( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new( - FfiConverterOptionalString.lower(`clientId`),FfiConverterUByte.lower(`mqttVersion`),_status) -} - ) - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_free_mqttengineffi(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_clone_mqttengineffi(pointer!!, status) - } - } - - override fun `auth`(`reasonCode`: kotlin.UByte) - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_auth( - it, FfiConverterUByte.lower(`reasonCode`),_status) -} - } - - - - override fun `connect`() - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_connect( - it, _status) -} - } - - - - override fun `disconnect`() - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_disconnect( - it, _status) -} - } - - - - override fun `getVersion`(): kotlin.UByte { - return FfiConverterUByte.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_get_version( - it, _status) -} - } - ) - } - - - override fun `handleConnectionLost`() - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_connection_lost( - it, _status) -} - } - - - - override fun `handleIncoming`(`data`: kotlin.ByteArray): List { - return FfiConverterSequenceTypeMqttEventFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_incoming( - it, FfiConverterByteArray.lower(`data`),_status) -} - } - ) - } - - - override fun `handleTick`(`nowMs`: kotlin.ULong): List { - return FfiConverterSequenceTypeMqttEventFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_tick( - it, FfiConverterULong.lower(`nowMs`),_status) -} - } - ) - } - - - override fun `isConnected`(): kotlin.Boolean { - return FfiConverterBoolean.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_is_connected( - it, _status) -} - } - ) - } - - - override fun `nextTickMs`(): kotlin.Long { - return FfiConverterLong.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_next_tick_ms( - it, _status) -} - } - ) - } - - - override fun `publish`(`topic`: kotlin.String, `payload`: kotlin.ByteArray, `qos`: kotlin.UByte, `priority`: kotlin.UByte?): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_publish( - it, FfiConverterString.lower(`topic`),FfiConverterByteArray.lower(`payload`),FfiConverterUByte.lower(`qos`),FfiConverterOptionalUByte.lower(`priority`),_status) -} - } - ) - } - - - override fun `pushEventFfi`(`event`: MqttEventFfi) - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_push_event_ffi( - it, FfiConverterTypeMqttEventFFI.lower(`event`),_status) -} - } - - - - override fun `subscribe`(`topicFilter`: kotlin.String, `qos`: kotlin.UByte): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_subscribe( - it, FfiConverterString.lower(`topicFilter`),FfiConverterUByte.lower(`qos`),_status) -} - } - ) - } - - - override fun `takeEvents`(): List { - return FfiConverterSequenceTypeMqttEventFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_events( - it, _status) -} - } - ) - } - - - override fun `takeOutgoing`(): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_outgoing( - it, _status) -} - } - ) - } - - - override fun `unsubscribe`(`topicFilter`: kotlin.String): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqttengineffi_unsubscribe( - it, FfiConverterString.lower(`topicFilter`),_status) -} - } - ) - } - - - - - - companion object { - fun `newWithOpts`(`opts`: MqttOptionsFfi): MqttEngineFfi { - return FfiConverterTypeMqttEngineFFI.lift( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new_with_opts( - FfiConverterTypeMqttOptionsFFI.lower(`opts`),_status) -} - ) - } - - - - } - -} - -/** - * @suppress - */ -public object FfiConverterTypeMqttEngineFFI: FfiConverter { - - override fun lower(value: MqttEngineFfi): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): MqttEngineFfi { - return MqttEngineFfi(value) - } - - override fun read(buf: ByteBuffer): MqttEngineFfi { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: MqttEngineFfi) = 8UL - - override fun write(value: MqttEngineFfi, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface MqttEventListFfiInterface { - - fun `get`(`index`: kotlin.UInt): MqttEventFfi? - - fun `isEmpty`(): kotlin.Boolean - - fun `len`(): kotlin.UInt - - companion object -} - -open class MqttEventListFfi: Disposable, AutoCloseable, MqttEventListFfiInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_free_mqtteventlistffi(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_clone_mqtteventlistffi(pointer!!, status) - } - } - - override fun `get`(`index`: kotlin.UInt): MqttEventFfi? { - return FfiConverterOptionalTypeMqttEventFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_get( - it, FfiConverterUInt.lower(`index`),_status) -} - } - ) - } - - - override fun `isEmpty`(): kotlin.Boolean { - return FfiConverterBoolean.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_is_empty( - it, _status) -} - } - ) - } - - - override fun `len`(): kotlin.UInt { - return FfiConverterUInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_len( - it, _status) -} - } - ) - } - - - - - - - companion object - -} - -/** - * @suppress - */ -public object FfiConverterTypeMqttEventListFFI: FfiConverter { - - override fun lower(value: MqttEventListFfi): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): MqttEventListFfi { - return MqttEventListFfi(value) - } - - override fun read(buf: ByteBuffer): MqttEventListFfi { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: MqttEventListFfi) = 8UL - - override fun write(value: MqttEventListFfi, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface QuicMqttEngineFfiInterface { - - fun `connect`(`serverAddr`: kotlin.String, `serverName`: kotlin.String, `tlsOpts`: MqttTlsOptionsFfi, `nowMs`: kotlin.ULong) - - fun `disconnect`() - - fun `handleDatagram`(`data`: kotlin.ByteArray, `remoteAddr`: kotlin.String, `nowMs`: kotlin.ULong) - - fun `handleTick`(`nowMs`: kotlin.ULong): List - - fun `isConnected`(): kotlin.Boolean - - fun `publish`(`topic`: kotlin.String, `payload`: kotlin.ByteArray, `qos`: kotlin.UByte): kotlin.Int - - fun `subscribe`(`topicFilter`: kotlin.String, `qos`: kotlin.UByte): kotlin.Int - - fun `takeEvents`(): List - - fun `takeOutgoingDatagrams`(): List - - fun `unsubscribe`(`topicFilter`: kotlin.String): kotlin.Int - - companion object -} - -open class QuicMqttEngineFfi: Disposable, AutoCloseable, QuicMqttEngineFfiInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - constructor(`opts`: MqttOptionsFfi) : - this( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_constructor_quicmqttengineffi_new( - FfiConverterTypeMqttOptionsFFI.lower(`opts`),_status) -} - ) - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_free_quicmqttengineffi(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_clone_quicmqttengineffi(pointer!!, status) - } - } - - override fun `connect`(`serverAddr`: kotlin.String, `serverName`: kotlin.String, `tlsOpts`: MqttTlsOptionsFfi, `nowMs`: kotlin.ULong) - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_connect( - it, FfiConverterString.lower(`serverAddr`),FfiConverterString.lower(`serverName`),FfiConverterTypeMqttTlsOptionsFFI.lower(`tlsOpts`),FfiConverterULong.lower(`nowMs`),_status) -} - } - - - - override fun `disconnect`() - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_disconnect( - it, _status) -} - } - - - - override fun `handleDatagram`(`data`: kotlin.ByteArray, `remoteAddr`: kotlin.String, `nowMs`: kotlin.ULong) - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_datagram( - it, FfiConverterByteArray.lower(`data`),FfiConverterString.lower(`remoteAddr`),FfiConverterULong.lower(`nowMs`),_status) -} - } - - - - override fun `handleTick`(`nowMs`: kotlin.ULong): List { - return FfiConverterSequenceTypeMqttEventFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_tick( - it, FfiConverterULong.lower(`nowMs`),_status) -} - } - ) - } - - - override fun `isConnected`(): kotlin.Boolean { - return FfiConverterBoolean.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_is_connected( - it, _status) -} - } - ) - } - - - override fun `publish`(`topic`: kotlin.String, `payload`: kotlin.ByteArray, `qos`: kotlin.UByte): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_publish( - it, FfiConverterString.lower(`topic`),FfiConverterByteArray.lower(`payload`),FfiConverterUByte.lower(`qos`),_status) -} - } - ) - } - - - override fun `subscribe`(`topicFilter`: kotlin.String, `qos`: kotlin.UByte): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_subscribe( - it, FfiConverterString.lower(`topicFilter`),FfiConverterUByte.lower(`qos`),_status) -} - } - ) - } - - - override fun `takeEvents`(): List { - return FfiConverterSequenceTypeMqttEventFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_events( - it, _status) -} - } - ) - } - - - override fun `takeOutgoingDatagrams`(): List { - return FfiConverterSequenceTypeMqttDatagramFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_outgoing_datagrams( - it, _status) -} - } - ) - } - - - override fun `unsubscribe`(`topicFilter`: kotlin.String): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_unsubscribe( - it, FfiConverterString.lower(`topicFilter`),_status) -} - } - ) - } - - - - - - - companion object - -} - -/** - * @suppress - */ -public object FfiConverterTypeQuicMqttEngineFFI: FfiConverter { - - override fun lower(value: QuicMqttEngineFfi): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): QuicMqttEngineFfi { - return QuicMqttEngineFfi(value) - } - - override fun read(buf: ByteBuffer): QuicMqttEngineFfi { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: QuicMqttEngineFfi) = 8UL - - override fun write(value: QuicMqttEngineFfi, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - -// This template implements a class for working with a Rust struct via a Pointer/Arc -// to the live Rust struct on the other side of the FFI. -// -// Each instance implements core operations for working with the Rust `Arc` and the -// Kotlin Pointer to work with the live Rust struct on the other side of the FFI. -// -// There's some subtlety here, because we have to be careful not to operate on a Rust -// struct after it has been dropped, and because we must expose a public API for freeing -// theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are: -// -// * Each instance holds an opaque pointer to the underlying Rust struct. -// Method calls need to read this pointer from the object's state and pass it in to -// the Rust FFI. -// -// * When an instance is no longer needed, its pointer should be passed to a -// special destructor function provided by the Rust FFI, which will drop the -// underlying Rust struct. -// -// * Given an instance, calling code is expected to call the special -// `destroy` method in order to free it after use, either by calling it explicitly -// or by using a higher-level helper like the `use` method. Failing to do so risks -// leaking the underlying Rust struct. -// -// * We can't assume that calling code will do the right thing, and must be prepared -// to handle Kotlin method calls executing concurrently with or even after a call to -// `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`. -// -// * We must never allow Rust code to operate on the underlying Rust struct after -// the destructor has been called, and must never call the destructor more than once. -// Doing so may trigger memory unsafety. -// -// * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner` -// is implemented to call the destructor when the Kotlin object becomes unreachable. -// This is done in a background thread. This is not a panacea, and client code should be aware that -// 1. the thread may starve if some there are objects that have poorly performing -// `drop` methods or do significant work in their `drop` methods. -// 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`, -// or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html). -// -// If we try to implement this with mutual exclusion on access to the pointer, there is the -// possibility of a race between a method call and a concurrent call to `destroy`: -// -// * Thread A starts a method call, reads the value of the pointer, but is interrupted -// before it can pass the pointer over the FFI to Rust. -// * Thread B calls `destroy` and frees the underlying Rust struct. -// * Thread A resumes, passing the already-read pointer value to Rust and triggering -// a use-after-free. -// -// One possible solution would be to use a `ReadWriteLock`, with each method call taking -// a read lock (and thus allowed to run concurrently) and the special `destroy` method -// taking a write lock (and thus blocking on live method calls). However, we aim not to -// generate methods with any hidden blocking semantics, and a `destroy` method that might -// block if called incorrectly seems to meet that bar. -// -// So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track -// the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy` -// has been called. These are updated according to the following rules: -// -// * The initial value of the counter is 1, indicating a live object with no in-flight calls. -// The initial value for the flag is false. -// -// * At the start of each method call, we atomically check the counter. -// If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted. -// If it is nonzero them we atomically increment it by 1 and proceed with the method call. -// -// * At the end of each method call, we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// * When `destroy` is called, we atomically flip the flag from false to true. -// If the flag was already true we silently fail. -// Otherwise we atomically decrement and check the counter. -// If it has reached zero then we destroy the underlying Rust struct. -// -// Astute readers may observe that this all sounds very similar to the way that Rust's `Arc` works, -// and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`. -// -// The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been -// called *and* all in-flight method calls have completed, avoiding violating any of the expectations -// of the underlying Rust code. -// -// This makes a cleaner a better alternative to _not_ calling `destroy()` as -// and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop` -// method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner -// thread may be starved, and the app will leak memory. -// -// In this case, `destroy`ing manually may be a better solution. -// -// The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects -// with Rust peers are reclaimed: -// -// 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen: -// 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then: -// 3. The memory is reclaimed when the process terminates. -// -// [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219 -// - - -public interface TlsMqttEngineFfiInterface { - - fun `connect`() - - fun `disconnect`() - - fun `handleSocketData`(`data`: kotlin.ByteArray) - - fun `handleTick`(`nowMs`: kotlin.ULong): List - - fun `isConnected`(): kotlin.Boolean - - fun `publish`(`topic`: kotlin.String, `payload`: kotlin.ByteArray, `qos`: kotlin.UByte): kotlin.Int - - fun `subscribe`(`topicFilter`: kotlin.String, `qos`: kotlin.UByte): kotlin.Int - - fun `takeEvents`(): List - - fun `takeSocketData`(): kotlin.ByteArray - - fun `unsubscribe`(`topicFilter`: kotlin.String): kotlin.Int - - companion object -} - -open class TlsMqttEngineFfi: Disposable, AutoCloseable, TlsMqttEngineFfiInterface { - - constructor(pointer: Pointer) { - this.pointer = pointer - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - - /** - * This constructor can be used to instantiate a fake object. Only used for tests. Any - * attempt to actually use an object constructed this way will fail as there is no - * connected Rust object. - */ - @Suppress("UNUSED_PARAMETER") - constructor(noPointer: NoPointer) { - this.pointer = null - this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer)) - } - constructor(`opts`: MqttOptionsFfi, `tlsOpts`: MqttTlsOptionsFfi, `serverName`: kotlin.String) : - this( - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_constructor_tlsmqttengineffi_new( - FfiConverterTypeMqttOptionsFFI.lower(`opts`),FfiConverterTypeMqttTlsOptionsFFI.lower(`tlsOpts`),FfiConverterString.lower(`serverName`),_status) -} - ) - - protected val pointer: Pointer? - protected val cleanable: UniffiCleaner.Cleanable - - private val wasDestroyed = AtomicBoolean(false) - private val callCounter = AtomicLong(1) - - override fun destroy() { - // Only allow a single call to this method. - // TODO: maybe we should log a warning if called more than once? - if (this.wasDestroyed.compareAndSet(false, true)) { - // This decrement always matches the initial count of 1 given at creation time. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - @Synchronized - override fun close() { - this.destroy() - } - - internal inline fun callWithPointer(block: (ptr: Pointer) -> R): R { - // Check and increment the call counter, to keep the object alive. - // This needs a compare-and-set retry loop in case of concurrent updates. - do { - val c = this.callCounter.get() - if (c == 0L) { - throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed") - } - if (c == Long.MAX_VALUE) { - throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow") - } - } while (! this.callCounter.compareAndSet(c, c + 1L)) - // Now we can safely do the method call without the pointer being freed concurrently. - try { - return block(this.uniffiClonePointer()) - } finally { - // This decrement always matches the increment we performed above. - if (this.callCounter.decrementAndGet() == 0L) { - cleanable.clean() - } - } - } - - // Use a static inner class instead of a closure so as not to accidentally - // capture `this` as part of the cleanable's action. - private class UniffiCleanAction(private val pointer: Pointer?) : Runnable { - override fun run() { - pointer?.let { ptr -> - uniffiRustCall { status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_free_tlsmqttengineffi(ptr, status) - } - } - } - } - - fun uniffiClonePointer(): Pointer { - return uniffiRustCall() { status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_clone_tlsmqttengineffi(pointer!!, status) - } - } - - override fun `connect`() - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_connect( - it, _status) -} - } - - - - override fun `disconnect`() - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_disconnect( - it, _status) -} - } - - - - override fun `handleSocketData`(`data`: kotlin.ByteArray) - = - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_socket_data( - it, FfiConverterByteArray.lower(`data`),_status) -} - } - - - - override fun `handleTick`(`nowMs`: kotlin.ULong): List { - return FfiConverterSequenceTypeMqttEventFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_tick( - it, FfiConverterULong.lower(`nowMs`),_status) -} - } - ) - } - - - override fun `isConnected`(): kotlin.Boolean { - return FfiConverterBoolean.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_is_connected( - it, _status) -} - } - ) - } - - - override fun `publish`(`topic`: kotlin.String, `payload`: kotlin.ByteArray, `qos`: kotlin.UByte): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_publish( - it, FfiConverterString.lower(`topic`),FfiConverterByteArray.lower(`payload`),FfiConverterUByte.lower(`qos`),_status) -} - } - ) - } - - - override fun `subscribe`(`topicFilter`: kotlin.String, `qos`: kotlin.UByte): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_subscribe( - it, FfiConverterString.lower(`topicFilter`),FfiConverterUByte.lower(`qos`),_status) -} - } - ) - } - - - override fun `takeEvents`(): List { - return FfiConverterSequenceTypeMqttEventFFI.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_events( - it, _status) -} - } - ) - } - - - override fun `takeSocketData`(): kotlin.ByteArray { - return FfiConverterByteArray.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_socket_data( - it, _status) -} - } - ) - } - - - override fun `unsubscribe`(`topicFilter`: kotlin.String): kotlin.Int { - return FfiConverterInt.lift( - callWithPointer { - uniffiRustCall() { _status -> - UniffiLib.INSTANCE.uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_unsubscribe( - it, FfiConverterString.lower(`topicFilter`),_status) -} - } - ) - } - - - - - - - companion object - -} - -/** - * @suppress - */ -public object FfiConverterTypeTlsMqttEngineFFI: FfiConverter { - - override fun lower(value: TlsMqttEngineFfi): Pointer { - return value.uniffiClonePointer() - } - - override fun lift(value: Pointer): TlsMqttEngineFfi { - return TlsMqttEngineFfi(value) - } - - override fun read(buf: ByteBuffer): TlsMqttEngineFfi { - // The Rust code always writes pointers as 8 bytes, and will - // fail to compile if they don't fit. - return lift(Pointer(buf.getLong())) - } - - override fun allocationSize(value: TlsMqttEngineFfi) = 8UL - - override fun write(value: TlsMqttEngineFfi, buf: ByteBuffer) { - // The Rust code always expects pointers written as 8 bytes, - // and will fail to compile if they don't fit. - buf.putLong(Pointer.nativeValue(lower(value))) - } -} - - - -data class ConnectionResultFfi ( - var `reasonCode`: kotlin.UByte, - var `sessionPresent`: kotlin.Boolean -) { - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypeConnectionResultFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): ConnectionResultFfi { - return ConnectionResultFfi( - FfiConverterUByte.read(buf), - FfiConverterBoolean.read(buf), - ) - } - - override fun allocationSize(value: ConnectionResultFfi) = ( - FfiConverterUByte.allocationSize(value.`reasonCode`) + - FfiConverterBoolean.allocationSize(value.`sessionPresent`) - ) - - override fun write(value: ConnectionResultFfi, buf: ByteBuffer) { - FfiConverterUByte.write(value.`reasonCode`, buf) - FfiConverterBoolean.write(value.`sessionPresent`, buf) - } -} - - - -data class MqttDatagramFfi ( - var `addr`: kotlin.String, - var `data`: kotlin.ByteArray -) { - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypeMqttDatagramFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): MqttDatagramFfi { - return MqttDatagramFfi( - FfiConverterString.read(buf), - FfiConverterByteArray.read(buf), - ) - } - - override fun allocationSize(value: MqttDatagramFfi) = ( - FfiConverterString.allocationSize(value.`addr`) + - FfiConverterByteArray.allocationSize(value.`data`) - ) - - override fun write(value: MqttDatagramFfi, buf: ByteBuffer) { - FfiConverterString.write(value.`addr`, buf) - FfiConverterByteArray.write(value.`data`, buf) - } -} - - - -data class MqttMessageFfi ( - var `topic`: kotlin.String, - var `payload`: kotlin.ByteArray, - var `qos`: kotlin.UByte, - var `retain`: kotlin.Boolean -) { - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypeMqttMessageFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): MqttMessageFfi { - return MqttMessageFfi( - FfiConverterString.read(buf), - FfiConverterByteArray.read(buf), - FfiConverterUByte.read(buf), - FfiConverterBoolean.read(buf), - ) - } - - override fun allocationSize(value: MqttMessageFfi) = ( - FfiConverterString.allocationSize(value.`topic`) + - FfiConverterByteArray.allocationSize(value.`payload`) + - FfiConverterUByte.allocationSize(value.`qos`) + - FfiConverterBoolean.allocationSize(value.`retain`) - ) - - override fun write(value: MqttMessageFfi, buf: ByteBuffer) { - FfiConverterString.write(value.`topic`, buf) - FfiConverterByteArray.write(value.`payload`, buf) - FfiConverterUByte.write(value.`qos`, buf) - FfiConverterBoolean.write(value.`retain`, buf) - } -} - - - -data class MqttOptionsFfi ( - var `clientId`: kotlin.String, - var `mqttVersion`: kotlin.UByte, - var `cleanStart`: kotlin.Boolean, - var `keepAlive`: kotlin.UShort, - var `username`: kotlin.String?, - var `password`: kotlin.String?, - var `reconnectBaseDelayMs`: kotlin.ULong, - var `reconnectMaxDelayMs`: kotlin.ULong, - var `maxReconnectAttempts`: kotlin.UInt -) { - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypeMqttOptionsFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): MqttOptionsFfi { - return MqttOptionsFfi( - FfiConverterString.read(buf), - FfiConverterUByte.read(buf), - FfiConverterBoolean.read(buf), - FfiConverterUShort.read(buf), - FfiConverterOptionalString.read(buf), - FfiConverterOptionalString.read(buf), - FfiConverterULong.read(buf), - FfiConverterULong.read(buf), - FfiConverterUInt.read(buf), - ) - } - - override fun allocationSize(value: MqttOptionsFfi) = ( - FfiConverterString.allocationSize(value.`clientId`) + - FfiConverterUByte.allocationSize(value.`mqttVersion`) + - FfiConverterBoolean.allocationSize(value.`cleanStart`) + - FfiConverterUShort.allocationSize(value.`keepAlive`) + - FfiConverterOptionalString.allocationSize(value.`username`) + - FfiConverterOptionalString.allocationSize(value.`password`) + - FfiConverterULong.allocationSize(value.`reconnectBaseDelayMs`) + - FfiConverterULong.allocationSize(value.`reconnectMaxDelayMs`) + - FfiConverterUInt.allocationSize(value.`maxReconnectAttempts`) - ) - - override fun write(value: MqttOptionsFfi, buf: ByteBuffer) { - FfiConverterString.write(value.`clientId`, buf) - FfiConverterUByte.write(value.`mqttVersion`, buf) - FfiConverterBoolean.write(value.`cleanStart`, buf) - FfiConverterUShort.write(value.`keepAlive`, buf) - FfiConverterOptionalString.write(value.`username`, buf) - FfiConverterOptionalString.write(value.`password`, buf) - FfiConverterULong.write(value.`reconnectBaseDelayMs`, buf) - FfiConverterULong.write(value.`reconnectMaxDelayMs`, buf) - FfiConverterUInt.write(value.`maxReconnectAttempts`, buf) - } -} - - - -data class MqttTlsOptionsFfi ( - var `caCertFile`: kotlin.String?, - var `clientCertFile`: kotlin.String?, - var `clientKeyFile`: kotlin.String?, - var `insecureSkipVerify`: kotlin.Boolean, - var `alpnProtocols`: List, - var `enableKeyLog`: kotlin.Boolean -) { - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypeMqttTlsOptionsFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): MqttTlsOptionsFfi { - return MqttTlsOptionsFfi( - FfiConverterOptionalString.read(buf), - FfiConverterOptionalString.read(buf), - FfiConverterOptionalString.read(buf), - FfiConverterBoolean.read(buf), - FfiConverterSequenceString.read(buf), - FfiConverterBoolean.read(buf), - ) - } - - override fun allocationSize(value: MqttTlsOptionsFfi) = ( - FfiConverterOptionalString.allocationSize(value.`caCertFile`) + - FfiConverterOptionalString.allocationSize(value.`clientCertFile`) + - FfiConverterOptionalString.allocationSize(value.`clientKeyFile`) + - FfiConverterBoolean.allocationSize(value.`insecureSkipVerify`) + - FfiConverterSequenceString.allocationSize(value.`alpnProtocols`) + - FfiConverterBoolean.allocationSize(value.`enableKeyLog`) - ) - - override fun write(value: MqttTlsOptionsFfi, buf: ByteBuffer) { - FfiConverterOptionalString.write(value.`caCertFile`, buf) - FfiConverterOptionalString.write(value.`clientCertFile`, buf) - FfiConverterOptionalString.write(value.`clientKeyFile`, buf) - FfiConverterBoolean.write(value.`insecureSkipVerify`, buf) - FfiConverterSequenceString.write(value.`alpnProtocols`, buf) - FfiConverterBoolean.write(value.`enableKeyLog`, buf) - } -} - - - -data class PublishResultFfi ( - var `packetId`: kotlin.UShort?, - var `reasonCode`: kotlin.UByte?, - var `qos`: kotlin.UByte -) { - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypePublishResultFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): PublishResultFfi { - return PublishResultFfi( - FfiConverterOptionalUShort.read(buf), - FfiConverterOptionalUByte.read(buf), - FfiConverterUByte.read(buf), - ) - } - - override fun allocationSize(value: PublishResultFfi) = ( - FfiConverterOptionalUShort.allocationSize(value.`packetId`) + - FfiConverterOptionalUByte.allocationSize(value.`reasonCode`) + - FfiConverterUByte.allocationSize(value.`qos`) - ) - - override fun write(value: PublishResultFfi, buf: ByteBuffer) { - FfiConverterOptionalUShort.write(value.`packetId`, buf) - FfiConverterOptionalUByte.write(value.`reasonCode`, buf) - FfiConverterUByte.write(value.`qos`, buf) - } -} - - - -data class SubscribeResultFfi ( - var `packetId`: kotlin.UShort, - var `reasonCodes`: kotlin.ByteArray -) { - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypeSubscribeResultFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): SubscribeResultFfi { - return SubscribeResultFfi( - FfiConverterUShort.read(buf), - FfiConverterByteArray.read(buf), - ) - } - - override fun allocationSize(value: SubscribeResultFfi) = ( - FfiConverterUShort.allocationSize(value.`packetId`) + - FfiConverterByteArray.allocationSize(value.`reasonCodes`) - ) - - override fun write(value: SubscribeResultFfi, buf: ByteBuffer) { - FfiConverterUShort.write(value.`packetId`, buf) - FfiConverterByteArray.write(value.`reasonCodes`, buf) - } -} - - - -data class UnsubscribeResultFfi ( - var `packetId`: kotlin.UShort, - var `reasonCodes`: kotlin.ByteArray -) { - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypeUnsubscribeResultFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): UnsubscribeResultFfi { - return UnsubscribeResultFfi( - FfiConverterUShort.read(buf), - FfiConverterByteArray.read(buf), - ) - } - - override fun allocationSize(value: UnsubscribeResultFfi) = ( - FfiConverterUShort.allocationSize(value.`packetId`) + - FfiConverterByteArray.allocationSize(value.`reasonCodes`) - ) - - override fun write(value: UnsubscribeResultFfi, buf: ByteBuffer) { - FfiConverterUShort.write(value.`packetId`, buf) - FfiConverterByteArray.write(value.`reasonCodes`, buf) - } -} - - - -sealed class MqttEventFfi { - - data class Connected( - val v1: ConnectionResultFfi) : MqttEventFfi() { - companion object - } - - data class Disconnected( - val `reasonCode`: kotlin.UByte?) : MqttEventFfi() { - companion object - } - - data class MessageReceived( - val v1: MqttMessageFfi) : MqttEventFfi() { - companion object - } - - data class Published( - val v1: PublishResultFfi) : MqttEventFfi() { - companion object - } - - data class Subscribed( - val v1: SubscribeResultFfi) : MqttEventFfi() { - companion object - } - - data class Unsubscribed( - val v1: UnsubscribeResultFfi) : MqttEventFfi() { - companion object - } - - data class PingResponse( - val `success`: kotlin.Boolean) : MqttEventFfi() { - companion object - } - - data class Error( - val `message`: kotlin.String) : MqttEventFfi() { - companion object - } - - object ReconnectNeeded : MqttEventFfi() - - - data class ReconnectScheduled( - val `attempt`: kotlin.UInt, - val `delayMs`: kotlin.ULong) : MqttEventFfi() { - companion object - } - - - - companion object -} - -/** - * @suppress - */ -public object FfiConverterTypeMqttEventFFI : FfiConverterRustBuffer{ - override fun read(buf: ByteBuffer): MqttEventFfi { - return when(buf.getInt()) { - 1 -> MqttEventFfi.Connected( - FfiConverterTypeConnectionResultFFI.read(buf), - ) - 2 -> MqttEventFfi.Disconnected( - FfiConverterOptionalUByte.read(buf), - ) - 3 -> MqttEventFfi.MessageReceived( - FfiConverterTypeMqttMessageFFI.read(buf), - ) - 4 -> MqttEventFfi.Published( - FfiConverterTypePublishResultFFI.read(buf), - ) - 5 -> MqttEventFfi.Subscribed( - FfiConverterTypeSubscribeResultFFI.read(buf), - ) - 6 -> MqttEventFfi.Unsubscribed( - FfiConverterTypeUnsubscribeResultFFI.read(buf), - ) - 7 -> MqttEventFfi.PingResponse( - FfiConverterBoolean.read(buf), - ) - 8 -> MqttEventFfi.Error( - FfiConverterString.read(buf), - ) - 9 -> MqttEventFfi.ReconnectNeeded - 10 -> MqttEventFfi.ReconnectScheduled( - FfiConverterUInt.read(buf), - FfiConverterULong.read(buf), - ) - else -> throw RuntimeException("invalid enum value, something is very wrong!!") - } - } - - override fun allocationSize(value: MqttEventFfi) = when(value) { - is MqttEventFfi.Connected -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterTypeConnectionResultFFI.allocationSize(value.v1) - ) - } - is MqttEventFfi.Disconnected -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterOptionalUByte.allocationSize(value.`reasonCode`) - ) - } - is MqttEventFfi.MessageReceived -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterTypeMqttMessageFFI.allocationSize(value.v1) - ) - } - is MqttEventFfi.Published -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterTypePublishResultFFI.allocationSize(value.v1) - ) - } - is MqttEventFfi.Subscribed -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterTypeSubscribeResultFFI.allocationSize(value.v1) - ) - } - is MqttEventFfi.Unsubscribed -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterTypeUnsubscribeResultFFI.allocationSize(value.v1) - ) - } - is MqttEventFfi.PingResponse -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterBoolean.allocationSize(value.`success`) - ) - } - is MqttEventFfi.Error -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterString.allocationSize(value.`message`) - ) - } - is MqttEventFfi.ReconnectNeeded -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - ) - } - is MqttEventFfi.ReconnectScheduled -> { - // Add the size for the Int that specifies the variant plus the size needed for all fields - ( - 4UL - + FfiConverterUInt.allocationSize(value.`attempt`) - + FfiConverterULong.allocationSize(value.`delayMs`) - ) - } - } - - override fun write(value: MqttEventFfi, buf: ByteBuffer) { - when(value) { - is MqttEventFfi.Connected -> { - buf.putInt(1) - FfiConverterTypeConnectionResultFFI.write(value.v1, buf) - Unit - } - is MqttEventFfi.Disconnected -> { - buf.putInt(2) - FfiConverterOptionalUByte.write(value.`reasonCode`, buf) - Unit - } - is MqttEventFfi.MessageReceived -> { - buf.putInt(3) - FfiConverterTypeMqttMessageFFI.write(value.v1, buf) - Unit - } - is MqttEventFfi.Published -> { - buf.putInt(4) - FfiConverterTypePublishResultFFI.write(value.v1, buf) - Unit - } - is MqttEventFfi.Subscribed -> { - buf.putInt(5) - FfiConverterTypeSubscribeResultFFI.write(value.v1, buf) - Unit - } - is MqttEventFfi.Unsubscribed -> { - buf.putInt(6) - FfiConverterTypeUnsubscribeResultFFI.write(value.v1, buf) - Unit - } - is MqttEventFfi.PingResponse -> { - buf.putInt(7) - FfiConverterBoolean.write(value.`success`, buf) - Unit - } - is MqttEventFfi.Error -> { - buf.putInt(8) - FfiConverterString.write(value.`message`, buf) - Unit - } - is MqttEventFfi.ReconnectNeeded -> { - buf.putInt(9) - Unit - } - is MqttEventFfi.ReconnectScheduled -> { - buf.putInt(10) - FfiConverterUInt.write(value.`attempt`, buf) - FfiConverterULong.write(value.`delayMs`, buf) - Unit - } - }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } - } -} - - - - - - -/** - * @suppress - */ -public object FfiConverterOptionalUByte: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): kotlin.UByte? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterUByte.read(buf) - } - - override fun allocationSize(value: kotlin.UByte?): ULong { - if (value == null) { - return 1UL - } else { - return 1UL + FfiConverterUByte.allocationSize(value) - } - } - - override fun write(value: kotlin.UByte?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterUByte.write(value, buf) - } - } -} - - - - -/** - * @suppress - */ -public object FfiConverterOptionalUShort: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): kotlin.UShort? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterUShort.read(buf) - } - - override fun allocationSize(value: kotlin.UShort?): ULong { - if (value == null) { - return 1UL - } else { - return 1UL + FfiConverterUShort.allocationSize(value) - } - } - - override fun write(value: kotlin.UShort?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterUShort.write(value, buf) - } - } -} - - - - -/** - * @suppress - */ -public object FfiConverterOptionalString: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): kotlin.String? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterString.read(buf) - } - - override fun allocationSize(value: kotlin.String?): ULong { - if (value == null) { - return 1UL - } else { - return 1UL + FfiConverterString.allocationSize(value) - } - } - - override fun write(value: kotlin.String?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterString.write(value, buf) - } - } -} - - - - -/** - * @suppress - */ -public object FfiConverterOptionalTypeMqttEventFFI: FfiConverterRustBuffer { - override fun read(buf: ByteBuffer): MqttEventFfi? { - if (buf.get().toInt() == 0) { - return null - } - return FfiConverterTypeMqttEventFFI.read(buf) - } - - override fun allocationSize(value: MqttEventFfi?): ULong { - if (value == null) { - return 1UL - } else { - return 1UL + FfiConverterTypeMqttEventFFI.allocationSize(value) - } - } - - override fun write(value: MqttEventFfi?, buf: ByteBuffer) { - if (value == null) { - buf.put(0) - } else { - buf.put(1) - FfiConverterTypeMqttEventFFI.write(value, buf) - } - } -} - - - - -/** - * @suppress - */ -public object FfiConverterSequenceString: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterString.read(buf) - } - } - - override fun allocationSize(value: List): ULong { - val sizeForLength = 4UL - val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.iterator().forEach { - FfiConverterString.write(it, buf) - } - } -} - - - - -/** - * @suppress - */ -public object FfiConverterSequenceTypeMqttDatagramFFI: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterTypeMqttDatagramFFI.read(buf) - } - } - - override fun allocationSize(value: List): ULong { - val sizeForLength = 4UL - val sizeForItems = value.map { FfiConverterTypeMqttDatagramFFI.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.iterator().forEach { - FfiConverterTypeMqttDatagramFFI.write(it, buf) - } - } -} - - - - -/** - * @suppress - */ -public object FfiConverterSequenceTypeMqttEventFFI: FfiConverterRustBuffer> { - override fun read(buf: ByteBuffer): List { - val len = buf.getInt() - return List(len) { - FfiConverterTypeMqttEventFFI.read(buf) - } - } - - override fun allocationSize(value: List): ULong { - val sizeForLength = 4UL - val sizeForItems = value.map { FfiConverterTypeMqttEventFFI.allocationSize(it) }.sum() - return sizeForLength + sizeForItems - } - - override fun write(value: List, buf: ByteBuffer) { - buf.putInt(value.size) - value.iterator().forEach { - FfiConverterTypeMqttEventFFI.write(it, buf) - } - } -} - diff --git a/scripts/build_swift_bindings.sh b/scripts/build_swift_bindings.sh index f8695ce2..6994e318 100755 --- a/scripts/build_swift_bindings.sh +++ b/scripts/build_swift_bindings.sh @@ -5,6 +5,7 @@ set -e PROFILE="debug" CARGO_PROFILE="dev" TARGET_DIR="target/debug" +COVERAGE=false if [[ "$1" == "--release" ]]; then PROFILE="release" @@ -13,6 +14,11 @@ if [[ "$1" == "--release" ]]; then shift fi +if [[ "$1" == "--coverage" ]]; then + COVERAGE=true + shift +fi + REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$REPO_ROOT" @@ -24,6 +30,11 @@ SWIFT_TARGET="swift/Sources/FlowSDK" SWIFT_LIB_DIR="swift/lib" echo "Building flowsdk_ffi ($PROFILE)..." +if [[ "$COVERAGE" == true ]]; then + mkdir -p target/llvm-cov-target + export RUSTFLAGS="-C instrument-coverage" + export LLVM_PROFILE_FILE="$PWD/target/llvm-cov-target/swift-%p-%m.profraw" +fi cargo build -p flowsdk_ffi --profile "$CARGO_PROFILE" --features quic echo "Generating Swift bindings..." @@ -108,4 +119,9 @@ if [[ "$1" == "--test" ]]; then LIBRARY_PATH="$PWD/$SWIFT_LIB_DIR" swift build --package-path swift fi +if [[ "$COVERAGE" == true ]]; then + echo "Running TcpClientExample to collect coverage data..." + LIBRARY_PATH="$PWD/$SWIFT_LIB_DIR" timeout 5s swift run --package-path swift TcpClientExample broker.emqx.io 1883 || true +fi + echo "Done!" diff --git a/swift/Sources/FlowSDK/flowsdk_ffi.swift b/swift/Sources/FlowSDK/flowsdk_ffi.swift deleted file mode 100644 index acf53e63..00000000 --- a/swift/Sources/FlowSDK/flowsdk_ffi.swift +++ /dev/null @@ -1,2537 +0,0 @@ -// This file was autogenerated by some hot garbage in the `uniffi` crate. -// Trust me, you don't want to mess with it! - -// swiftlint:disable all -import Foundation - -// Depending on the consumer's build setup, the low-level FFI code -// might be in a separate module, or it might be compiled inline into -// this module. This is a bit of light hackery to work with both. -#if canImport(flowsdk_ffi) -import flowsdk_ffi -#endif - -fileprivate extension RustBuffer { - // Allocate a new buffer, copying the contents of a `UInt8` array. - init(bytes: [UInt8]) { - let rbuf = bytes.withUnsafeBufferPointer { ptr in - RustBuffer.from(ptr) - } - self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) - } - - static func empty() -> RustBuffer { - RustBuffer(capacity: 0, len:0, data: nil) - } - - static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { - try! rustCall { ffi_flowsdk_ffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } - } - - // Frees the buffer in place. - // The buffer must not be used after this is called. - func deallocate() { - try! rustCall { ffi_flowsdk_ffi_rustbuffer_free(self, $0) } - } -} - -fileprivate extension ForeignBytes { - init(bufferPointer: UnsafeBufferPointer) { - self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) - } -} - -// For every type used in the interface, we provide helper methods for conveniently -// lifting and lowering that type from C-compatible data, and for reading and writing -// values of that type in a buffer. - -// Helper classes/extensions that don't change. -// Someday, this will be in a library of its own. - -fileprivate extension Data { - init(rustBuffer: RustBuffer) { - self.init( - bytesNoCopy: rustBuffer.data!, - count: Int(rustBuffer.len), - deallocator: .none - ) - } -} - -// Define reader functionality. Normally this would be defined in a class or -// struct, but we use standalone functions instead in order to make external -// types work. -// -// With external types, one swift source file needs to be able to call the read -// method on another source file's FfiConverter, but then what visibility -// should Reader have? -// - If Reader is fileprivate, then this means the read() must also -// be fileprivate, which doesn't work with external types. -// - If Reader is internal/public, we'll get compile errors since both source -// files will try define the same type. -// -// Instead, the read() method and these helper functions input a tuple of data - -fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) { - (data: data, offset: 0) -} - -// Reads an integer at the current offset, in big-endian order, and advances -// the offset on success. Throws if reading the integer would move the -// offset past the end of the buffer. -fileprivate func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { - let range = reader.offset...size - guard reader.data.count >= range.upperBound else { - throw UniffiInternalError.bufferOverflow - } - if T.self == UInt8.self { - let value = reader.data[reader.offset] - reader.offset += 1 - return value as! T - } - var value: T = 0 - let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)}) - reader.offset = range.upperBound - return value.bigEndian -} - -// Reads an arbitrary number of bytes, to be used to read -// raw bytes, this is useful when lifting strings -fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array { - let range = reader.offset..<(reader.offset+count) - guard reader.data.count >= range.upperBound else { - throw UniffiInternalError.bufferOverflow - } - var value = [UInt8](repeating: 0, count: count) - value.withUnsafeMutableBufferPointer({ buffer in - reader.data.copyBytes(to: buffer, from: range) - }) - reader.offset = range.upperBound - return value -} - -// Reads a float at the current offset. -fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { - return Float(bitPattern: try readInt(&reader)) -} - -// Reads a float at the current offset. -fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { - return Double(bitPattern: try readInt(&reader)) -} - -// Indicates if the offset has reached the end of the buffer. -fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { - return reader.offset < reader.data.count -} - -// Define writer functionality. Normally this would be defined in a class or -// struct, but we use standalone functions instead in order to make external -// types work. See the above discussion on Readers for details. - -fileprivate func createWriter() -> [UInt8] { - return [] -} - -fileprivate func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { - writer.append(contentsOf: byteArr) -} - -// Writes an integer in big-endian order. -// -// Warning: make sure what you are trying to write -// is in the correct type! -fileprivate func writeInt(_ writer: inout [UInt8], _ value: T) { - var value = value.bigEndian - withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } -} - -fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) { - writeInt(&writer, value.bitPattern) -} - -fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) { - writeInt(&writer, value.bitPattern) -} - -// Protocol for types that transfer other types across the FFI. This is -// analogous to the Rust trait of the same name. -fileprivate protocol FfiConverter { - associatedtype FfiType - associatedtype SwiftType - - static func lift(_ value: FfiType) throws -> SwiftType - static func lower(_ value: SwiftType) -> FfiType - static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType - static func write(_ value: SwiftType, into buf: inout [UInt8]) -} - -// Types conforming to `Primitive` pass themselves directly over the FFI. -fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { } - -extension FfiConverterPrimitive { -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public static func lift(_ value: FfiType) throws -> SwiftType { - return value - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public static func lower(_ value: SwiftType) -> FfiType { - return value - } -} - -// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. -// Used for complex types where it's hard to write a custom lift/lower. -fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} - -extension FfiConverterRustBuffer { -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public static func lift(_ buf: RustBuffer) throws -> SwiftType { - var reader = createReader(data: Data(rustBuffer: buf)) - let value = try read(from: &reader) - if hasRemaining(reader) { - throw UniffiInternalError.incompleteData - } - buf.deallocate() - return value - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public static func lower(_ value: SwiftType) -> RustBuffer { - var writer = createWriter() - write(value, into: &writer) - return RustBuffer(bytes: writer) - } -} -// An error type for FFI errors. These errors occur at the UniFFI level, not -// the library level. -fileprivate enum UniffiInternalError: LocalizedError { - case bufferOverflow - case incompleteData - case unexpectedOptionalTag - case unexpectedEnumCase - case unexpectedNullPointer - case unexpectedRustCallStatusCode - case unexpectedRustCallError - case unexpectedStaleHandle - case rustPanic(_ message: String) - - public var errorDescription: String? { - switch self { - case .bufferOverflow: return "Reading the requested value would read past the end of the buffer" - case .incompleteData: return "The buffer still has data after lifting its containing value" - case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1" - case .unexpectedEnumCase: return "Raw enum value doesn't match any cases" - case .unexpectedNullPointer: return "Raw pointer value was null" - case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code" - case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified" - case .unexpectedStaleHandle: return "The object in the handle map has been dropped already" - case let .rustPanic(message): return message - } - } -} - -fileprivate extension NSLock { - func withLock(f: () throws -> T) rethrows -> T { - self.lock() - defer { self.unlock() } - return try f() - } -} - -fileprivate let CALL_SUCCESS: Int8 = 0 -fileprivate let CALL_ERROR: Int8 = 1 -fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2 -fileprivate let CALL_CANCELLED: Int8 = 3 - -fileprivate extension RustCallStatus { - init() { - self.init( - code: CALL_SUCCESS, - errorBuf: RustBuffer.init( - capacity: 0, - len: 0, - data: nil - ) - ) - } -} - -private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { - let neverThrow: ((RustBuffer) throws -> Never)? = nil - return try makeRustCall(callback, errorHandler: neverThrow) -} - -private func rustCallWithError( - _ errorHandler: @escaping (RustBuffer) throws -> E, - _ callback: (UnsafeMutablePointer) -> T) throws -> T { - try makeRustCall(callback, errorHandler: errorHandler) -} - -private func makeRustCall( - _ callback: (UnsafeMutablePointer) -> T, - errorHandler: ((RustBuffer) throws -> E)? -) throws -> T { - uniffiEnsureInitialized() - var callStatus = RustCallStatus.init() - let returnedVal = callback(&callStatus) - try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) - return returnedVal -} - -private func uniffiCheckCallStatus( - callStatus: RustCallStatus, - errorHandler: ((RustBuffer) throws -> E)? -) throws { - switch callStatus.code { - case CALL_SUCCESS: - return - - case CALL_ERROR: - if let errorHandler = errorHandler { - throw try errorHandler(callStatus.errorBuf) - } else { - callStatus.errorBuf.deallocate() - throw UniffiInternalError.unexpectedRustCallError - } - - case CALL_UNEXPECTED_ERROR: - // When the rust code sees a panic, it tries to construct a RustBuffer - // with the message. But if that code panics, then it just sends back - // an empty buffer. - if callStatus.errorBuf.len > 0 { - throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) - } else { - callStatus.errorBuf.deallocate() - throw UniffiInternalError.rustPanic("Rust panic") - } - - case CALL_CANCELLED: - fatalError("Cancellation not supported yet") - - default: - throw UniffiInternalError.unexpectedRustCallStatusCode - } -} - -private func uniffiTraitInterfaceCall( - callStatus: UnsafeMutablePointer, - makeCall: () throws -> T, - writeReturn: (T) -> () -) { - do { - try writeReturn(makeCall()) - } catch let error { - callStatus.pointee.code = CALL_UNEXPECTED_ERROR - callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) - } -} - -private func uniffiTraitInterfaceCallWithError( - callStatus: UnsafeMutablePointer, - makeCall: () throws -> T, - writeReturn: (T) -> (), - lowerError: (E) -> RustBuffer -) { - do { - try writeReturn(makeCall()) - } catch let error as E { - callStatus.pointee.code = CALL_ERROR - callStatus.pointee.errorBuf = lowerError(error) - } catch { - callStatus.pointee.code = CALL_UNEXPECTED_ERROR - callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) - } -} -fileprivate class UniffiHandleMap { - private var map: [UInt64: T] = [:] - private let lock = NSLock() - private var currentHandle: UInt64 = 1 - - func insert(obj: T) -> UInt64 { - lock.withLock { - let handle = currentHandle - currentHandle += 1 - map[handle] = obj - return handle - } - } - - func get(handle: UInt64) throws -> T { - try lock.withLock { - guard let obj = map[handle] else { - throw UniffiInternalError.unexpectedStaleHandle - } - return obj - } - } - - @discardableResult - func remove(handle: UInt64) throws -> T { - try lock.withLock { - guard let obj = map.removeValue(forKey: handle) else { - throw UniffiInternalError.unexpectedStaleHandle - } - return obj - } - } - - var count: Int { - get { - map.count - } - } -} - - -// Public interface members begin here. - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterUInt8: FfiConverterPrimitive { - typealias FfiType = UInt8 - typealias SwiftType = UInt8 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: UInt8, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterUInt16: FfiConverterPrimitive { - typealias FfiType = UInt16 - typealias SwiftType = UInt16 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt16 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterUInt32: FfiConverterPrimitive { - typealias FfiType = UInt32 - typealias SwiftType = UInt32 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterInt32: FfiConverterPrimitive { - typealias FfiType = Int32 - typealias SwiftType = Int32 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int32 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: Int32, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { - typealias FfiType = UInt64 - typealias SwiftType = UInt64 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterInt64: FfiConverterPrimitive { - typealias FfiType = Int64 - typealias SwiftType = Int64 - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int64 { - return try lift(readInt(&buf)) - } - - public static func write(_ value: Int64, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterBool : FfiConverter { - typealias FfiType = Int8 - typealias SwiftType = Bool - - public static func lift(_ value: Int8) throws -> Bool { - return value != 0 - } - - public static func lower(_ value: Bool) -> Int8 { - return value ? 1 : 0 - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { - return try lift(readInt(&buf)) - } - - public static func write(_ value: Bool, into buf: inout [UInt8]) { - writeInt(&buf, lower(value)) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterString: FfiConverter { - typealias SwiftType = String - typealias FfiType = RustBuffer - - public static func lift(_ value: RustBuffer) throws -> String { - defer { - value.deallocate() - } - if value.data == nil { - return String() - } - let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) - return String(bytes: bytes, encoding: String.Encoding.utf8)! - } - - public static func lower(_ value: String) -> RustBuffer { - return value.utf8CString.withUnsafeBufferPointer { ptr in - // The swift string gives us int8_t, we want uint8_t. - ptr.withMemoryRebound(to: UInt8.self) { ptr in - // The swift string gives us a trailing null byte, we don't want it. - let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) - return RustBuffer.from(buf) - } - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { - let len: Int32 = try readInt(&buf) - return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! - } - - public static func write(_ value: String, into buf: inout [UInt8]) { - let len = Int32(value.utf8.count) - writeInt(&buf, len) - writeBytes(&buf, value.utf8) - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterData: FfiConverterRustBuffer { - typealias SwiftType = Data - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data { - let len: Int32 = try readInt(&buf) - return Data(try readBytes(&buf, count: Int(len))) - } - - public static func write(_ value: Data, into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - writeBytes(&buf, value) - } -} - - - - -public protocol MqttEngineFfiProtocol : AnyObject { - - func auth(reasonCode: UInt8) - - func connect() - - func disconnect() - - func getVersion() -> UInt8 - - func handleConnectionLost() - - func handleIncoming(data: Data) -> [MqttEventFfi] - - func handleTick(nowMs: UInt64) -> [MqttEventFfi] - - func isConnected() -> Bool - - func nextTickMs() -> Int64 - - func publish(topic: String, payload: Data, qos: UInt8, priority: UInt8?) -> Int32 - - func pushEventFfi(event: MqttEventFfi) - - func subscribe(topicFilter: String, qos: UInt8) -> Int32 - - func takeEvents() -> [MqttEventFfi] - - func takeOutgoing() -> Data - - func unsubscribe(topicFilter: String) -> Int32 - -} - -open class MqttEngineFfi: - MqttEngineFfiProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - // This constructor can be used to instantiate a fake object. - // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - // - // - Warning: - // 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. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public init(noPointer: NoPointer) { - self.pointer = nil - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_flowsdk_ffi_fn_clone_mqttengineffi(self.pointer, $0) } - } -public convenience init(clientId: String?, mqttVersion: UInt8) { - let pointer = - try! rustCall() { - uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new( - FfiConverterOptionString.lower(clientId), - FfiConverterUInt8.lower(mqttVersion),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_flowsdk_ffi_fn_free_mqttengineffi(pointer, $0) } - } - - -public static func newWithOpts(opts: MqttOptionsFfi) -> MqttEngineFfi { - return try! FfiConverterTypeMqttEngineFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new_with_opts( - FfiConverterTypeMqttOptionsFFI.lower(opts),$0 - ) -}) -} - - - -open func auth(reasonCode: UInt8) {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_auth(self.uniffiClonePointer(), - FfiConverterUInt8.lower(reasonCode),$0 - ) -} -} - -open func connect() {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_connect(self.uniffiClonePointer(),$0 - ) -} -} - -open func disconnect() {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_disconnect(self.uniffiClonePointer(),$0 - ) -} -} - -open func getVersion() -> UInt8 { - return try! FfiConverterUInt8.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_get_version(self.uniffiClonePointer(),$0 - ) -}) -} - -open func handleConnectionLost() {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_connection_lost(self.uniffiClonePointer(),$0 - ) -} -} - -open func handleIncoming(data: Data) -> [MqttEventFfi] { - return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_incoming(self.uniffiClonePointer(), - FfiConverterData.lower(data),$0 - ) -}) -} - -open func handleTick(nowMs: UInt64) -> [MqttEventFfi] { - return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_tick(self.uniffiClonePointer(), - FfiConverterUInt64.lower(nowMs),$0 - ) -}) -} - -open func isConnected() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_is_connected(self.uniffiClonePointer(),$0 - ) -}) -} - -open func nextTickMs() -> Int64 { - return try! FfiConverterInt64.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_next_tick_ms(self.uniffiClonePointer(),$0 - ) -}) -} - -open func publish(topic: String, payload: Data, qos: UInt8, priority: UInt8?) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_publish(self.uniffiClonePointer(), - FfiConverterString.lower(topic), - FfiConverterData.lower(payload), - FfiConverterUInt8.lower(qos), - FfiConverterOptionUInt8.lower(priority),$0 - ) -}) -} - -open func pushEventFfi(event: MqttEventFfi) {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_push_event_ffi(self.uniffiClonePointer(), - FfiConverterTypeMqttEventFFI.lower(event),$0 - ) -} -} - -open func subscribe(topicFilter: String, qos: UInt8) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_subscribe(self.uniffiClonePointer(), - FfiConverterString.lower(topicFilter), - FfiConverterUInt8.lower(qos),$0 - ) -}) -} - -open func takeEvents() -> [MqttEventFfi] { - return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_events(self.uniffiClonePointer(),$0 - ) -}) -} - -open func takeOutgoing() -> Data { - return try! FfiConverterData.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_outgoing(self.uniffiClonePointer(),$0 - ) -}) -} - -open func unsubscribe(topicFilter: String) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqttengineffi_unsubscribe(self.uniffiClonePointer(), - FfiConverterString.lower(topicFilter),$0 - ) -}) -} - - -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeMqttEngineFFI: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = MqttEngineFfi - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MqttEngineFfi { - return MqttEngineFfi(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: MqttEngineFfi) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttEngineFfi { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: MqttEngineFfi, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttEngineFFI_lift(_ pointer: UnsafeMutableRawPointer) throws -> MqttEngineFfi { - return try FfiConverterTypeMqttEngineFFI.lift(pointer) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttEngineFFI_lower(_ value: MqttEngineFfi) -> UnsafeMutableRawPointer { - return FfiConverterTypeMqttEngineFFI.lower(value) -} - - - - -public protocol MqttEventListFfiProtocol : AnyObject { - - func get(index: UInt32) -> MqttEventFfi? - - func isEmpty() -> Bool - - func len() -> UInt32 - -} - -open class MqttEventListFfi: - MqttEventListFfiProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - // This constructor can be used to instantiate a fake object. - // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - // - // - Warning: - // 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. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public init(noPointer: NoPointer) { - self.pointer = nil - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_flowsdk_ffi_fn_clone_mqtteventlistffi(self.pointer, $0) } - } - // No primary constructor declared for this class. - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_flowsdk_ffi_fn_free_mqtteventlistffi(pointer, $0) } - } - - - - -open func get(index: UInt32) -> MqttEventFfi? { - return try! FfiConverterOptionTypeMqttEventFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_get(self.uniffiClonePointer(), - FfiConverterUInt32.lower(index),$0 - ) -}) -} - -open func isEmpty() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_is_empty(self.uniffiClonePointer(),$0 - ) -}) -} - -open func len() -> UInt32 { - return try! FfiConverterUInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_len(self.uniffiClonePointer(),$0 - ) -}) -} - - -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeMqttEventListFFI: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = MqttEventListFfi - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MqttEventListFfi { - return MqttEventListFfi(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: MqttEventListFfi) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttEventListFfi { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: MqttEventListFfi, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttEventListFFI_lift(_ pointer: UnsafeMutableRawPointer) throws -> MqttEventListFfi { - return try FfiConverterTypeMqttEventListFFI.lift(pointer) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttEventListFFI_lower(_ value: MqttEventListFfi) -> UnsafeMutableRawPointer { - return FfiConverterTypeMqttEventListFFI.lower(value) -} - - - - -public protocol QuicMqttEngineFfiProtocol : AnyObject { - - func connect(serverAddr: String, serverName: String, tlsOpts: MqttTlsOptionsFfi, nowMs: UInt64) - - func disconnect() - - func handleDatagram(data: Data, remoteAddr: String, nowMs: UInt64) - - func handleTick(nowMs: UInt64) -> [MqttEventFfi] - - func isConnected() -> Bool - - func publish(topic: String, payload: Data, qos: UInt8) -> Int32 - - func subscribe(topicFilter: String, qos: UInt8) -> Int32 - - func takeEvents() -> [MqttEventFfi] - - func takeOutgoingDatagrams() -> [MqttDatagramFfi] - - func unsubscribe(topicFilter: String) -> Int32 - -} - -open class QuicMqttEngineFfi: - QuicMqttEngineFfiProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - // This constructor can be used to instantiate a fake object. - // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - // - // - Warning: - // 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. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public init(noPointer: NoPointer) { - self.pointer = nil - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_flowsdk_ffi_fn_clone_quicmqttengineffi(self.pointer, $0) } - } -public convenience init(opts: MqttOptionsFfi) { - let pointer = - try! rustCall() { - uniffi_flowsdk_ffi_fn_constructor_quicmqttengineffi_new( - FfiConverterTypeMqttOptionsFFI.lower(opts),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_flowsdk_ffi_fn_free_quicmqttengineffi(pointer, $0) } - } - - - - -open func connect(serverAddr: String, serverName: String, tlsOpts: MqttTlsOptionsFfi, nowMs: UInt64) {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_connect(self.uniffiClonePointer(), - FfiConverterString.lower(serverAddr), - FfiConverterString.lower(serverName), - FfiConverterTypeMqttTlsOptionsFFI.lower(tlsOpts), - FfiConverterUInt64.lower(nowMs),$0 - ) -} -} - -open func disconnect() {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_disconnect(self.uniffiClonePointer(),$0 - ) -} -} - -open func handleDatagram(data: Data, remoteAddr: String, nowMs: UInt64) {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_datagram(self.uniffiClonePointer(), - FfiConverterData.lower(data), - FfiConverterString.lower(remoteAddr), - FfiConverterUInt64.lower(nowMs),$0 - ) -} -} - -open func handleTick(nowMs: UInt64) -> [MqttEventFfi] { - return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_tick(self.uniffiClonePointer(), - FfiConverterUInt64.lower(nowMs),$0 - ) -}) -} - -open func isConnected() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_is_connected(self.uniffiClonePointer(),$0 - ) -}) -} - -open func publish(topic: String, payload: Data, qos: UInt8) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_publish(self.uniffiClonePointer(), - FfiConverterString.lower(topic), - FfiConverterData.lower(payload), - FfiConverterUInt8.lower(qos),$0 - ) -}) -} - -open func subscribe(topicFilter: String, qos: UInt8) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_subscribe(self.uniffiClonePointer(), - FfiConverterString.lower(topicFilter), - FfiConverterUInt8.lower(qos),$0 - ) -}) -} - -open func takeEvents() -> [MqttEventFfi] { - return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_events(self.uniffiClonePointer(),$0 - ) -}) -} - -open func takeOutgoingDatagrams() -> [MqttDatagramFfi] { - return try! FfiConverterSequenceTypeMqttDatagramFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_outgoing_datagrams(self.uniffiClonePointer(),$0 - ) -}) -} - -open func unsubscribe(topicFilter: String) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_unsubscribe(self.uniffiClonePointer(), - FfiConverterString.lower(topicFilter),$0 - ) -}) -} - - -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeQuicMqttEngineFFI: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = QuicMqttEngineFfi - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> QuicMqttEngineFfi { - return QuicMqttEngineFfi(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: QuicMqttEngineFfi) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> QuicMqttEngineFfi { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: QuicMqttEngineFfi, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeQuicMqttEngineFFI_lift(_ pointer: UnsafeMutableRawPointer) throws -> QuicMqttEngineFfi { - return try FfiConverterTypeQuicMqttEngineFFI.lift(pointer) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeQuicMqttEngineFFI_lower(_ value: QuicMqttEngineFfi) -> UnsafeMutableRawPointer { - return FfiConverterTypeQuicMqttEngineFFI.lower(value) -} - - - - -public protocol TlsMqttEngineFfiProtocol : AnyObject { - - func connect() - - func disconnect() - - func handleSocketData(data: Data) - - func handleTick(nowMs: UInt64) -> [MqttEventFfi] - - func isConnected() -> Bool - - func publish(topic: String, payload: Data, qos: UInt8) -> Int32 - - func subscribe(topicFilter: String, qos: UInt8) -> Int32 - - func takeEvents() -> [MqttEventFfi] - - func takeSocketData() -> Data - - func unsubscribe(topicFilter: String) -> Int32 - -} - -open class TlsMqttEngineFfi: - TlsMqttEngineFfiProtocol { - fileprivate let pointer: UnsafeMutableRawPointer! - - /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public struct NoPointer { - public init() {} - } - - // TODO: We'd like this to be `private` but for Swifty reasons, - // we can't implement `FfiConverter` without making this `required` and we can't - // make it `required` without making it `public`. - required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { - self.pointer = pointer - } - - // This constructor can be used to instantiate a fake object. - // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. - // - // - Warning: - // 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. -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public init(noPointer: NoPointer) { - self.pointer = nil - } - -#if swift(>=5.8) - @_documentation(visibility: private) -#endif - public func uniffiClonePointer() -> UnsafeMutableRawPointer { - return try! rustCall { uniffi_flowsdk_ffi_fn_clone_tlsmqttengineffi(self.pointer, $0) } - } -public convenience init(opts: MqttOptionsFfi, tlsOpts: MqttTlsOptionsFfi, serverName: String) { - let pointer = - try! rustCall() { - uniffi_flowsdk_ffi_fn_constructor_tlsmqttengineffi_new( - FfiConverterTypeMqttOptionsFFI.lower(opts), - FfiConverterTypeMqttTlsOptionsFFI.lower(tlsOpts), - FfiConverterString.lower(serverName),$0 - ) -} - self.init(unsafeFromRawPointer: pointer) -} - - deinit { - guard let pointer = pointer else { - return - } - - try! rustCall { uniffi_flowsdk_ffi_fn_free_tlsmqttengineffi(pointer, $0) } - } - - - - -open func connect() {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_connect(self.uniffiClonePointer(),$0 - ) -} -} - -open func disconnect() {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_disconnect(self.uniffiClonePointer(),$0 - ) -} -} - -open func handleSocketData(data: Data) {try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_socket_data(self.uniffiClonePointer(), - FfiConverterData.lower(data),$0 - ) -} -} - -open func handleTick(nowMs: UInt64) -> [MqttEventFfi] { - return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_tick(self.uniffiClonePointer(), - FfiConverterUInt64.lower(nowMs),$0 - ) -}) -} - -open func isConnected() -> Bool { - return try! FfiConverterBool.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_is_connected(self.uniffiClonePointer(),$0 - ) -}) -} - -open func publish(topic: String, payload: Data, qos: UInt8) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_publish(self.uniffiClonePointer(), - FfiConverterString.lower(topic), - FfiConverterData.lower(payload), - FfiConverterUInt8.lower(qos),$0 - ) -}) -} - -open func subscribe(topicFilter: String, qos: UInt8) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_subscribe(self.uniffiClonePointer(), - FfiConverterString.lower(topicFilter), - FfiConverterUInt8.lower(qos),$0 - ) -}) -} - -open func takeEvents() -> [MqttEventFfi] { - return try! FfiConverterSequenceTypeMqttEventFFI.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_events(self.uniffiClonePointer(),$0 - ) -}) -} - -open func takeSocketData() -> Data { - return try! FfiConverterData.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_socket_data(self.uniffiClonePointer(),$0 - ) -}) -} - -open func unsubscribe(topicFilter: String) -> Int32 { - return try! FfiConverterInt32.lift(try! rustCall() { - uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_unsubscribe(self.uniffiClonePointer(), - FfiConverterString.lower(topicFilter),$0 - ) -}) -} - - -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeTlsMqttEngineFFI: FfiConverter { - - typealias FfiType = UnsafeMutableRawPointer - typealias SwiftType = TlsMqttEngineFfi - - public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> TlsMqttEngineFfi { - return TlsMqttEngineFfi(unsafeFromRawPointer: pointer) - } - - public static func lower(_ value: TlsMqttEngineFfi) -> UnsafeMutableRawPointer { - return value.uniffiClonePointer() - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TlsMqttEngineFfi { - let v: UInt64 = try readInt(&buf) - // The Rust code won't compile if a pointer won't fit in a UInt64. - // We have to go via `UInt` because that's the thing that's the size of a pointer. - let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) - if (ptr == nil) { - throw UniffiInternalError.unexpectedNullPointer - } - return try lift(ptr!) - } - - public static func write(_ value: TlsMqttEngineFfi, into buf: inout [UInt8]) { - // This fiddling is because `Int` is the thing that's the same size as a pointer. - // The Rust code won't compile if a pointer won't fit in a `UInt64`. - writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) - } -} - - - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeTlsMqttEngineFFI_lift(_ pointer: UnsafeMutableRawPointer) throws -> TlsMqttEngineFfi { - return try FfiConverterTypeTlsMqttEngineFFI.lift(pointer) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeTlsMqttEngineFFI_lower(_ value: TlsMqttEngineFfi) -> UnsafeMutableRawPointer { - return FfiConverterTypeTlsMqttEngineFFI.lower(value) -} - - -public struct ConnectionResultFfi { - public var reasonCode: UInt8 - public var sessionPresent: Bool - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(reasonCode: UInt8, sessionPresent: Bool) { - self.reasonCode = reasonCode - self.sessionPresent = sessionPresent - } -} - - - -extension ConnectionResultFfi: Equatable, Hashable { - public static func ==(lhs: ConnectionResultFfi, rhs: ConnectionResultFfi) -> Bool { - if lhs.reasonCode != rhs.reasonCode { - return false - } - if lhs.sessionPresent != rhs.sessionPresent { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(reasonCode) - hasher.combine(sessionPresent) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeConnectionResultFFI: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ConnectionResultFfi { - return - try ConnectionResultFfi( - reasonCode: FfiConverterUInt8.read(from: &buf), - sessionPresent: FfiConverterBool.read(from: &buf) - ) - } - - public static func write(_ value: ConnectionResultFfi, into buf: inout [UInt8]) { - FfiConverterUInt8.write(value.reasonCode, into: &buf) - FfiConverterBool.write(value.sessionPresent, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeConnectionResultFFI_lift(_ buf: RustBuffer) throws -> ConnectionResultFfi { - return try FfiConverterTypeConnectionResultFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeConnectionResultFFI_lower(_ value: ConnectionResultFfi) -> RustBuffer { - return FfiConverterTypeConnectionResultFFI.lower(value) -} - - -public struct MqttDatagramFfi { - public var addr: String - public var data: Data - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(addr: String, data: Data) { - self.addr = addr - self.data = data - } -} - - - -extension MqttDatagramFfi: Equatable, Hashable { - public static func ==(lhs: MqttDatagramFfi, rhs: MqttDatagramFfi) -> Bool { - if lhs.addr != rhs.addr { - return false - } - if lhs.data != rhs.data { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(addr) - hasher.combine(data) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeMqttDatagramFFI: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttDatagramFfi { - return - try MqttDatagramFfi( - addr: FfiConverterString.read(from: &buf), - data: FfiConverterData.read(from: &buf) - ) - } - - public static func write(_ value: MqttDatagramFfi, into buf: inout [UInt8]) { - FfiConverterString.write(value.addr, into: &buf) - FfiConverterData.write(value.data, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttDatagramFFI_lift(_ buf: RustBuffer) throws -> MqttDatagramFfi { - return try FfiConverterTypeMqttDatagramFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttDatagramFFI_lower(_ value: MqttDatagramFfi) -> RustBuffer { - return FfiConverterTypeMqttDatagramFFI.lower(value) -} - - -public struct MqttMessageFfi { - public var topic: String - public var payload: Data - public var qos: UInt8 - public var retain: Bool - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(topic: String, payload: Data, qos: UInt8, retain: Bool) { - self.topic = topic - self.payload = payload - self.qos = qos - self.retain = retain - } -} - - - -extension MqttMessageFfi: Equatable, Hashable { - public static func ==(lhs: MqttMessageFfi, rhs: MqttMessageFfi) -> Bool { - if lhs.topic != rhs.topic { - return false - } - if lhs.payload != rhs.payload { - return false - } - if lhs.qos != rhs.qos { - return false - } - if lhs.retain != rhs.retain { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(topic) - hasher.combine(payload) - hasher.combine(qos) - hasher.combine(retain) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeMqttMessageFFI: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttMessageFfi { - return - try MqttMessageFfi( - topic: FfiConverterString.read(from: &buf), - payload: FfiConverterData.read(from: &buf), - qos: FfiConverterUInt8.read(from: &buf), - retain: FfiConverterBool.read(from: &buf) - ) - } - - public static func write(_ value: MqttMessageFfi, into buf: inout [UInt8]) { - FfiConverterString.write(value.topic, into: &buf) - FfiConverterData.write(value.payload, into: &buf) - FfiConverterUInt8.write(value.qos, into: &buf) - FfiConverterBool.write(value.retain, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttMessageFFI_lift(_ buf: RustBuffer) throws -> MqttMessageFfi { - return try FfiConverterTypeMqttMessageFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttMessageFFI_lower(_ value: MqttMessageFfi) -> RustBuffer { - return FfiConverterTypeMqttMessageFFI.lower(value) -} - - -public struct MqttOptionsFfi { - public var clientId: String - public var mqttVersion: UInt8 - public var cleanStart: Bool - public var keepAlive: UInt16 - public var username: String? - public var password: String? - public var reconnectBaseDelayMs: UInt64 - public var reconnectMaxDelayMs: UInt64 - public var maxReconnectAttempts: UInt32 - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(clientId: String, mqttVersion: UInt8, cleanStart: Bool, keepAlive: UInt16, username: String?, password: String?, reconnectBaseDelayMs: UInt64, reconnectMaxDelayMs: UInt64, maxReconnectAttempts: UInt32) { - self.clientId = clientId - self.mqttVersion = mqttVersion - self.cleanStart = cleanStart - self.keepAlive = keepAlive - self.username = username - self.password = password - self.reconnectBaseDelayMs = reconnectBaseDelayMs - self.reconnectMaxDelayMs = reconnectMaxDelayMs - self.maxReconnectAttempts = maxReconnectAttempts - } -} - - - -extension MqttOptionsFfi: Equatable, Hashable { - public static func ==(lhs: MqttOptionsFfi, rhs: MqttOptionsFfi) -> Bool { - if lhs.clientId != rhs.clientId { - return false - } - if lhs.mqttVersion != rhs.mqttVersion { - return false - } - if lhs.cleanStart != rhs.cleanStart { - return false - } - if lhs.keepAlive != rhs.keepAlive { - return false - } - if lhs.username != rhs.username { - return false - } - if lhs.password != rhs.password { - return false - } - if lhs.reconnectBaseDelayMs != rhs.reconnectBaseDelayMs { - return false - } - if lhs.reconnectMaxDelayMs != rhs.reconnectMaxDelayMs { - return false - } - if lhs.maxReconnectAttempts != rhs.maxReconnectAttempts { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(clientId) - hasher.combine(mqttVersion) - hasher.combine(cleanStart) - hasher.combine(keepAlive) - hasher.combine(username) - hasher.combine(password) - hasher.combine(reconnectBaseDelayMs) - hasher.combine(reconnectMaxDelayMs) - hasher.combine(maxReconnectAttempts) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeMqttOptionsFFI: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttOptionsFfi { - return - try MqttOptionsFfi( - clientId: FfiConverterString.read(from: &buf), - mqttVersion: FfiConverterUInt8.read(from: &buf), - cleanStart: FfiConverterBool.read(from: &buf), - keepAlive: FfiConverterUInt16.read(from: &buf), - username: FfiConverterOptionString.read(from: &buf), - password: FfiConverterOptionString.read(from: &buf), - reconnectBaseDelayMs: FfiConverterUInt64.read(from: &buf), - reconnectMaxDelayMs: FfiConverterUInt64.read(from: &buf), - maxReconnectAttempts: FfiConverterUInt32.read(from: &buf) - ) - } - - public static func write(_ value: MqttOptionsFfi, into buf: inout [UInt8]) { - FfiConverterString.write(value.clientId, into: &buf) - FfiConverterUInt8.write(value.mqttVersion, into: &buf) - FfiConverterBool.write(value.cleanStart, into: &buf) - FfiConverterUInt16.write(value.keepAlive, into: &buf) - FfiConverterOptionString.write(value.username, into: &buf) - FfiConverterOptionString.write(value.password, into: &buf) - FfiConverterUInt64.write(value.reconnectBaseDelayMs, into: &buf) - FfiConverterUInt64.write(value.reconnectMaxDelayMs, into: &buf) - FfiConverterUInt32.write(value.maxReconnectAttempts, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttOptionsFFI_lift(_ buf: RustBuffer) throws -> MqttOptionsFfi { - return try FfiConverterTypeMqttOptionsFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttOptionsFFI_lower(_ value: MqttOptionsFfi) -> RustBuffer { - return FfiConverterTypeMqttOptionsFFI.lower(value) -} - - -public struct MqttTlsOptionsFfi { - public var caCertFile: String? - public var clientCertFile: String? - public var clientKeyFile: String? - public var insecureSkipVerify: Bool - public var alpnProtocols: [String] - public var enableKeyLog: Bool - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(caCertFile: String?, clientCertFile: String?, clientKeyFile: String?, insecureSkipVerify: Bool, alpnProtocols: [String], enableKeyLog: Bool) { - self.caCertFile = caCertFile - self.clientCertFile = clientCertFile - self.clientKeyFile = clientKeyFile - self.insecureSkipVerify = insecureSkipVerify - self.alpnProtocols = alpnProtocols - self.enableKeyLog = enableKeyLog - } -} - - - -extension MqttTlsOptionsFfi: Equatable, Hashable { - public static func ==(lhs: MqttTlsOptionsFfi, rhs: MqttTlsOptionsFfi) -> Bool { - if lhs.caCertFile != rhs.caCertFile { - return false - } - if lhs.clientCertFile != rhs.clientCertFile { - return false - } - if lhs.clientKeyFile != rhs.clientKeyFile { - return false - } - if lhs.insecureSkipVerify != rhs.insecureSkipVerify { - return false - } - if lhs.alpnProtocols != rhs.alpnProtocols { - return false - } - if lhs.enableKeyLog != rhs.enableKeyLog { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(caCertFile) - hasher.combine(clientCertFile) - hasher.combine(clientKeyFile) - hasher.combine(insecureSkipVerify) - hasher.combine(alpnProtocols) - hasher.combine(enableKeyLog) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeMqttTlsOptionsFFI: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttTlsOptionsFfi { - return - try MqttTlsOptionsFfi( - caCertFile: FfiConverterOptionString.read(from: &buf), - clientCertFile: FfiConverterOptionString.read(from: &buf), - clientKeyFile: FfiConverterOptionString.read(from: &buf), - insecureSkipVerify: FfiConverterBool.read(from: &buf), - alpnProtocols: FfiConverterSequenceString.read(from: &buf), - enableKeyLog: FfiConverterBool.read(from: &buf) - ) - } - - public static func write(_ value: MqttTlsOptionsFfi, into buf: inout [UInt8]) { - FfiConverterOptionString.write(value.caCertFile, into: &buf) - FfiConverterOptionString.write(value.clientCertFile, into: &buf) - FfiConverterOptionString.write(value.clientKeyFile, into: &buf) - FfiConverterBool.write(value.insecureSkipVerify, into: &buf) - FfiConverterSequenceString.write(value.alpnProtocols, into: &buf) - FfiConverterBool.write(value.enableKeyLog, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttTlsOptionsFFI_lift(_ buf: RustBuffer) throws -> MqttTlsOptionsFfi { - return try FfiConverterTypeMqttTlsOptionsFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttTlsOptionsFFI_lower(_ value: MqttTlsOptionsFfi) -> RustBuffer { - return FfiConverterTypeMqttTlsOptionsFFI.lower(value) -} - - -public struct PublishResultFfi { - public var packetId: UInt16? - public var reasonCode: UInt8? - public var qos: UInt8 - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(packetId: UInt16?, reasonCode: UInt8?, qos: UInt8) { - self.packetId = packetId - self.reasonCode = reasonCode - self.qos = qos - } -} - - - -extension PublishResultFfi: Equatable, Hashable { - public static func ==(lhs: PublishResultFfi, rhs: PublishResultFfi) -> Bool { - if lhs.packetId != rhs.packetId { - return false - } - if lhs.reasonCode != rhs.reasonCode { - return false - } - if lhs.qos != rhs.qos { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(packetId) - hasher.combine(reasonCode) - hasher.combine(qos) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypePublishResultFFI: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PublishResultFfi { - return - try PublishResultFfi( - packetId: FfiConverterOptionUInt16.read(from: &buf), - reasonCode: FfiConverterOptionUInt8.read(from: &buf), - qos: FfiConverterUInt8.read(from: &buf) - ) - } - - public static func write(_ value: PublishResultFfi, into buf: inout [UInt8]) { - FfiConverterOptionUInt16.write(value.packetId, into: &buf) - FfiConverterOptionUInt8.write(value.reasonCode, into: &buf) - FfiConverterUInt8.write(value.qos, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypePublishResultFFI_lift(_ buf: RustBuffer) throws -> PublishResultFfi { - return try FfiConverterTypePublishResultFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypePublishResultFFI_lower(_ value: PublishResultFfi) -> RustBuffer { - return FfiConverterTypePublishResultFFI.lower(value) -} - - -public struct SubscribeResultFfi { - public var packetId: UInt16 - public var reasonCodes: Data - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(packetId: UInt16, reasonCodes: Data) { - self.packetId = packetId - self.reasonCodes = reasonCodes - } -} - - - -extension SubscribeResultFfi: Equatable, Hashable { - public static func ==(lhs: SubscribeResultFfi, rhs: SubscribeResultFfi) -> Bool { - if lhs.packetId != rhs.packetId { - return false - } - if lhs.reasonCodes != rhs.reasonCodes { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(packetId) - hasher.combine(reasonCodes) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeSubscribeResultFFI: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SubscribeResultFfi { - return - try SubscribeResultFfi( - packetId: FfiConverterUInt16.read(from: &buf), - reasonCodes: FfiConverterData.read(from: &buf) - ) - } - - public static func write(_ value: SubscribeResultFfi, into buf: inout [UInt8]) { - FfiConverterUInt16.write(value.packetId, into: &buf) - FfiConverterData.write(value.reasonCodes, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeSubscribeResultFFI_lift(_ buf: RustBuffer) throws -> SubscribeResultFfi { - return try FfiConverterTypeSubscribeResultFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeSubscribeResultFFI_lower(_ value: SubscribeResultFfi) -> RustBuffer { - return FfiConverterTypeSubscribeResultFFI.lower(value) -} - - -public struct UnsubscribeResultFfi { - public var packetId: UInt16 - public var reasonCodes: Data - - // Default memberwise initializers are never public by default, so we - // declare one manually. - public init(packetId: UInt16, reasonCodes: Data) { - self.packetId = packetId - self.reasonCodes = reasonCodes - } -} - - - -extension UnsubscribeResultFfi: Equatable, Hashable { - public static func ==(lhs: UnsubscribeResultFfi, rhs: UnsubscribeResultFfi) -> Bool { - if lhs.packetId != rhs.packetId { - return false - } - if lhs.reasonCodes != rhs.reasonCodes { - return false - } - return true - } - - public func hash(into hasher: inout Hasher) { - hasher.combine(packetId) - hasher.combine(reasonCodes) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeUnsubscribeResultFFI: FfiConverterRustBuffer { - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UnsubscribeResultFfi { - return - try UnsubscribeResultFfi( - packetId: FfiConverterUInt16.read(from: &buf), - reasonCodes: FfiConverterData.read(from: &buf) - ) - } - - public static func write(_ value: UnsubscribeResultFfi, into buf: inout [UInt8]) { - FfiConverterUInt16.write(value.packetId, into: &buf) - FfiConverterData.write(value.reasonCodes, into: &buf) - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeUnsubscribeResultFFI_lift(_ buf: RustBuffer) throws -> UnsubscribeResultFfi { - return try FfiConverterTypeUnsubscribeResultFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeUnsubscribeResultFFI_lower(_ value: UnsubscribeResultFfi) -> RustBuffer { - return FfiConverterTypeUnsubscribeResultFFI.lower(value) -} - -// Note that we don't yet support `indirect` for enums. -// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. - -public enum MqttEventFfi { - - case connected(ConnectionResultFfi - ) - case disconnected(reasonCode: UInt8? - ) - case messageReceived(MqttMessageFfi - ) - case published(PublishResultFfi - ) - case subscribed(SubscribeResultFfi - ) - case unsubscribed(UnsubscribeResultFfi - ) - case pingResponse(success: Bool - ) - case error(message: String - ) - case reconnectNeeded - case reconnectScheduled(attempt: UInt32, delayMs: UInt64 - ) -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public struct FfiConverterTypeMqttEventFFI: FfiConverterRustBuffer { - typealias SwiftType = MqttEventFfi - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MqttEventFfi { - let variant: Int32 = try readInt(&buf) - switch variant { - - case 1: return .connected(try FfiConverterTypeConnectionResultFFI.read(from: &buf) - ) - - case 2: return .disconnected(reasonCode: try FfiConverterOptionUInt8.read(from: &buf) - ) - - case 3: return .messageReceived(try FfiConverterTypeMqttMessageFFI.read(from: &buf) - ) - - case 4: return .published(try FfiConverterTypePublishResultFFI.read(from: &buf) - ) - - case 5: return .subscribed(try FfiConverterTypeSubscribeResultFFI.read(from: &buf) - ) - - case 6: return .unsubscribed(try FfiConverterTypeUnsubscribeResultFFI.read(from: &buf) - ) - - case 7: return .pingResponse(success: try FfiConverterBool.read(from: &buf) - ) - - case 8: return .error(message: try FfiConverterString.read(from: &buf) - ) - - case 9: return .reconnectNeeded - - case 10: return .reconnectScheduled(attempt: try FfiConverterUInt32.read(from: &buf), delayMs: try FfiConverterUInt64.read(from: &buf) - ) - - default: throw UniffiInternalError.unexpectedEnumCase - } - } - - public static func write(_ value: MqttEventFfi, into buf: inout [UInt8]) { - switch value { - - - case let .connected(v1): - writeInt(&buf, Int32(1)) - FfiConverterTypeConnectionResultFFI.write(v1, into: &buf) - - - case let .disconnected(reasonCode): - writeInt(&buf, Int32(2)) - FfiConverterOptionUInt8.write(reasonCode, into: &buf) - - - case let .messageReceived(v1): - writeInt(&buf, Int32(3)) - FfiConverterTypeMqttMessageFFI.write(v1, into: &buf) - - - case let .published(v1): - writeInt(&buf, Int32(4)) - FfiConverterTypePublishResultFFI.write(v1, into: &buf) - - - case let .subscribed(v1): - writeInt(&buf, Int32(5)) - FfiConverterTypeSubscribeResultFFI.write(v1, into: &buf) - - - case let .unsubscribed(v1): - writeInt(&buf, Int32(6)) - FfiConverterTypeUnsubscribeResultFFI.write(v1, into: &buf) - - - case let .pingResponse(success): - writeInt(&buf, Int32(7)) - FfiConverterBool.write(success, into: &buf) - - - case let .error(message): - writeInt(&buf, Int32(8)) - FfiConverterString.write(message, into: &buf) - - - case .reconnectNeeded: - writeInt(&buf, Int32(9)) - - - case let .reconnectScheduled(attempt,delayMs): - writeInt(&buf, Int32(10)) - FfiConverterUInt32.write(attempt, into: &buf) - FfiConverterUInt64.write(delayMs, into: &buf) - - } - } -} - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttEventFFI_lift(_ buf: RustBuffer) throws -> MqttEventFfi { - return try FfiConverterTypeMqttEventFFI.lift(buf) -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -public func FfiConverterTypeMqttEventFFI_lower(_ value: MqttEventFfi) -> RustBuffer { - return FfiConverterTypeMqttEventFFI.lower(value) -} - - - -extension MqttEventFfi: Equatable, Hashable {} - - - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterOptionUInt8: FfiConverterRustBuffer { - typealias SwiftType = UInt8? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterUInt8.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterUInt8.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterOptionUInt16: FfiConverterRustBuffer { - typealias SwiftType = UInt16? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterUInt16.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterUInt16.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { - typealias SwiftType = String? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterString.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterString.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterOptionTypeMqttEventFFI: FfiConverterRustBuffer { - typealias SwiftType = MqttEventFfi? - - public static func write(_ value: SwiftType, into buf: inout [UInt8]) { - guard let value = value else { - writeInt(&buf, Int8(0)) - return - } - writeInt(&buf, Int8(1)) - FfiConverterTypeMqttEventFFI.write(value, into: &buf) - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { - switch try readInt(&buf) as Int8 { - case 0: return nil - case 1: return try FfiConverterTypeMqttEventFFI.read(from: &buf) - default: throw UniffiInternalError.unexpectedOptionalTag - } - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { - typealias SwiftType = [String] - - public static func write(_ value: [String], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterString.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] { - let len: Int32 = try readInt(&buf) - var seq = [String]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterString.read(from: &buf)) - } - return seq - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterSequenceTypeMqttDatagramFFI: FfiConverterRustBuffer { - typealias SwiftType = [MqttDatagramFfi] - - public static func write(_ value: [MqttDatagramFfi], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeMqttDatagramFFI.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MqttDatagramFfi] { - let len: Int32 = try readInt(&buf) - var seq = [MqttDatagramFfi]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeMqttDatagramFFI.read(from: &buf)) - } - return seq - } -} - -#if swift(>=5.8) -@_documentation(visibility: private) -#endif -fileprivate struct FfiConverterSequenceTypeMqttEventFFI: FfiConverterRustBuffer { - typealias SwiftType = [MqttEventFfi] - - public static func write(_ value: [MqttEventFfi], into buf: inout [UInt8]) { - let len = Int32(value.count) - writeInt(&buf, len) - for item in value { - FfiConverterTypeMqttEventFFI.write(item, into: &buf) - } - } - - public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [MqttEventFfi] { - let len: Int32 = try readInt(&buf) - var seq = [MqttEventFfi]() - seq.reserveCapacity(Int(len)) - for _ in 0 ..< len { - seq.append(try FfiConverterTypeMqttEventFFI.read(from: &buf)) - } - return seq - } -} - -private enum InitializationResult { - case ok - case contractVersionMismatch - case apiChecksumMismatch -} -// Use a global variable to perform the versioning checks. Swift ensures that -// the code inside is only computed once. -private var initializationResult: InitializationResult = { - // Get the bindings contract version from our ComponentInterface - let bindings_contract_version = 26 - // Get the scaffolding contract version by calling the into the dylib - let scaffolding_contract_version = ffi_flowsdk_ffi_uniffi_contract_version() - if bindings_contract_version != scaffolding_contract_version { - return InitializationResult.contractVersionMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_auth() != 13274) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_connect() != 11843) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_disconnect() != 35275) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_get_version() != 19826) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_connection_lost() != 12358) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_incoming() != 55488) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_tick() != 40864) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_is_connected() != 33756) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_next_tick_ms() != 63992) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_publish() != 44572) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_push_event_ffi() != 16806) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_subscribe() != 31682) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_events() != 17921) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_outgoing() != 12337) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqttengineffi_unsubscribe() != 51097) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_get() != 5088) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_is_empty() != 43194) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_len() != 36035) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_connect() != 39570) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_disconnect() != 54076) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_datagram() != 34322) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_tick() != 39076) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_is_connected() != 53863) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_publish() != 17969) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_subscribe() != 16787) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_events() != 34914) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_outgoing_datagrams() != 32224) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_unsubscribe() != 48) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_connect() != 53946) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_disconnect() != 58642) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_socket_data() != 27993) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_tick() != 57570) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_is_connected() != 11670) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_publish() != 29858) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_subscribe() != 35959) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_events() != 41728) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_socket_data() != 6663) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_unsubscribe() != 21790) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new() != 63280) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new_with_opts() != 49926) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_constructor_quicmqttengineffi_new() != 4296) { - return InitializationResult.apiChecksumMismatch - } - if (uniffi_flowsdk_ffi_checksum_constructor_tlsmqttengineffi_new() != 55234) { - return InitializationResult.apiChecksumMismatch - } - - return InitializationResult.ok -}() - -private func uniffiEnsureInitialized() { - switch initializationResult { - case .ok: - break - case .contractVersionMismatch: - fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") - case .apiChecksumMismatch: - fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") - } -} - -// swiftlint:enable all \ No newline at end of file diff --git a/swift/Sources/flowsdk_ffi/flowsdk_ffi.h b/swift/Sources/flowsdk_ffi/flowsdk_ffi.h deleted file mode 100644 index f93c6761..00000000 --- a/swift/Sources/flowsdk_ffi/flowsdk_ffi.h +++ /dev/null @@ -1,1042 +0,0 @@ -// This file was autogenerated by some hot garbage in the `uniffi` crate. -// Trust me, you don't want to mess with it! - -#pragma once - -#include -#include -#include - -// The following structs are used to implement the lowest level -// of the FFI, and thus useful to multiple uniffied crates. -// We ensure they are declared exactly once, with a header guard, UNIFFI_SHARED_H. -#ifdef UNIFFI_SHARED_H - // We also try to prevent mixing versions of shared uniffi header structs. - // If you add anything to the #else block, you must increment the version suffix in UNIFFI_SHARED_HEADER_V4 - #ifndef UNIFFI_SHARED_HEADER_V4 - #error Combining helper code from multiple versions of uniffi is not supported - #endif // ndef UNIFFI_SHARED_HEADER_V4 -#else -#define UNIFFI_SHARED_H -#define UNIFFI_SHARED_HEADER_V4 -// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ -// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ - -typedef struct RustBuffer -{ - uint64_t capacity; - uint64_t len; - uint8_t *_Nullable data; -} RustBuffer; - -typedef struct ForeignBytes -{ - int32_t len; - const uint8_t *_Nullable data; -} ForeignBytes; - -// Error definitions -typedef struct RustCallStatus { - int8_t code; - RustBuffer errorBuf; -} RustCallStatus; - -// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️ -// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️ -#endif // def UNIFFI_SHARED_H -#ifndef UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK -#define UNIFFI_FFIDEF_RUST_FUTURE_CONTINUATION_CALLBACK -typedef void (*UniffiRustFutureContinuationCallback)(uint64_t, int8_t - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_FREE -typedef void (*UniffiForeignFutureFree)(uint64_t - ); - -#endif -#ifndef UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE -#define UNIFFI_FFIDEF_CALLBACK_INTERFACE_FREE -typedef void (*UniffiCallbackInterfaceFree)(uint64_t - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE -#define UNIFFI_FFIDEF_FOREIGN_FUTURE -typedef struct UniffiForeignFuture { - uint64_t handle; - UniffiForeignFutureFree _Nonnull free; -} UniffiForeignFuture; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U8 -typedef struct UniffiForeignFutureStructU8 { - uint8_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructU8; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U8 -typedef void (*UniffiForeignFutureCompleteU8)(uint64_t, UniffiForeignFutureStructU8 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I8 -typedef struct UniffiForeignFutureStructI8 { - int8_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructI8; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I8 -typedef void (*UniffiForeignFutureCompleteI8)(uint64_t, UniffiForeignFutureStructI8 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U16 -typedef struct UniffiForeignFutureStructU16 { - uint16_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructU16; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U16 -typedef void (*UniffiForeignFutureCompleteU16)(uint64_t, UniffiForeignFutureStructU16 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I16 -typedef struct UniffiForeignFutureStructI16 { - int16_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructI16; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I16 -typedef void (*UniffiForeignFutureCompleteI16)(uint64_t, UniffiForeignFutureStructI16 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U32 -typedef struct UniffiForeignFutureStructU32 { - uint32_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructU32; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U32 -typedef void (*UniffiForeignFutureCompleteU32)(uint64_t, UniffiForeignFutureStructU32 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I32 -typedef struct UniffiForeignFutureStructI32 { - int32_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructI32; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I32 -typedef void (*UniffiForeignFutureCompleteI32)(uint64_t, UniffiForeignFutureStructI32 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_U64 -typedef struct UniffiForeignFutureStructU64 { - uint64_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructU64; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_U64 -typedef void (*UniffiForeignFutureCompleteU64)(uint64_t, UniffiForeignFutureStructU64 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_I64 -typedef struct UniffiForeignFutureStructI64 { - int64_t returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructI64; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_I64 -typedef void (*UniffiForeignFutureCompleteI64)(uint64_t, UniffiForeignFutureStructI64 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F32 -typedef struct UniffiForeignFutureStructF32 { - float returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructF32; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F32 -typedef void (*UniffiForeignFutureCompleteF32)(uint64_t, UniffiForeignFutureStructF32 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_F64 -typedef struct UniffiForeignFutureStructF64 { - double returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructF64; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_F64 -typedef void (*UniffiForeignFutureCompleteF64)(uint64_t, UniffiForeignFutureStructF64 - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_POINTER -typedef struct UniffiForeignFutureStructPointer { - void*_Nonnull returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructPointer; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_POINTER -typedef void (*UniffiForeignFutureCompletePointer)(uint64_t, UniffiForeignFutureStructPointer - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_RUST_BUFFER -typedef struct UniffiForeignFutureStructRustBuffer { - RustBuffer returnValue; - RustCallStatus callStatus; -} UniffiForeignFutureStructRustBuffer; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_RUST_BUFFER -typedef void (*UniffiForeignFutureCompleteRustBuffer)(uint64_t, UniffiForeignFutureStructRustBuffer - ); - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_STRUCT_VOID -typedef struct UniffiForeignFutureStructVoid { - RustCallStatus callStatus; -} UniffiForeignFutureStructVoid; - -#endif -#ifndef UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID -#define UNIFFI_FFIDEF_FOREIGN_FUTURE_COMPLETE_VOID -typedef void (*UniffiForeignFutureCompleteVoid)(uint64_t, UniffiForeignFutureStructVoid - ); - -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_MQTTENGINEFFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_MQTTENGINEFFI -void*_Nonnull uniffi_flowsdk_ffi_fn_clone_mqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_MQTTENGINEFFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_MQTTENGINEFFI -void uniffi_flowsdk_ffi_fn_free_mqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_MQTTENGINEFFI_NEW -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_MQTTENGINEFFI_NEW -void*_Nonnull uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new(RustBuffer client_id, uint8_t mqtt_version, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_MQTTENGINEFFI_NEW_WITH_OPTS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_MQTTENGINEFFI_NEW_WITH_OPTS -void*_Nonnull uniffi_flowsdk_ffi_fn_constructor_mqttengineffi_new_with_opts(RustBuffer opts, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_AUTH -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_AUTH -void uniffi_flowsdk_ffi_fn_method_mqttengineffi_auth(void*_Nonnull ptr, uint8_t reason_code, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_CONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_CONNECT -void uniffi_flowsdk_ffi_fn_method_mqttengineffi_connect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_DISCONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_DISCONNECT -void uniffi_flowsdk_ffi_fn_method_mqttengineffi_disconnect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_GET_VERSION -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_GET_VERSION -uint8_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_get_version(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_CONNECTION_LOST -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_CONNECTION_LOST -void uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_connection_lost(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_INCOMING -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_INCOMING -RustBuffer uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_incoming(void*_Nonnull ptr, RustBuffer data, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_TICK -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_HANDLE_TICK -RustBuffer uniffi_flowsdk_ffi_fn_method_mqttengineffi_handle_tick(void*_Nonnull ptr, uint64_t now_ms, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_IS_CONNECTED -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_IS_CONNECTED -int8_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_is_connected(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_NEXT_TICK_MS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_NEXT_TICK_MS -int64_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_next_tick_ms(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_PUBLISH -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_PUBLISH -int32_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_publish(void*_Nonnull ptr, RustBuffer topic, RustBuffer payload, uint8_t qos, RustBuffer priority, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_PUSH_EVENT_FFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_PUSH_EVENT_FFI -void uniffi_flowsdk_ffi_fn_method_mqttengineffi_push_event_ffi(void*_Nonnull ptr, RustBuffer event, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_SUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_SUBSCRIBE -int32_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_subscribe(void*_Nonnull ptr, RustBuffer topic_filter, uint8_t qos, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_TAKE_EVENTS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_TAKE_EVENTS -RustBuffer uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_events(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_TAKE_OUTGOING -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_TAKE_OUTGOING -RustBuffer uniffi_flowsdk_ffi_fn_method_mqttengineffi_take_outgoing(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_UNSUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTENGINEFFI_UNSUBSCRIBE -int32_t uniffi_flowsdk_ffi_fn_method_mqttengineffi_unsubscribe(void*_Nonnull ptr, RustBuffer topic_filter, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_MQTTEVENTLISTFFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_MQTTEVENTLISTFFI -void*_Nonnull uniffi_flowsdk_ffi_fn_clone_mqtteventlistffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_MQTTEVENTLISTFFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_MQTTEVENTLISTFFI -void uniffi_flowsdk_ffi_fn_free_mqtteventlistffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_GET -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_GET -RustBuffer uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_get(void*_Nonnull ptr, uint32_t index, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_IS_EMPTY -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_IS_EMPTY -int8_t uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_is_empty(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_LEN -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_MQTTEVENTLISTFFI_LEN -uint32_t uniffi_flowsdk_ffi_fn_method_mqtteventlistffi_len(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_QUICMQTTENGINEFFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_QUICMQTTENGINEFFI -void*_Nonnull uniffi_flowsdk_ffi_fn_clone_quicmqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_QUICMQTTENGINEFFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_QUICMQTTENGINEFFI -void uniffi_flowsdk_ffi_fn_free_quicmqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_QUICMQTTENGINEFFI_NEW -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_QUICMQTTENGINEFFI_NEW -void*_Nonnull uniffi_flowsdk_ffi_fn_constructor_quicmqttengineffi_new(RustBuffer opts, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_CONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_CONNECT -void uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_connect(void*_Nonnull ptr, RustBuffer server_addr, RustBuffer server_name, RustBuffer tls_opts, uint64_t now_ms, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_DISCONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_DISCONNECT -void uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_disconnect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_HANDLE_DATAGRAM -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_HANDLE_DATAGRAM -void uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_datagram(void*_Nonnull ptr, RustBuffer data, RustBuffer remote_addr, uint64_t now_ms, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_HANDLE_TICK -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_HANDLE_TICK -RustBuffer uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_handle_tick(void*_Nonnull ptr, uint64_t now_ms, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_IS_CONNECTED -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_IS_CONNECTED -int8_t uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_is_connected(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_PUBLISH -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_PUBLISH -int32_t uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_publish(void*_Nonnull ptr, RustBuffer topic, RustBuffer payload, uint8_t qos, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_SUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_SUBSCRIBE -int32_t uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_subscribe(void*_Nonnull ptr, RustBuffer topic_filter, uint8_t qos, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_TAKE_EVENTS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_TAKE_EVENTS -RustBuffer uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_events(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_TAKE_OUTGOING_DATAGRAMS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_TAKE_OUTGOING_DATAGRAMS -RustBuffer uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_take_outgoing_datagrams(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_UNSUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_QUICMQTTENGINEFFI_UNSUBSCRIBE -int32_t uniffi_flowsdk_ffi_fn_method_quicmqttengineffi_unsubscribe(void*_Nonnull ptr, RustBuffer topic_filter, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_TLSMQTTENGINEFFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CLONE_TLSMQTTENGINEFFI -void*_Nonnull uniffi_flowsdk_ffi_fn_clone_tlsmqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_TLSMQTTENGINEFFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_FREE_TLSMQTTENGINEFFI -void uniffi_flowsdk_ffi_fn_free_tlsmqttengineffi(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_TLSMQTTENGINEFFI_NEW -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_CONSTRUCTOR_TLSMQTTENGINEFFI_NEW -void*_Nonnull uniffi_flowsdk_ffi_fn_constructor_tlsmqttengineffi_new(RustBuffer opts, RustBuffer tls_opts, RustBuffer server_name, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_CONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_CONNECT -void uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_connect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_DISCONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_DISCONNECT -void uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_disconnect(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_HANDLE_SOCKET_DATA -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_HANDLE_SOCKET_DATA -void uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_socket_data(void*_Nonnull ptr, RustBuffer data, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_HANDLE_TICK -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_HANDLE_TICK -RustBuffer uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_handle_tick(void*_Nonnull ptr, uint64_t now_ms, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_IS_CONNECTED -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_IS_CONNECTED -int8_t uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_is_connected(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_PUBLISH -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_PUBLISH -int32_t uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_publish(void*_Nonnull ptr, RustBuffer topic, RustBuffer payload, uint8_t qos, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_SUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_SUBSCRIBE -int32_t uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_subscribe(void*_Nonnull ptr, RustBuffer topic_filter, uint8_t qos, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_TAKE_EVENTS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_TAKE_EVENTS -RustBuffer uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_events(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_TAKE_SOCKET_DATA -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_TAKE_SOCKET_DATA -RustBuffer uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_take_socket_data(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_UNSUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_FN_METHOD_TLSMQTTENGINEFFI_UNSUBSCRIBE -int32_t uniffi_flowsdk_ffi_fn_method_tlsmqttengineffi_unsubscribe(void*_Nonnull ptr, RustBuffer topic_filter, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_ALLOC -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_ALLOC -RustBuffer ffi_flowsdk_ffi_rustbuffer_alloc(uint64_t size, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_FROM_BYTES -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_FROM_BYTES -RustBuffer ffi_flowsdk_ffi_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_FREE -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_FREE -void ffi_flowsdk_ffi_rustbuffer_free(RustBuffer buf, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_RESERVE -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUSTBUFFER_RESERVE -RustBuffer ffi_flowsdk_ffi_rustbuffer_reserve(RustBuffer buf, uint64_t additional, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U8 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U8 -void ffi_flowsdk_ffi_rust_future_poll_u8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U8 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U8 -void ffi_flowsdk_ffi_rust_future_cancel_u8(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U8 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U8 -void ffi_flowsdk_ffi_rust_future_free_u8(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U8 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U8 -uint8_t ffi_flowsdk_ffi_rust_future_complete_u8(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I8 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I8 -void ffi_flowsdk_ffi_rust_future_poll_i8(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I8 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I8 -void ffi_flowsdk_ffi_rust_future_cancel_i8(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I8 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I8 -void ffi_flowsdk_ffi_rust_future_free_i8(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I8 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I8 -int8_t ffi_flowsdk_ffi_rust_future_complete_i8(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U16 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U16 -void ffi_flowsdk_ffi_rust_future_poll_u16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U16 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U16 -void ffi_flowsdk_ffi_rust_future_cancel_u16(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U16 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U16 -void ffi_flowsdk_ffi_rust_future_free_u16(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U16 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U16 -uint16_t ffi_flowsdk_ffi_rust_future_complete_u16(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I16 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I16 -void ffi_flowsdk_ffi_rust_future_poll_i16(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I16 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I16 -void ffi_flowsdk_ffi_rust_future_cancel_i16(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I16 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I16 -void ffi_flowsdk_ffi_rust_future_free_i16(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I16 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I16 -int16_t ffi_flowsdk_ffi_rust_future_complete_i16(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U32 -void ffi_flowsdk_ffi_rust_future_poll_u32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U32 -void ffi_flowsdk_ffi_rust_future_cancel_u32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U32 -void ffi_flowsdk_ffi_rust_future_free_u32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U32 -uint32_t ffi_flowsdk_ffi_rust_future_complete_u32(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I32 -void ffi_flowsdk_ffi_rust_future_poll_i32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I32 -void ffi_flowsdk_ffi_rust_future_cancel_i32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I32 -void ffi_flowsdk_ffi_rust_future_free_i32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I32 -int32_t ffi_flowsdk_ffi_rust_future_complete_i32(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_U64 -void ffi_flowsdk_ffi_rust_future_poll_u64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_U64 -void ffi_flowsdk_ffi_rust_future_cancel_u64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_U64 -void ffi_flowsdk_ffi_rust_future_free_u64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_U64 -uint64_t ffi_flowsdk_ffi_rust_future_complete_u64(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_I64 -void ffi_flowsdk_ffi_rust_future_poll_i64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_I64 -void ffi_flowsdk_ffi_rust_future_cancel_i64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_I64 -void ffi_flowsdk_ffi_rust_future_free_i64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_I64 -int64_t ffi_flowsdk_ffi_rust_future_complete_i64(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_F32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_F32 -void ffi_flowsdk_ffi_rust_future_poll_f32(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_F32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_F32 -void ffi_flowsdk_ffi_rust_future_cancel_f32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_F32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_F32 -void ffi_flowsdk_ffi_rust_future_free_f32(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_F32 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_F32 -float ffi_flowsdk_ffi_rust_future_complete_f32(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_F64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_F64 -void ffi_flowsdk_ffi_rust_future_poll_f64(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_F64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_F64 -void ffi_flowsdk_ffi_rust_future_cancel_f64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_F64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_F64 -void ffi_flowsdk_ffi_rust_future_free_f64(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_F64 -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_F64 -double ffi_flowsdk_ffi_rust_future_complete_f64(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_POINTER -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_POINTER -void ffi_flowsdk_ffi_rust_future_poll_pointer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_POINTER -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_POINTER -void ffi_flowsdk_ffi_rust_future_cancel_pointer(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_POINTER -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_POINTER -void ffi_flowsdk_ffi_rust_future_free_pointer(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_POINTER -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_POINTER -void*_Nonnull ffi_flowsdk_ffi_rust_future_complete_pointer(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_RUST_BUFFER -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_RUST_BUFFER -void ffi_flowsdk_ffi_rust_future_poll_rust_buffer(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_RUST_BUFFER -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_RUST_BUFFER -void ffi_flowsdk_ffi_rust_future_cancel_rust_buffer(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_RUST_BUFFER -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_RUST_BUFFER -void ffi_flowsdk_ffi_rust_future_free_rust_buffer(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_RUST_BUFFER -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_RUST_BUFFER -RustBuffer ffi_flowsdk_ffi_rust_future_complete_rust_buffer(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_VOID -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_POLL_VOID -void ffi_flowsdk_ffi_rust_future_poll_void(uint64_t handle, UniffiRustFutureContinuationCallback _Nonnull callback, uint64_t callback_data -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_VOID -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_CANCEL_VOID -void ffi_flowsdk_ffi_rust_future_cancel_void(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_VOID -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_FREE_VOID -void ffi_flowsdk_ffi_rust_future_free_void(uint64_t handle -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_VOID -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_RUST_FUTURE_COMPLETE_VOID -void ffi_flowsdk_ffi_rust_future_complete_void(uint64_t handle, RustCallStatus *_Nonnull out_status -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_AUTH -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_AUTH -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_auth(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_CONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_CONNECT -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_connect(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_DISCONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_DISCONNECT -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_disconnect(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_GET_VERSION -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_GET_VERSION -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_get_version(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_CONNECTION_LOST -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_CONNECTION_LOST -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_connection_lost(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_INCOMING -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_INCOMING -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_incoming(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_TICK -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_HANDLE_TICK -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_handle_tick(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_IS_CONNECTED -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_IS_CONNECTED -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_is_connected(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_NEXT_TICK_MS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_NEXT_TICK_MS -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_next_tick_ms(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_PUBLISH -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_PUBLISH -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_publish(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_PUSH_EVENT_FFI -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_PUSH_EVENT_FFI -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_push_event_ffi(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_SUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_SUBSCRIBE -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_subscribe(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_TAKE_EVENTS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_TAKE_EVENTS -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_events(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_TAKE_OUTGOING -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_TAKE_OUTGOING -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_take_outgoing(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_UNSUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTENGINEFFI_UNSUBSCRIBE -uint16_t uniffi_flowsdk_ffi_checksum_method_mqttengineffi_unsubscribe(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_GET -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_GET -uint16_t uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_get(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_IS_EMPTY -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_IS_EMPTY -uint16_t uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_is_empty(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_LEN -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_MQTTEVENTLISTFFI_LEN -uint16_t uniffi_flowsdk_ffi_checksum_method_mqtteventlistffi_len(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_CONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_CONNECT -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_connect(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_DISCONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_DISCONNECT -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_disconnect(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_HANDLE_DATAGRAM -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_HANDLE_DATAGRAM -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_datagram(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_HANDLE_TICK -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_HANDLE_TICK -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_handle_tick(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_IS_CONNECTED -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_IS_CONNECTED -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_is_connected(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_PUBLISH -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_PUBLISH -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_publish(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_SUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_SUBSCRIBE -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_subscribe(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_TAKE_EVENTS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_TAKE_EVENTS -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_events(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_TAKE_OUTGOING_DATAGRAMS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_TAKE_OUTGOING_DATAGRAMS -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_take_outgoing_datagrams(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_UNSUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_QUICMQTTENGINEFFI_UNSUBSCRIBE -uint16_t uniffi_flowsdk_ffi_checksum_method_quicmqttengineffi_unsubscribe(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_CONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_CONNECT -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_connect(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_DISCONNECT -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_DISCONNECT -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_disconnect(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_HANDLE_SOCKET_DATA -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_HANDLE_SOCKET_DATA -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_socket_data(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_HANDLE_TICK -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_HANDLE_TICK -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_handle_tick(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_IS_CONNECTED -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_IS_CONNECTED -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_is_connected(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_PUBLISH -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_PUBLISH -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_publish(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_SUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_SUBSCRIBE -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_subscribe(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_TAKE_EVENTS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_TAKE_EVENTS -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_events(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_TAKE_SOCKET_DATA -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_TAKE_SOCKET_DATA -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_take_socket_data(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_UNSUBSCRIBE -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_METHOD_TLSMQTTENGINEFFI_UNSUBSCRIBE -uint16_t uniffi_flowsdk_ffi_checksum_method_tlsmqttengineffi_unsubscribe(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_MQTTENGINEFFI_NEW -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_MQTTENGINEFFI_NEW -uint16_t uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_MQTTENGINEFFI_NEW_WITH_OPTS -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_MQTTENGINEFFI_NEW_WITH_OPTS -uint16_t uniffi_flowsdk_ffi_checksum_constructor_mqttengineffi_new_with_opts(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_QUICMQTTENGINEFFI_NEW -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_QUICMQTTENGINEFFI_NEW -uint16_t uniffi_flowsdk_ffi_checksum_constructor_quicmqttengineffi_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_TLSMQTTENGINEFFI_NEW -#define UNIFFI_FFIDEF_UNIFFI_FLOWSDK_FFI_CHECKSUM_CONSTRUCTOR_TLSMQTTENGINEFFI_NEW -uint16_t uniffi_flowsdk_ffi_checksum_constructor_tlsmqttengineffi_new(void - -); -#endif -#ifndef UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_UNIFFI_CONTRACT_VERSION -#define UNIFFI_FFIDEF_FFI_FLOWSDK_FFI_UNIFFI_CONTRACT_VERSION -uint32_t ffi_flowsdk_ffi_uniffi_contract_version(void - -); -#endif - From f1971dec6e111626c810f6a1329dd5dc8750f245 Mon Sep 17 00:00:00 2001 From: William Yang Date: Tue, 21 Apr 2026 13:39:35 +0200 Subject: [PATCH 5/5] fix(example): update file descriptor closing logic and improve sendAll error handling --- .github/workflows/ci.yml | 2 +- swift/Examples/QuicClientExample/main.swift | 2 +- swift/Examples/TcpClientExample/main.swift | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84a50d0f..73f12087 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -220,7 +220,7 @@ jobs: ~/.cargo/registry ~/.cargo/git target - key: ${{ runner.os }}-cargo-swift-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-cargo-swift-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-swift- diff --git a/swift/Examples/QuicClientExample/main.swift b/swift/Examples/QuicClientExample/main.swift index 311bf936..8fc83f7f 100644 --- a/swift/Examples/QuicClientExample/main.swift +++ b/swift/Examples/QuicClientExample/main.swift @@ -212,5 +212,5 @@ while nowMs(since: engineStartMs) < runDurationMs { print("Run time elapsed, disconnecting...") engine.disconnect() sendOutgoing(engine, fd: fd, to: &brokerAddr) -Darwin.close(fd) +close(fd) print("Done.") diff --git a/swift/Examples/TcpClientExample/main.swift b/swift/Examples/TcpClientExample/main.swift index 7b790c9a..0e5556c4 100644 --- a/swift/Examples/TcpClientExample/main.swift +++ b/swift/Examples/TcpClientExample/main.swift @@ -65,8 +65,18 @@ private func sendAll(_ fd: Int32, data: Data) { var sent = 0 while sent < data.count { let n = send(fd, ptr.baseAddress!.advanced(by: sent), data.count - sent, 0) - if n <= 0 { return } - sent += n + if n > 0 { + sent += n + } else if n < 0 { + if errno == EINTR { + continue // signal interrupted — retry immediately + } else if errno == EAGAIN || errno == EWOULDBLOCK { + _ = waitWritable(fd, timeoutMs: 1000) // wait for buffer space + continue + } else { + return // unrecoverable error + } + } } } } @@ -196,5 +206,5 @@ while nowMs(since: engineStartMs) < runDurationMs { print("Run time elapsed, disconnecting...") engine.disconnect() sendAll(fd, data: engine.takeOutgoing()) -Darwin.close(fd) +close(fd) print("Done.")