diff --git a/core/src/com/riiablo/io/nio/BitInput.java b/core/src/com/riiablo/io/nio/BitInput.java index e3c2bd49..b3540b4b 100644 --- a/core/src/com/riiablo/io/nio/BitInput.java +++ b/core/src/com/riiablo/io/nio/BitInput.java @@ -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)); } /** diff --git a/core/src/com/riiablo/io/nio/ByteInput.java b/core/src/com/riiablo/io/nio/ByteInput.java index d33c9907..30b22121 100644 --- a/core/src/com/riiablo/io/nio/ByteInput.java +++ b/core/src/com/riiablo/io/nio/ByteInput.java @@ -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(); }