Skip to content

Commit ef72496

Browse files
keremncjenkins
authored andcommitted
util/util-core: Increase visibility of Buf.Composite
When Bufs are built by concatenation they are usually represented as a `Buf.Composite`. Since this class is private, it is difficult to consume the underlying discontiguous Bufs without copying. Making the class public allows constructions like: ``` def consume(buf: Buf)(eat: Array[Byte] => Unit): Unit = buf match { case array: Buf.ByteArray => eat(array.unsafeRawByteArray) // [unsafeArrayOffset + length] case Buf.ByteBuffer(bb) if bb.hasArray => eat(bb.array()) // [+ bb.arrayOffset()] case Buf.Composite(bufs, _) => bufs.foreach(consume(_)(eat)) case _ => eat(Buf.ByteArray.Owned.extract(buf)) } ``` Differential Revision: https://phabricator.twitter.biz/D1198118
1 parent 81bab63 commit ef72496

File tree

1 file changed

+1
-1
lines changed
  • util-core/src/main/scala/com/twitter/io

1 file changed

+1
-1
lines changed

util-core/src/main/scala/com/twitter/io/Buf.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ object Buf {
404404
def length: Int = 3
405405
}
406406

407-
private final case class Composite(bufs: IndexedSeq[Buf], length: Int) extends Buf {
407+
final case class Composite(bufs: IndexedSeq[Buf], length: Int) extends Buf {
408408
// the factory method requires non-empty Bufs
409409
override def isEmpty: Boolean = false
410410

0 commit comments

Comments
 (0)