diff --git a/runtime/src/main/java/org/capnproto/PackedInputStream.java b/runtime/src/main/java/org/capnproto/PackedInputStream.java index c15cfc1..f0f73e9 100644 --- a/runtime/src/main/java/org/capnproto/PackedInputStream.java +++ b/runtime/src/main/java/org/capnproto/PackedInputStream.java @@ -33,11 +33,53 @@ public final class PackedInputStream implements ReadableByteChannel { //if (outBuf if (inBuf.remaining() < 10) { + if (out >= outEnd) { + return len; + } + + if (inBuf.remaining() == 0) { + // refresh buffer... + continue; + } + + //# We have at least 1, but not 10, bytes available. We need to read + //# slowly, doing a bounds check on each byte. + // TODO + } else { + + tag = inBuf.get(); + for (int n = 0; n < 8; ++n) { + boolean isNonzero = (tag & (1 << n)) != 0; + // ... + } + } - // TODO + if (tag == 0) { + if (inBuf.remaining() == 0) { + throw new Error("Should always have non-empty buffer here."); + } + int runLength = inBuf.get() * 8; + + if (runLength > outEnd - out) { + throw new Error("Packed input did not end cleanly on a segment boundary"); + } + + + } else if (tag == (byte)0xff) { + + int runLength = inBuf.get() * 8; + + + if (inBuf.remaining() >= runLength) { + + } else { + + } + + } if (out == outEnd) { return len;