diff --git a/src/capnp/InputStreamMessageReader.java b/src/capnp/InputStreamMessageReader.java index 44b1592..4f7019b 100644 --- a/src/capnp/InputStreamMessageReader.java +++ b/src/capnp/InputStreamMessageReader.java @@ -26,9 +26,7 @@ public class InputStreamMessageReader { static ByteBuffer makeByteBuffer(byte[] bytes) { ByteBuffer result = ByteBuffer.wrap(bytes); - - // something odd is happening here. - // result.order(ByteOrder.LITTLE_ENDIAN); + result.order(ByteOrder.LITTLE_ENDIAN); return result; } @@ -37,15 +35,11 @@ public class InputStreamMessageReader { int segmentCount = 1 + firstWord.getInt(0); - System.out.println("segmentCount = " + segmentCount); - int segment0Size = 0; if (segmentCount > 0) { - segment0Size = firstWord.getInt(1); + segment0Size = firstWord.getInt(4); } - System.out.println("segment0Size = " + segment0Size); - int totalWords = segment0Size; if (segmentCount > 512) { @@ -57,7 +51,7 @@ public class InputStreamMessageReader { if (segmentCount > 1) { ByteBuffer moreSizesRaw = makeByteBuffer(readExact(is, 4 * (segmentCount & ~1))); for(int ii = 0; ii < segmentCount - 1; ++ii) { - int size = moreSizesRaw.getInt(ii); + int size = moreSizesRaw.getInt(ii * 4); moreSizes.add(size); totalWords += size; } diff --git a/src/capnp/ListPointer.java b/src/capnp/ListPointer.java index 60cbf37..272981b 100644 --- a/src/capnp/ListPointer.java +++ b/src/capnp/ListPointer.java @@ -2,18 +2,19 @@ package capnp; import java.nio.ByteBuffer; -class ListPointer extends WirePointer { +class ListPointer { + public WirePointer ptr; - public ListPointer(ByteBuffer buffer, int buffer_offset) { - super(buffer, buffer_offset); + public ListPointer(WirePointer ptr) { + this.ptr = ptr; } public byte elementSize() { - return (byte)(this.buffer.getInt(buffer_offset * 2 + 1) & 7); + return (byte)(this.ptr.buffer.getInt(this.ptr.buffer_offset * 8 + 4) & 7); } public int elementCount() { - return this.buffer.getInt(buffer_offset * 2 + 1) >> 3; + return this.ptr.buffer.getInt(this.ptr.buffer_offset * 8 + 4) >> 3; } public int inlineCompositeWordCount() { diff --git a/src/capnp/StructPointer.java b/src/capnp/StructPointer.java index e22795f..9cdf5b0 100644 --- a/src/capnp/StructPointer.java +++ b/src/capnp/StructPointer.java @@ -10,11 +10,11 @@ class StructPointer{ } public short dataSize() { - return this.ptr.buffer.getShort(this.ptr.buffer_offset * 4 + 2); + return this.ptr.buffer.getShort(this.ptr.buffer_offset * 8 + 4); } public short ptrCount() { - return this.ptr.buffer.getShort(this.ptr.buffer_offset * 4 + 3); + return this.ptr.buffer.getShort(this.ptr.buffer_offset * 8 + 6); } public int wordSize() { diff --git a/src/capnp/StructReader.java b/src/capnp/StructReader.java index ffee244..b9c541c 100644 --- a/src/capnp/StructReader.java +++ b/src/capnp/StructReader.java @@ -46,7 +46,7 @@ public class StructReader { public byte getShortField(int offset) { if ((offset + 1) * 16 <= this.dataSize) { - return this.segment.ptr.get(this.data / 2 + offset); + return this.segment.ptr.get(this.data + offset * 2); } else { return 0; } @@ -54,7 +54,7 @@ public class StructReader { public int getIntField(int offset) { if ((offset + 1) * 32 <= this.dataSize) { - return this.segment.ptr.getInt((this.data / 4) + offset); + return this.segment.ptr.getInt(this.data + offset * 4); } else { return 0; } @@ -66,6 +66,7 @@ public class StructReader { this.pointers + ptrIndex, this.nestingLimit); } else { + System.out.println("pointer count: " + this.pointerCount); return new PointerReader(); } } diff --git a/src/capnp/Text.java b/src/capnp/Text.java index f07a384..273dce2 100644 --- a/src/capnp/Text.java +++ b/src/capnp/Text.java @@ -10,8 +10,8 @@ public class Text { public final int size; // in bytes public Reader(ListPointer ptr) { - this.buffer = ptr.buffer; - this.offset = ptr.buffer_offset * 8; + this.buffer = ptr.ptr.buffer; + this.offset = ptr.ptr.buffer_offset * 8; this.size = ptr.elementCount(); } diff --git a/src/capnp/WireHelpers.java b/src/capnp/WireHelpers.java index 6673c83..e035dd8 100644 --- a/src/capnp/WireHelpers.java +++ b/src/capnp/WireHelpers.java @@ -30,7 +30,7 @@ class WireHelpers { // TODO check for null, follow fars, nestingLimit - ListPointer listPtr = (ListPointer)ref; + ListPointer listPtr = new ListPointer(ref); WordPointer ptr = ref.target(); @@ -70,7 +70,7 @@ class WireHelpers { public static Text.Reader readTextPointer(SegmentReader segment, WirePointer ref) { ref.target(); - ListPointer listPtr = (ListPointer)ref; + ListPointer listPtr = new ListPointer(ref); return new Text.Reader(listPtr); } }