mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-20 09:17:29 +07:00
Tightened up field visibility
Tightened up field visibility ByteInput#bitInput set via bitInput(BitInput) which enforces invariants
This commit is contained in:
parent
afd7bafa12
commit
20ae623fe7
@ -22,10 +22,9 @@ public class BitInput {
|
||||
}
|
||||
}
|
||||
|
||||
final ByteInput byteInput;
|
||||
final long numBits;
|
||||
long bitsRead;
|
||||
|
||||
private final ByteInput byteInput;
|
||||
private final long numBits;
|
||||
private long bitsRead;
|
||||
private int bitsCached;
|
||||
private long cache;
|
||||
|
||||
@ -48,6 +47,10 @@ public class BitInput {
|
||||
this.numBits = numBits;
|
||||
}
|
||||
|
||||
ByteInput byteInput() {
|
||||
return byteInput;
|
||||
}
|
||||
|
||||
public int bytesRead() {
|
||||
return byteInput.bytesRead();
|
||||
}
|
||||
@ -136,7 +139,7 @@ public class BitInput {
|
||||
// length should include the last byte that bits belong (round to ceil)
|
||||
final long numBytes = (numBits - bitsCached + Byte.SIZE - 1) / Byte.SIZE;
|
||||
final ByteInput byteInput = this.byteInput.readSlice(numBytes);
|
||||
return byteInput.bitInput = new BitInput(byteInput, bitsCached, cache, numBits);
|
||||
return byteInput.bitInput(new BitInput(byteInput, bitsCached, cache, numBits));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,13 +17,19 @@ public class ByteInput {
|
||||
return bytes == null ? emptyByteInput() : new ByteInput(Unpooled.wrappedBuffer(bytes));
|
||||
}
|
||||
|
||||
final ByteBuf buffer;
|
||||
BitInput bitInput;
|
||||
private final ByteBuf buffer;
|
||||
private BitInput bitInput;
|
||||
|
||||
ByteInput(ByteBuf buffer) {
|
||||
this.buffer = buffer;
|
||||
}
|
||||
|
||||
BitInput bitInput(BitInput bitInput) {
|
||||
assert this.bitInput == null : "this.bitInput(" + this.bitInput + ") != null";
|
||||
assert bitInput.byteInput() == this : "bitInput.byteInput()(" + bitInput.byteInput() + ") != this(" + this + ")";
|
||||
return this.bitInput = bitInput;
|
||||
}
|
||||
|
||||
public int bytesRead() {
|
||||
return buffer.readerIndex();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user