Skip to content

Commit dd58fb2

Browse files
committed
Split NIO ChannelHandler conformances into separate files from RESP Encoder/Decoder
1 parent 5bdb929 commit dd58fb2

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import NIO
2+
3+
extension RESPDecoder: ByteToMessageDecoder {
4+
/// `ByteToMessageDecoder.InboundOut`
5+
public typealias InboundOut = RESPValue
6+
7+
/// See `ByteToMessageDecoder.decode(ctx:buffer:)`
8+
public func decode(ctx: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
9+
var position = 0
10+
11+
switch try parse(at: &position, from: &buffer) {
12+
case .notYetParsed:
13+
return .needMoreData
14+
15+
case .parsed(let RESPValue):
16+
ctx.fireChannelRead(wrapInboundOut(RESPValue))
17+
buffer.moveReaderIndex(forwardBy: position)
18+
return .continue
19+
}
20+
}
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import NIO
2+
3+
extension RESPEncoder: MessageToByteEncoder {
4+
/// See `MessageToByteEncoder.OutboundIn`
5+
public typealias OutboundIn = RESPValue
6+
7+
/// See `RESPEncoder.encode(ctx:data:out:)`
8+
public func encode(ctx: ChannelHandlerContext, data: RESPValue, out: inout ByteBuffer) throws {
9+
out.write(bytes: encode(data))
10+
}
11+
}

Sources/NIORedis/ChannelHandlers/RESPDecoder.swift renamed to Sources/NIORedis/RESP/RESPDecoder.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,3 @@ public final class RESPDecoder {
186186
return .parsed(.array(values))
187187
}
188188
}
189-
190-
extension RESPDecoder: ByteToMessageDecoder {
191-
/// `ByteToMessageDecoder.InboundOut`
192-
public typealias InboundOut = RESPValue
193-
194-
/// See `ByteToMessageDecoder.decode(ctx:buffer:)`
195-
public func decode(ctx: ChannelHandlerContext, buffer: inout ByteBuffer) throws -> DecodingState {
196-
var position = 0
197-
198-
switch try parse(at: &position, from: &buffer) {
199-
case .notYetParsed:
200-
return .needMoreData
201-
202-
case .parsed(let RESPValue):
203-
ctx.fireChannelRead(wrapInboundOut(RESPValue))
204-
buffer.moveReaderIndex(forwardBy: position)
205-
return .continue
206-
}
207-
}
208-
}

Sources/NIORedis/ChannelHandlers/RESPEncoder.swift renamed to Sources/NIORedis/RESP/RESPEncoder.swift

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import Foundation
2-
import NIO
32

43
/// Translates `RedisValue` into raw bytes, formatted according to the Redis Serialization Protocol (RESP).
54
///
65
/// See: https://redis.io/topics/protocol
76
public final class RESPEncoder {
87
public init() { }
9-
8+
109
/// Encodes the `RedisValue` to bytes, following the RESP specification.
1110
///
1211
/// See https://redis.io/topics/protocol
@@ -35,15 +34,3 @@ public final class RESPEncoder {
3534
}
3635
}
3736
}
38-
39-
// MARK: MessageToByteEncoder
40-
41-
extension RESPEncoder: MessageToByteEncoder {
42-
/// See `MessageToByteEncoder.OutboundIn`
43-
public typealias OutboundIn = RESPValue
44-
45-
/// See `RESPEncoder.encode(ctx:data:out:)`
46-
public func encode(ctx: ChannelHandlerContext, data: RESPValue, out: inout ByteBuffer) throws {
47-
out.write(bytes: encode(data))
48-
}
49-
}

0 commit comments

Comments
 (0)