Commit ef72496
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/D11981181 parent 81bab63 commit ef72496
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| |||
0 commit comments