Split ByteString for 2.13 and 2.12
see https://github.com/scala/bug/issues/10973 for indexWhere/indexOf
This commit is contained in:
parent
4c7440c952
commit
fcde44f424
5 changed files with 1271 additions and 8 deletions
1251
akka-actor/src/main/scala-2.13+/akka/util/ByteString.scala
Normal file
1251
akka-actor/src/main/scala-2.13+/akka/util/ByteString.scala
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -33,8 +33,9 @@ object ByteIterator {
|
|||
|
||||
@inline final def head: Byte = array(from)
|
||||
|
||||
@throws[NoSuchElementException]
|
||||
final def next(): Byte = {
|
||||
if (!hasNext) Iterator.empty.next
|
||||
if (!hasNext) throw new NoSuchElementException("next on empty iterator")
|
||||
else { val i = from; from = from + 1; array(i) }
|
||||
}
|
||||
|
||||
|
|
@ -103,11 +104,12 @@ object ByteIterator {
|
|||
result
|
||||
}
|
||||
|
||||
@throws[NoSuchElementException]
|
||||
def getBytes(xs: Array[Byte], offset: Int, n: Int): this.type = {
|
||||
if (n <= this.len) {
|
||||
Array.copy(this.array, this.from, xs, offset, n)
|
||||
this.drop(n)
|
||||
} else Iterator.empty.next
|
||||
} else throw new NoSuchElementException("next on empty iterator")
|
||||
}
|
||||
|
||||
private def wrappedByteBuffer: ByteBuffer = ByteBuffer.wrap(array, from, len).asReadOnlyBuffer
|
||||
|
|
@ -437,16 +439,16 @@ abstract class ByteIterator extends BufferedIterator[Byte] {
|
|||
(this, that)
|
||||
}
|
||||
|
||||
override def indexWhere(p: Byte ⇒ Boolean): Int = {
|
||||
var index = 0
|
||||
override def indexWhere(p: Byte ⇒ Boolean, from: Int = 0): Int = {
|
||||
var index = from
|
||||
var found = false
|
||||
while (!found && hasNext) if (p(next())) { found = true } else { index += 1 }
|
||||
if (found) index else -1
|
||||
}
|
||||
|
||||
def indexOf(elem: Byte): Int = indexWhere { _ == elem }
|
||||
override def indexOf(elem: Byte, from: Int = 0): Int = indexWhere(_ == elem, from)
|
||||
|
||||
override def indexOf[B >: Byte](elem: B): Int = indexWhere { _ == elem }
|
||||
override def indexOf[B >: Byte](elem: B, from: Int = 0): Int = indexWhere(_ == elem, from)
|
||||
|
||||
def toByteString: ByteString
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ private[akka] object PrettyByteString {
|
|||
|
||||
def formatLine(bs: ByteString): String = {
|
||||
val data = bs.toSeq
|
||||
val hex = data.map(asHex).mkString(" ")
|
||||
val ascii = data.map(asASCII).mkString
|
||||
val hex = data.map(asHex _).mkString(" ")
|
||||
val ascii = data.map(asASCII _).mkString
|
||||
f"$indent%s $hex%-48s | $ascii"
|
||||
}
|
||||
def formatBytes(bs: ByteString): String =
|
||||
|
|
|
|||
|
|
@ -127,6 +127,16 @@ object AkkaBuild {
|
|||
|
||||
crossVersion := CrossVersion.binary,
|
||||
|
||||
// Adds a `src/main/scala-2.13+` source directory for Scala 2.13 and newer
|
||||
// and a `src/main/scala-2.13-` source directory for Scala version older than 2.13
|
||||
unmanagedSourceDirectories in Compile += {
|
||||
val sourceDir = (sourceDirectory in Compile).value
|
||||
CrossVersion.partialVersion(scalaVersion.value) match {
|
||||
case Some((2, n)) if n >= 13 => sourceDir / "scala-2.13+"
|
||||
case _ => sourceDir / "scala-2.13-"
|
||||
}
|
||||
},
|
||||
|
||||
ivyLoggingLevel in ThisBuild := UpdateLogging.Quiet,
|
||||
|
||||
licenses := Seq(("Apache License, Version 2.0", url("http://www.apache.org/licenses/LICENSE-2.0"))),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue