Skip to content

Commit

Permalink
Enable Swift 6 support (#177)
Browse files Browse the repository at this point in the history
Enable Swift 6 support. `String.init(validatingUTF8:)` is deprecated,
and we use `String.init(validatingCString:)` instead.

Closes #169
  • Loading branch information
mimischi authored Nov 14, 2024
1 parent de10ce1 commit 397b09e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/Kafka/KafkaAcknowledgedMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions Sources/Kafka/KafkaConsumerMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 397b09e

Please sign in to comment.