Skip to content

Commit 3a85aff

Browse files
Fix conversion from String to Bytes (#103)
Motivation: `String.count` is the character count, but not the byte count Modifications: * `String+KafkaContiguousBytes`: use `String.utf8.count` when creating `UnsafeRawBufferPointer`
1 parent 071f51d commit 3a85aff

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/SwiftKafka/Data/String+KafkaContiguousBytes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension String: KafkaContiguousBytes {
1818
public func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R {
1919
if let read = try self.utf8.withContiguousStorageIfAvailable({ unsafePointer in
2020
// Fast Path
21-
let unsafeRawBufferPointer = UnsafeRawBufferPointer(start: unsafePointer.baseAddress, count: self.count)
21+
let unsafeRawBufferPointer = UnsafeRawBufferPointer(start: unsafePointer.baseAddress, count: self.utf8.count)
2222
return try body(unsafeRawBufferPointer)
2323
}) {
2424
return read

0 commit comments

Comments
 (0)