Skip to content

Commit eb11a5c

Browse files
authored
Remove fromRESP parameter label from RESPTokenDecodable.init(_:) (#275)
* Remove fromRESP parameter label from RESPTokenDecodable.init(_:) Signed-off-by: Adam Fowler <[email protected]> * Fix documentation issue Signed-off-by: Adam Fowler <[email protected]> --------- Signed-off-by: Adam Fowler <[email protected]>
1 parent dfebc67 commit eb11a5c

21 files changed

+196
-196
lines changed

Sources/Valkey/Commands/Custom/ClusterCustomCommands.swift

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public struct ValkeyClusterDescription: Hashable, Sendable, RESPTokenDecodable {
180180

181181
/// Creates a cluster description from the response token you provide.
182182
/// - Parameter respToken: The response token.
183-
public init(fromRESP respToken: RESPToken) throws {
183+
public init(_ respToken: RESPToken) throws {
184184
self = try Self.makeClusterDescription(respToken: respToken)
185185
}
186186

@@ -264,7 +264,7 @@ public struct ValkeyClusterLink: Hashable, Sendable, RESPTokenDecodable {
264264

265265
/// Creates a cluster link from the response token you provide.
266266
/// - Parameter respToken: The response token.
267-
public init(fromRESP respToken: RESPToken) throws {
267+
public init(_ respToken: RESPToken) throws {
268268
self = try Self.makeClusterLink(respToken: respToken)
269269
}
270270

@@ -275,7 +275,7 @@ public struct ValkeyClusterLink: Hashable, Sendable, RESPTokenDecodable {
275275

276276
case .map(let map):
277277
let mapped = map.lazy.compactMap { (keyNode, value) -> (String, RESPToken)? in
278-
if let key = try? String(fromRESP: keyNode) {
278+
if let key = try? String(keyNode) {
279279
return (key, value)
280280
} else {
281281
return nil
@@ -302,27 +302,27 @@ public struct ValkeyClusterLink: Hashable, Sendable, RESPTokenDecodable {
302302
for (key, value) in sequence {
303303
switch key {
304304
case "direction":
305-
guard let directionString = try? String(fromRESP: value),
305+
guard let directionString = try? String(value),
306306
let directionValue = ValkeyClusterLink.Direction(rawValue: directionString)
307307
else {
308308
throw RESPDecodeError.missingToken(key: "direction", token: respToken)
309309
}
310310
direction = directionValue
311311

312312
case "node":
313-
node = try? String(fromRESP: value)
313+
node = try? String(value)
314314

315315
case "create-time":
316-
createTime = try? Int64(fromRESP: value)
316+
createTime = try? Int64(value)
317317

318318
case "events":
319-
events = try? String(fromRESP: value)
319+
events = try? String(value)
320320

321321
case "send-buffer-allocated":
322-
sendBufferAllocated = try? Int64(fromRESP: value)
322+
sendBufferAllocated = try? Int64(value)
323323

324324
case "send-buffer-used":
325-
sendBufferUsed = try? Int64(fromRESP: value)
325+
sendBufferUsed = try? Int64(value)
326326

327327
default:
328328
// ignore unexpected keys for forward compatibility
@@ -379,7 +379,7 @@ public struct ValkeyClusterSlotStats: Hashable, Sendable, RESPTokenDecodable {
379379

380380
/// Creates a cluster slot stats from the response token you provide.
381381
/// - Parameter respToken: The response token.
382-
public init(fromRESP respToken: RESPToken) throws {
382+
public init(_ respToken: RESPToken) throws {
383383
self = try Self.makeClusterSlotStats(respToken: respToken)
384384
}
385385

@@ -419,7 +419,7 @@ public struct ValkeyClusterSlotStats: Hashable, Sendable, RESPTokenDecodable {
419419
case .map(let map):
420420
// For RESP3, handle RESPToken stats as map
421421
let mapped = map.lazy.compactMap { (keyNode, value) -> (String, RESPToken)? in
422-
if let key = try? String(fromRESP: keyNode) {
422+
if let key = try? String(keyNode) {
423423
return (key, value)
424424
} else {
425425
return nil
@@ -428,16 +428,16 @@ public struct ValkeyClusterSlotStats: Hashable, Sendable, RESPTokenDecodable {
428428
for (key, value) in mapped {
429429
switch key {
430430
case "key-count":
431-
keyCount = try? Int64(fromRESP: value)
431+
keyCount = try? Int64(value)
432432

433433
case "cpu-usec":
434-
cpuUsec = try? Int64(fromRESP: value)
434+
cpuUsec = try? Int64(value)
435435

436436
case "network-bytes-in":
437-
networkBytesIn = try? Int64(fromRESP: value)
437+
networkBytesIn = try? Int64(value)
438438

439439
case "network-bytes-out":
440-
networkBytesOut = try? Int64(fromRESP: value)
440+
networkBytesOut = try? Int64(value)
441441

442442
default:
443443
// ignore unexpected keys for forward compatibility
@@ -451,16 +451,16 @@ public struct ValkeyClusterSlotStats: Hashable, Sendable, RESPTokenDecodable {
451451
for (key, valueToken) in mapArray {
452452
switch key {
453453
case "key-count":
454-
keyCount = try? Int64(fromRESP: valueToken)
454+
keyCount = try? Int64(valueToken)
455455

456456
case "cpu-usec":
457-
cpuUsec = try? Int64(fromRESP: valueToken)
457+
cpuUsec = try? Int64(valueToken)
458458

459459
case "network-bytes-in":
460-
networkBytesIn = try? Int64(fromRESP: valueToken)
460+
networkBytesIn = try? Int64(valueToken)
461461

462462
case "network-bytes-out":
463-
networkBytesOut = try? Int64(fromRESP: valueToken)
463+
networkBytesOut = try? Int64(valueToken)
464464

465465
default:
466466
// ignore unexpected keys for forward compatibility
@@ -536,7 +536,7 @@ public struct ValkeyClusterSlotRange: Hashable, Sendable, RESPTokenDecodable {
536536

537537
/// Creates a cluster slot range from the response token you provide.
538538
/// - Parameter respToken: The response token.
539-
public init(fromRESP respToken: RESPToken) throws {
539+
public init(_ respToken: RESPToken) throws {
540540
self = try Self.makeClusterSlotRange(respToken: respToken)
541541
}
542542

@@ -639,7 +639,7 @@ extension ValkeyClusterDescription.Shard {
639639

640640
case .map(let map):
641641
let mapped = map.lazy.compactMap { (keyNode, value) -> (String, RESPToken)? in
642-
if let key = try? String(fromRESP: keyNode) {
642+
if let key = try? String(keyNode) {
643643
return (key, value)
644644
} else {
645645
return nil
@@ -692,7 +692,7 @@ extension ValkeyClusterDescription.Node {
692692

693693
case .map(let map):
694694
let mapped = map.lazy.compactMap { (keyNode, value) -> (String, RESPToken)? in
695-
if let key = try? String(fromRESP: keyNode) {
695+
if let key = try? String(keyNode) {
696696
return (key, value)
697697
} else {
698698
return nil
@@ -736,27 +736,27 @@ extension ValkeyClusterDescription.Node {
736736
while let (key, nodeVal) = nodeIterator.next() {
737737
switch key {
738738
case "id":
739-
id = try? String(fromRESP: nodeVal)
739+
id = try? String(nodeVal)
740740
case "port":
741-
port = try? Int64(fromRESP: nodeVal)
741+
port = try? Int64(nodeVal)
742742
case "tls-port":
743-
tlsPort = try? Int64(fromRESP: nodeVal)
743+
tlsPort = try? Int64(nodeVal)
744744
case "ip":
745-
ip = try? String(fromRESP: nodeVal)
745+
ip = try? String(nodeVal)
746746
case "hostname":
747-
hostname = try? String(fromRESP: nodeVal)
747+
hostname = try? String(nodeVal)
748748
case "endpoint":
749-
endpoint = try? String(fromRESP: nodeVal)
749+
endpoint = try? String(nodeVal)
750750
case "role":
751-
guard let roleString = try? String(fromRESP: nodeVal), let roleValue = ValkeyClusterDescription.Node.Role(rawValue: roleString) else {
751+
guard let roleString = try? String(nodeVal), let roleValue = ValkeyClusterDescription.Node.Role(rawValue: roleString) else {
752752
throw .decodeError(RESPDecodeError(.unexpectedToken, token: nodeVal, message: "Invalid Role String"))
753753
}
754754
role = roleValue
755755

756756
case "replication-offset":
757-
replicationOffset = try? Int64(fromRESP: nodeVal)
757+
replicationOffset = try? Int64(nodeVal)
758758
case "health":
759-
guard let healthString = try? String(fromRESP: nodeVal),
759+
guard let healthString = try? String(nodeVal),
760760
let healthValue = ValkeyClusterDescription.Node.Health(rawValue: healthString)
761761
else {
762762
throw .decodeError(RESPDecodeError(.unexpectedToken, token: nodeVal, message: "Invalid Node Health String"))
@@ -808,7 +808,7 @@ extension ValkeyClusterSlotRange.Node {
808808

809809
// First element: IP address
810810
guard let ipToken = iterator.next(),
811-
let ip = try? String(fromRESP: ipToken)
811+
let ip = try? String(ipToken)
812812
else {
813813
throw RESPDecodeError.missingToken(key: "ip", token: respToken)
814814
}
@@ -823,7 +823,7 @@ extension ValkeyClusterSlotRange.Node {
823823

824824
// Third element: node ID
825825
guard let nodeIdToken = iterator.next(),
826-
let nodeId = try? String(fromRESP: nodeIdToken)
826+
let nodeId = try? String(nodeIdToken)
827827
else {
828828
throw RESPDecodeError.missingToken(key: "node id", token: respToken)
829829
}
@@ -836,8 +836,8 @@ extension ValkeyClusterSlotRange.Node {
836836
case .map(let map):
837837
// Handle metadata as a map
838838
for (keyToken, valueToken) in map {
839-
if let key = try? String(fromRESP: keyToken),
840-
let value = try? String(fromRESP: valueToken)
839+
if let key = try? String(keyToken),
840+
let value = try? String(valueToken)
841841
{
842842
metadata[key] = value
843843
}
@@ -849,7 +849,7 @@ extension ValkeyClusterSlotRange.Node {
849849
// Handle metadata as key-value pairs in array format (using MapStyleArray)
850850
let mapArray = MapStyleArray(underlying: array)
851851
for (key, valueToken) in mapArray {
852-
if let value = try? String(fromRESP: valueToken) {
852+
if let value = try? String(valueToken) {
853853
metadata[key] = value
854854
}
855855
}
@@ -879,7 +879,7 @@ struct MapStyleArray: Sequence {
879879

880880
mutating func next() -> (String, RESPToken)? {
881881
guard let nodeKey = self.underlying.next(),
882-
let key = try? String(fromRESP: nodeKey),
882+
let key = try? String(nodeKey),
883883
let nodeVal = self.underlying.next()
884884
else {
885885
return nil

Sources/Valkey/Commands/Custom/GenericCustomCommands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension SCAN {
1212
public let cursor: Int
1313
public let keys: RESPToken.Array
1414

15-
public init(fromRESP token: RESPToken) throws {
15+
public init(_ token: RESPToken) throws {
1616
(self.cursor, self.keys) = try token.decodeArrayElements(as: (Int, RESPToken.Array).self)
1717
}
1818
}

Sources/Valkey/Commands/Custom/GeoCustomCommands.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct GeoCoordinates: RESPTokenDecodable, Sendable {
1313
public let longitude: Double
1414
public let latitude: Double
1515

16-
public init(fromRESP token: RESPToken) throws {
16+
public init(_ token: RESPToken) throws {
1717
(self.longitude, self.latitude) = try token.decodeArrayElements()
1818
}
1919
}
@@ -41,14 +41,14 @@ extension GEOSEARCH {
4141
public let member: String
4242
public let attributes: [RESPToken]
4343

44-
public init(fromRESP token: RESPToken) throws {
44+
public init(_ token: RESPToken) throws {
4545
switch token.value {
4646
case .array(let array):
4747
var arrayIterator = array.makeIterator()
4848
guard let member = arrayIterator.next() else {
4949
throw RESPDecodeError.invalidArraySize(array, expectedSize: 1)
5050
}
51-
self.member = try String(fromRESP: member)
51+
self.member = try String(member)
5252
self.attributes = array.dropFirst().map { $0 }
5353

5454
case .bulkString(let buffer):

Sources/Valkey/Commands/Custom/HashCustomCommands.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct HashEntry: RESPTokenDecodable, Sendable {
1818
self.value = value
1919
}
2020

21-
public init(fromRESP token: RESPToken) throws {
21+
public init(_ token: RESPToken) throws {
2222
switch token.value {
2323
case .array(let array):
2424
(self.field, self.value) = try array.decodeElements()
@@ -34,7 +34,7 @@ extension HSCAN {
3434
/// List of members and possibly scores.
3535
public let elements: RESPToken.Array
3636

37-
public init(fromRESP token: RESPToken) throws {
37+
public init(_ token: RESPToken) throws {
3838
self.elements = try token.decode(as: RESPToken.Array.self)
3939
}
4040

@@ -49,8 +49,8 @@ extension HSCAN {
4949
public func withValues() throws -> [HashEntry] {
5050
var array: [HashEntry] = []
5151
for respElement in try self.elements.asMap() {
52-
let field = try RESPBulkString(fromRESP: respElement.key)
53-
let value = try RESPBulkString(fromRESP: respElement.value)
52+
let field = try RESPBulkString(respElement.key)
53+
let value = try RESPBulkString(respElement.value)
5454
array.append(.init(field: field, value: value))
5555
}
5656
return array
@@ -61,7 +61,7 @@ extension HSCAN {
6161
/// Sorted set members
6262
public let members: Members
6363

64-
public init(fromRESP token: RESPToken) throws {
64+
public init(_ token: RESPToken) throws {
6565
(self.cursor, self.members) = try token.decodeArrayElements()
6666
}
6767
}
@@ -73,7 +73,7 @@ extension HRANDFIELD {
7373
/// The raw RESP token containing the response
7474
public let token: RESPToken
7575

76-
public init(fromRESP token: RESPToken) throws {
76+
public init(_ token: RESPToken) throws {
7777
self.token = token
7878
}
7979

@@ -85,15 +85,15 @@ extension HRANDFIELD {
8585
if token.value == .null {
8686
return nil
8787
}
88-
return try RESPBulkString(fromRESP: token)
88+
return try RESPBulkString(token)
8989
}
9090

9191
/// Get multiple random fields when HRANDFIELD was called with COUNT but without WITHVALUES
9292
/// - Returns: Array of field names as RESPBulkString, or empty array if key doesn't exist
9393
/// - Throws: RESPDecodeError if response format is unexpected
9494
@inlinable
9595
public func multipleFields() throws -> [RESPBulkString]? {
96-
try [RESPBulkString]?(fromRESP: token)
96+
try [RESPBulkString]?(token)
9797
}
9898

9999
/// Get multiple random field-value pairs when HRANDFIELD was called with COUNT and WITHVALUES
@@ -116,7 +116,7 @@ extension HRANDFIELD {
116116
switch firstElement.value {
117117
case .array:
118118
// Array of arrays format - can use HashEntry decode
119-
return try [HashEntry]?(fromRESP: token)
119+
return try [HashEntry]?(token)
120120
default:
121121
// Flat array format - handle manually
122122
return try _decodeFlatArrayFormat(array)
@@ -141,8 +141,8 @@ extension HRANDFIELD {
141141
// Iterate over pairs
142142
var iterator = array.makeIterator()
143143
while let field = iterator.next(), let value = iterator.next() {
144-
let fieldBuffer = try RESPBulkString(fromRESP: field)
145-
let valueBuffer = try RESPBulkString(fromRESP: value)
144+
let fieldBuffer = try RESPBulkString(field)
145+
let valueBuffer = try RESPBulkString(value)
146146
entries.append(HashEntry(field: fieldBuffer, value: valueBuffer))
147147
}
148148

Sources/Valkey/Commands/Custom/ListCustomCommands.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public struct ListEntry: RESPTokenDecodable, Sendable {
1414
public let key: ValkeyKey
1515
public let value: RESPBulkString
1616

17-
public init(fromRESP token: RESPToken) throws {
17+
public init(_ token: RESPToken) throws {
1818
(self.key, self.value) = try token.decodeArrayElements()
1919
}
2020
}
@@ -31,7 +31,7 @@ extension LMPOP {
3131
public let key: ValkeyKey
3232
public let values: RESPToken.Array
3333

34-
public init(fromRESP token: RESPToken) throws {
34+
public init(_ token: RESPToken) throws {
3535
switch token.value {
3636
case .array(let array):
3737
(self.key, self.values) = try array.decodeElements()

0 commit comments

Comments
 (0)