From 397b09e4f768493e02690a9d60614ed2dad5977c Mon Sep 17 00:00:00 2001 From: Michael Gecht Date: Thu, 14 Nov 2024 17:25:27 +0000 Subject: [PATCH] Enable Swift 6 support (#177) Enable Swift 6 support. `String.init(validatingUTF8:)` is deprecated, and we use `String.init(validatingCString:)` instead. Closes https://github.com/swift-server/swift-kafka-client/pull/169 --- Sources/Kafka/KafkaAcknowledgedMessage.swift | 7 +++++++ Sources/Kafka/KafkaConsumerMessage.swift | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Sources/Kafka/KafkaAcknowledgedMessage.swift b/Sources/Kafka/KafkaAcknowledgedMessage.swift index 8f529acc..7c7d958a 100644 --- a/Sources/Kafka/KafkaAcknowledgedMessage.swift +++ b/Sources/Kafka/KafkaAcknowledgedMessage.swift @@ -40,9 +40,16 @@ public struct KafkaAcknowledgedMessage { throw KafkaError.rdKafkaError(wrapping: rdKafkaMessage.err) } + #if swift(<6.0) guard let topic = String(validatingUTF8: rd_kafka_topic_name(rdKafkaMessage.rkt)) else { fatalError("Received topic name that is non-valid UTF-8") } + #else + guard let topic = String(validatingCString: rd_kafka_topic_name(rdKafkaMessage.rkt)) else { + fatalError("Received topic name that is non-valid UTF-8") + } + #endif + self.topic = topic self.partition = KafkaPartition(rawValue: Int(rdKafkaMessage.partition)) diff --git a/Sources/Kafka/KafkaConsumerMessage.swift b/Sources/Kafka/KafkaConsumerMessage.swift index c4a6570a..a33b1be9 100644 --- a/Sources/Kafka/KafkaConsumerMessage.swift +++ b/Sources/Kafka/KafkaConsumerMessage.swift @@ -52,9 +52,16 @@ public struct KafkaConsumerMessage { } } + #if swift(<6.0) guard let topic = String(validatingUTF8: rd_kafka_topic_name(rdKafkaMessage.rkt)) else { fatalError("Received topic name that is non-valid UTF-8") } + #else + guard let topic = String(validatingCString: rd_kafka_topic_name(rdKafkaMessage.rkt)) else { + fatalError("Received topic name that is non-valid UTF-8") + } + #endif + self.topic = topic self.partition = KafkaPartition(rawValue: Int(rdKafkaMessage.partition))