Skip to content

Commit b3c1afa

Browse files
authored
Merge pull request #30 from Mordil/29-replace-data
Replace `Foundation.Data` with `[UInt8]` type everywhere
2 parents 51dd32d + 3c53d44 commit b3c1afa

17 files changed

+82
-100
lines changed

Sources/NIORedis/ChannelHandlers/RedisCommandHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Foundation
1+
import struct Foundation.UUID
22
import Logging
33
import NIO
44

Sources/NIORedis/Commands/BasicCommands.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Foundation
21
import NIO
32

43
extension RedisClient {

Sources/NIORedis/Commands/SetCommands.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Foundation
21
import NIO
32

43
// MARK: General

Sources/NIORedis/Extensions/NIO/ClientBootstrap.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Foundation
21
import NIO
32

43
extension ClientBootstrap {

Sources/NIORedis/RESP/RESPDecoder.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Foundation
21
import NIO
32

43
extension UInt8 {
@@ -143,7 +142,7 @@ extension RESPDecoder {
143142
guard size > 0 else {
144143
// Move the tip of the message position
145144
position += 2
146-
return .parsed(.bulkString(Data()))
145+
return .parsed(.bulkString([]))
147146
}
148147

149148
guard let bytes = buffer.copyBytes(at: position, length: expectedRemainingMessageSize) else {
@@ -154,9 +153,9 @@ extension RESPDecoder {
154153
// of the bulk string content
155154
position += expectedRemainingMessageSize
156155

157-
return .parsed(
158-
.bulkString(Data(bytes[ ..<size ]))
159-
)
156+
return .parsed(.bulkString(
157+
.init(bytes[..<size])
158+
))
160159
}
161160

162161
/// See [https://redis.io/topics/protocol#resp-arrays](https://redis.io/topics/protocol#resp-arrays)

Sources/NIORedis/RESP/RESPValue.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import Foundation
2-
31
/// A representation of a Redis Serialization Protocol (RESP) primitive value.
42
///
53
/// See: [https://redis.io/topics/protocol](https://redis.io/topics/protocol)
64
public enum RESPValue {
75
case null
86
case simpleString(String)
9-
case bulkString(Data)
7+
case bulkString([UInt8])
108
case error(RedisError)
119
case integer(Int)
1210
case array([RESPValue])
1311

1412
/// Initializes a `bulkString` by converting the provided string input.
1513
public init(bulk: String) {
16-
self = .bulkString(Data(bulk.utf8))
14+
let bytes = [UInt8](bulk.utf8)
15+
self = .bulkString(bytes)
1716
}
1817
}
1918

2019
extension RESPValue: ExpressibleByStringLiteral {
2120
/// Initializes a bulk string from a String literal
2221
public init(stringLiteral value: String) {
23-
self = .bulkString(Data(value.utf8))
22+
let bytes = [UInt8](value.utf8)
23+
self = .bulkString(bytes)
2424
}
2525
}
2626

@@ -51,15 +51,15 @@ extension RESPValue {
5151
public var string: String? {
5252
switch self {
5353
case .simpleString(let string): return string
54-
case .bulkString(let data): return String(bytes: data, encoding: .utf8)
54+
case .bulkString(let bytes): return String(bytes: bytes, encoding: .utf8)
5555
default: return nil
5656
}
5757
}
5858

59-
/// Extracted binary data from `bulkString` representations.
60-
public var data: Data? {
61-
guard case .bulkString(let data) = self else { return nil }
62-
return data
59+
/// Extracted byte representation from `bulkString` values.
60+
public var bytes: [UInt8]? {
61+
guard case let .bulkString(bytes) = self else { return nil }
62+
return bytes
6363
}
6464

6565
/// Extracted container of data elements from `array` representations.

Sources/NIORedis/RESP/RESPValueConvertible.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Foundation
2-
31
/// Capable of converting to / from `RESPValue`.
42
public protocol RESPValueConvertible {
53
init?(_ value: RESPValue)
@@ -39,7 +37,7 @@ extension String: RESPValueConvertible {
3937

4038
/// See `RESPValueConvertible.convertedToRESPValue()`
4139
public func convertedToRESPValue() -> RESPValue {
42-
return .bulkString(Data(self.utf8))
40+
return .bulkString(.init(self.utf8))
4341
}
4442
}
4543

@@ -56,7 +54,7 @@ extension FixedWidthInteger {
5654

5755
/// See `RESPValueConvertible.convertedToRESPValue()`
5856
public func convertedToRESPValue() -> RESPValue {
59-
return .bulkString(Data(self.description.utf8))
57+
return .bulkString(.init(self.description.utf8))
6058
}
6159
}
6260

@@ -80,7 +78,7 @@ extension Double: RESPValueConvertible {
8078

8179
/// See `RESPValueConvertible.convertedToRESPValue()`
8280
public func convertedToRESPValue() -> RESPValue {
83-
return .bulkString(Data(self.description.utf8))
81+
return .bulkString(.init(self.description.utf8))
8482
}
8583
}
8684

@@ -93,19 +91,7 @@ extension Float: RESPValueConvertible {
9391

9492
/// See `RESPValueConvertible.convertedToRESPValue()`
9593
public func convertedToRESPValue() -> RESPValue {
96-
return .bulkString(Data(self.description.utf8))
97-
}
98-
}
99-
100-
extension Data: RESPValueConvertible {
101-
public init?(_ value: RESPValue) {
102-
guard let data = value.data else { return nil }
103-
self = data
104-
}
105-
106-
/// See `RESPValueConvertible.convertedToRESPValue()`
107-
public func convertedToRESPValue() -> RESPValue {
108-
return .bulkString(self)
94+
return .bulkString(.init(self.description.utf8))
10995
}
11096
}
11197

Sources/NIORedis/RedisClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import struct Foundation.UUID
12
import Logging
2-
import Foundation
33
import NIO
44
import NIOConcurrencyHelpers
55

Sources/NIORedis/RedisError.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import Foundation
1+
import protocol Foundation.LocalizedError
2+
import class Foundation.Thread
23

34
/// Errors thrown while working with Redis.
45
public struct RedisError: CustomDebugStringConvertible, CustomStringConvertible, LocalizedError {

Sources/NIORedis/RedisPipeline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Foundation
1+
import struct Foundation.UUID
22
import Logging
33

44
/// An object that provides a mechanism to "pipeline" multiple Redis commands in sequence,

0 commit comments

Comments
 (0)