Skip to content

Commit 15859bc

Browse files
committed
Fix decoding bug with arrays and remove unnecessary extensions
1 parent 7b1d2b4 commit 15859bc

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

Sources/NIORedis/Coders/RedisDataDecoder.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extension RedisDataDecoder {
4646
}
4747

4848
func _parse(at position: inout Int, from buffer: inout ByteBuffer) throws -> _RedisDataDecodingState {
49-
guard let token = buffer.copyByte(at: position) else { return .notYetParsed }
49+
guard let token = buffer.copyBytes(at: position, length: 1)?.first else { return .notYetParsed }
5050

5151
position += 1
5252

@@ -188,19 +188,6 @@ extension RedisDataDecoder {
188188
}
189189

190190
private extension ByteBuffer {
191-
/// Copies the `ByteBuffer` from the current `readerIndex`.
192-
///
193-
/// buffer.copyBytes(count: 5)
194-
/// // Optional(5 bytes)
195-
///
196-
/// - Parameters:
197-
/// - count: The number of bytes to copy
198-
/// - skipping: The amount of bytes to skip, defaulting to `0`.
199-
func copyBytes(count: Int, skipping: Int = 0) -> [UInt8]? {
200-
guard readableBytes >= count + skipping else { return nil }
201-
return getBytes(at: readerIndex + skipping, length: count)
202-
}
203-
204191
/// Copies bytes from the `ByteBuffer` from at the provided position, up to the length desired.
205192
///
206193
/// buffer.copyBytes(at: 3, length: 2)
@@ -213,15 +200,4 @@ private extension ByteBuffer {
213200
guard readableBytes >= offset + length else { return nil }
214201
return getBytes(at: offset + readerIndex, length: length)
215202
}
216-
217-
/// Copies the first byte from the `ByteBuffer` at the desired position.
218-
///
219-
/// buffer.copyByte(at: 3)
220-
/// // Optional(1 byte), assuming buffer contains 3 or more bytes
221-
///
222-
/// - Parameter at: The position offset of the byte to be copied from the buffer.
223-
func copyByte(at position: Int) -> UInt8? {
224-
guard readableBytes >= 1 else { return nil }
225-
return getBytes(at: position, length: 1)?.first
226-
}
227203
}

0 commit comments

Comments
 (0)