fixing bugs

This commit is contained in:
David Renshaw 2014-05-10 22:33:24 -04:00
parent 2fcfecc403
commit ca2231587a
3 changed files with 16 additions and 9 deletions

View file

@ -26,20 +26,26 @@ public class InputStreamMessageReader {
static ByteBuffer makeByteBuffer(byte[] bytes) { static ByteBuffer makeByteBuffer(byte[] bytes) {
ByteBuffer result = ByteBuffer.wrap(bytes); ByteBuffer result = ByteBuffer.wrap(bytes);
result.order(ByteOrder.LITTLE_ENDIAN);
// something odd is happening here.
// result.order(ByteOrder.LITTLE_ENDIAN);
return result; return result;
} }
public static MessageReader create(InputStream is) throws IOException { public static MessageReader create(InputStream is) throws IOException {
ByteBuffer firstWord = makeByteBuffer(readExact(is, 8)); ByteBuffer firstWord = makeByteBuffer(readExact(is, 8));
int segmentCount = 1 + firstWord.getInt(); int segmentCount = 1 + firstWord.getInt(0);
System.out.println("segmentCount = " + segmentCount);
int segment0Size = 0; int segment0Size = 0;
if (segmentCount > 0) { if (segmentCount > 0) {
segment0Size = firstWord.getInt(1); segment0Size = firstWord.getInt(1);
} }
System.out.println("segment0Size = " + segment0Size);
int totalWords = segment0Size; int totalWords = segment0Size;
if (segmentCount > 512) { if (segmentCount > 512) {

View file

@ -2,18 +2,19 @@ package capnp;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
class StructPointer extends WirePointer { class StructPointer{
public WirePointer ptr;
public StructPointer(ByteBuffer buffer, int buffer_offset) { public StructPointer(WirePointer ptr) {
super(buffer, buffer_offset); this.ptr = ptr;
} }
public short dataSize() { public short dataSize() {
return this.buffer.getShort(this.buffer_offset * 4 + 2); return this.ptr.buffer.getShort(this.ptr.buffer_offset * 4 + 2);
} }
public short ptrCount() { public short ptrCount() {
return this.buffer.getShort(this.buffer_offset * 4 + 3); return this.ptr.buffer.getShort(this.ptr.buffer_offset * 4 + 3);
} }
public int wordSize() { public int wordSize() {

View file

@ -9,7 +9,7 @@ class WireHelpers {
// TODO error handling // TODO error handling
WordPointer ptr = ref.target(); WordPointer ptr = ref.target();
StructPointer structPtr = (StructPointer)ref; StructPointer structPtr = new StructPointer(ref);
int dataSizeWords = structPtr.dataSize(); int dataSizeWords = structPtr.dataSize();
return new StructReader(segment, return new StructReader(segment,
@ -44,7 +44,7 @@ class WireHelpers {
// TODO bounds check // TODO bounds check
int size = tag.inlineCompositeListElementCount(); int size = tag.inlineCompositeListElementCount();
StructPointer structPtr = (StructPointer)tag; StructPointer structPtr = new StructPointer(tag);
int wordsPerElement = structPtr.wordSize(); int wordsPerElement = structPtr.wordSize();
// TODO check that elemements do not overrun word count // TODO check that elemements do not overrun word count