Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: Make
ProxyByteReader
and ProxyByteWriter
Public
Problem `ProxyByteReader` is incredibly useful for reading specialized information out of a `Buf` while still benefitting from all the already existing goodness that comes for free from the `ByteReader` implementation. However, it is not currently accessible to code outside of the `com.twitter` namespace. Solution Make `ProxyByteReader` and `ProxyByteWriter` both public, and modify `ProxyByteReader`s structure so that it aligns with `ProxyByteWriter`. Differential Revision: https://phabricator.twitter.biz/D622705
- Loading branch information
1 parent
955754d
commit 35abeca
Showing
4 changed files
with
83 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
util-core/src/main/scala/com/twitter/io/ProxyByteReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.twitter.io | ||
|
||
import java.nio.charset.Charset | ||
|
||
/** | ||
* A proxy [[ByteReader]] that forwards all calls to another [[ByteReader]]. | ||
* This is useful if you want to wrap-but-modify an existing [[ByteReader]]. | ||
*/ | ||
abstract class ProxyByteReader(underlying: ByteReader) extends ByteReader { | ||
|
||
def remaining: Int = underlying.remaining | ||
|
||
def remainingUntil(byte: Byte): Int = underlying.remainingUntil(byte) | ||
|
||
def readByte(): Byte = underlying.readByte() | ||
|
||
def readUnsignedByte(): Short = underlying.readUnsignedByte() | ||
|
||
def readShortBE(): Short = underlying.readShortBE() | ||
|
||
def readShortLE(): Short = underlying.readShortLE() | ||
|
||
def readUnsignedShortBE(): Int = underlying.readUnsignedShortBE() | ||
|
||
def readUnsignedShortLE(): Int = underlying.readUnsignedShortLE() | ||
|
||
def readMediumBE(): Int = underlying.readMediumBE() | ||
|
||
def readMediumLE(): Int = underlying.readMediumLE() | ||
|
||
def readUnsignedMediumBE(): Int = underlying.readUnsignedMediumBE() | ||
|
||
def readUnsignedMediumLE(): Int = underlying.readUnsignedMediumLE() | ||
|
||
def readIntBE(): Int = underlying.readIntBE() | ||
|
||
def readIntLE(): Int = underlying.readIntLE() | ||
|
||
def readUnsignedIntBE(): Long = underlying.readUnsignedIntBE() | ||
|
||
def readUnsignedIntLE(): Long = underlying.readUnsignedIntLE() | ||
|
||
def readLongBE(): Long = underlying.readLongBE() | ||
|
||
def readLongLE(): Long = underlying.readLongLE() | ||
|
||
def readUnsignedLongBE(): BigInt = underlying.readUnsignedLongBE() | ||
|
||
def readUnsignedLongLE(): BigInt = underlying.readUnsignedLongLE() | ||
|
||
def readFloatBE(): Float = underlying.readFloatBE() | ||
|
||
def readFloatLE(): Float = underlying.readFloatLE() | ||
|
||
def readDoubleBE(): Double = underlying.readDoubleBE() | ||
|
||
def readDoubleLE(): Double = underlying.readDoubleLE() | ||
|
||
def readBytes(n: Int): Buf = underlying.readBytes(n) | ||
|
||
def readString(bytes: Int, charset: Charset): String = underlying.readString(bytes, charset) | ||
|
||
def skip(n: Int): Unit = underlying.skip(n) | ||
|
||
def readAll(): Buf = underlying.readAll() | ||
|
||
def process(from: Int, until: Int, processor: Buf.Processor): Int = | ||
underlying.process(from, until, processor) | ||
|
||
def process(processor: Buf.Processor): Int = | ||
underlying.process(processor) | ||
|
||
def close(): Unit = underlying.close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters