mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-05 07:48:05 +07:00
Implemented BitOutput#skipBits(long) and ByteOutput#skipBytes(int)
This commit is contained in:
@ -63,6 +63,31 @@ public class BitOutput {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BitOutput skipBits(long bits) {
|
||||||
|
if (bits < 0) throw new IllegalArgumentException("bits(" + bits + ") < " + 0);
|
||||||
|
if (bits == 0) return this;
|
||||||
|
|
||||||
|
// aligns bit stream for multi-byte skipping
|
||||||
|
assert bitsCached < Byte.SIZE : "bitsCached(" + bitsCached + ") > " + (Byte.SIZE - 1);
|
||||||
|
final int bitsUncached = Byte.SIZE - bitsCached;
|
||||||
|
if (bits >= bitsUncached) {
|
||||||
|
bits -= bitsUncached;
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
// skips multiple bytes
|
||||||
|
final long startingBitsWritten = bitsWritten;
|
||||||
|
final long bytes = bits / Byte.SIZE;
|
||||||
|
assert bytes <= Integer.MAX_VALUE : "bytes(" + bytes + ") > Integer.MAX_VALUE";
|
||||||
|
if (bytes > 0) align().skipBytes((int) bytes);
|
||||||
|
|
||||||
|
// skips overflow bits
|
||||||
|
final long overflowBits = (startingBitsWritten + bits) - bitsWritten;
|
||||||
|
assert overflowBits < Byte.SIZE : "overflowBits(" + overflowBits + ") > " + (Byte.SIZE - 1);
|
||||||
|
if (overflowBits > 0) _writeRaw(0L, (int) overflowBits);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
void _writeUnsigned(long value, int bits) {
|
void _writeUnsigned(long value, int bits) {
|
||||||
assert bits >= 0 : "bits(" + bits + ") < " + 0;
|
assert bits >= 0 : "bits(" + bits + ") < " + 0;
|
||||||
assert bits < Long.SIZE : "bits(" + bits + ") > " + (Long.SIZE - 1);
|
assert bits < Long.SIZE : "bits(" + bits + ") > " + (Long.SIZE - 1);
|
||||||
|
@ -30,6 +30,12 @@ public class ByteOutput {
|
|||||||
return bitOutput();
|
return bitOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ByteOutput skipBytes(int bytes) {
|
||||||
|
incrementBitsWritten((long) bytes * Byte.SIZE);
|
||||||
|
buffer.writeZero(bytes);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
long incrementBitsWritten(long bits) {
|
long incrementBitsWritten(long bits) {
|
||||||
assert (bits & (Byte.SIZE - 1)) == 0;
|
assert (bits & (Byte.SIZE - 1)) == 0;
|
||||||
if (bitOutput == null) return 0;
|
if (bitOutput == null) return 0;
|
||||||
|
Reference in New Issue
Block a user