Skip to content

Commit

Permalink
Resp Bound Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDavenport committed Aug 10, 2020
1 parent 65474d9 commit a0c1b52
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/src/main/scala/io/chrisdavenport/rediculous/Resp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object Resp {
}

def parse(arr: SArray[Byte]): RespParserResult[Resp] = {
if (arr.size >= 0) {
if (arr.size > 0) {
val switchVal = arr(0)
switchVal match {
case Plus => SimpleString.parse(arr)
Expand All @@ -65,6 +65,7 @@ object Resp {
}

// First Byte is +
// +foo/r/n
case class SimpleString(value: String) extends Resp
object SimpleString {
def encode(s: SimpleString): SArray[Byte] = {
Expand Down Expand Up @@ -139,6 +140,7 @@ object Resp {
}
}
// First Byte is $
// $3/r/n/foo/r/n
case class BulkString(value: Option[String]) extends Resp
object BulkString {
def encode(b: BulkString): SArray[Byte] = {
Expand All @@ -162,10 +164,10 @@ object Resp {
idx += 2
}
if (length == -1) ParseComplete(BulkString(None), arr.drop(idx))
else {
else if (idx + length + 2 < arr.size) {
val out = new String(arr, idx, length)
ParseComplete(BulkString(Some(out)), arr.drop(idx + length + 2))
}
} else ParseIncomplete(arr)
} catch {
case scala.util.control.NonFatal(e) =>
ParseError(s"Error in BulkString Processing: ${e.getMessage}", Some(e))
Expand Down

0 comments on commit a0c1b52

Please sign in to comment.