Skip to content

Commit

Permalink
Accept chars wherever integral value is expected
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSpanel committed Nov 11, 2020
1 parent 8c78d53 commit 12aa6a9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/scala/io/bullet/borer/Reader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,17 @@ final class InputReader[Config <: Reader.Config](
@inline def hasByte(value: Byte): Boolean = hasByte && receptacle.intValue == value.toInt
@inline def tryReadByte(value: Byte): Boolean = clearIfTrue(hasByte(value))

private def readLongFromString(): Long = {
clearDataItem()
new String(receptacle.charBufValue, 0, receptacle.intValue).toLong
}

def readShort(): Short =
if (hasShort) {
clearDataItem()
receptacle.intValue.toShort
} else if (hasChars) {
readLongFromString().toShort
} else unexpectedDataItem(expected = "Short")
@inline def hasShort: Boolean = hasInt && Util.isShort(receptacle.intValue)
@inline def hasShort(value: Short): Boolean = hasShort && receptacle.intValue == value.toInt
Expand All @@ -141,6 +148,8 @@ final class InputReader[Config <: Reader.Config](
if (hasInt) {
clearDataItem()
receptacle.intValue
} else if (hasChars) {
readLongFromString().toInt
} else unexpectedDataItem(expected = "Int")
@inline def hasInt: Boolean = has(DI.Int)
@inline def hasInt(value: Int): Boolean = hasInt && receptacle.intValue == value
Expand All @@ -151,6 +160,8 @@ final class InputReader[Config <: Reader.Config](
val result = if (hasInt) receptacle.intValue.toLong else receptacle.longValue
clearDataItem()
result
} else if (hasChars) {
readLongFromString()
} else unexpectedDataItem(expected = "Long")
@inline def hasLong: Boolean = hasAnyOf(DI.Int | DI.Long)

Expand Down

0 comments on commit 12aa6a9

Please sign in to comment.