@@ -128,23 +128,22 @@ extension RedisDataDecoder {
128
128
// Redis sends '-1' to represent a null string
129
129
guard size > - 1 else { return . parsed( . null) }
130
130
131
- // Redis can hold empty bulk strings, and represents it with a 0 size
132
- // so return an empty string
131
+ // verify that we have our expected bulk string message
132
+ // by adding the expected CRLF bytes to the parsed size
133
+ // even if the size is 0, Redis provides line endings (i.e. $0\r\n\r\n)
134
+ let readableByteCount = buffer. readableBytes - position
135
+ let expectedRemainingMessageSize = size + 2
136
+ guard readableByteCount >= expectedRemainingMessageSize else { return . notYetParsed }
137
+
133
138
guard size > 0 else {
134
139
// Move the tip of the message position
135
- // since size = 0, and we successfully parsed the size
136
- // the beginning of the next message should be 2 further (the final \r\n - $0\r\n\r\n)
137
140
position += 2
138
141
return . parsed( . bulkString( Data ( ) ) )
139
142
}
140
143
141
- // verify that we have at least our expected bulk string message
142
- // by adding the expected CRLF bytes to the parsed size
143
- let readableByteCount = buffer. readableBytes - position
144
- let expectedRemainingMessageSize = size + 2
145
- guard readableByteCount >= expectedRemainingMessageSize else { return . notYetParsed }
146
-
147
- guard let bytes = buffer. copyBytes ( at: position, length: expectedRemainingMessageSize) else { return . notYetParsed }
144
+ guard let bytes = buffer. copyBytes ( at: position, length: expectedRemainingMessageSize) else {
145
+ return . notYetParsed
146
+ }
148
147
149
148
// Move the tip of the message position for recursive parsing to just after the newline
150
149
// of the bulk string content
0 commit comments