aha, index is always in bytes
This commit is contained in:
parent
ca2231587a
commit
d230ea824a
6 changed files with 18 additions and 22 deletions
|
@ -26,9 +26,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,15 +35,11 @@ public class InputStreamMessageReader {
|
||||||
|
|
||||||
int segmentCount = 1 + firstWord.getInt(0);
|
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(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("segment0Size = " + segment0Size);
|
|
||||||
|
|
||||||
int totalWords = segment0Size;
|
int totalWords = segment0Size;
|
||||||
|
|
||||||
if (segmentCount > 512) {
|
if (segmentCount > 512) {
|
||||||
|
@ -57,7 +51,7 @@ public class InputStreamMessageReader {
|
||||||
if (segmentCount > 1) {
|
if (segmentCount > 1) {
|
||||||
ByteBuffer moreSizesRaw = makeByteBuffer(readExact(is, 4 * (segmentCount & ~1)));
|
ByteBuffer moreSizesRaw = makeByteBuffer(readExact(is, 4 * (segmentCount & ~1)));
|
||||||
for(int ii = 0; ii < segmentCount - 1; ++ii) {
|
for(int ii = 0; ii < segmentCount - 1; ++ii) {
|
||||||
int size = moreSizesRaw.getInt(ii);
|
int size = moreSizesRaw.getInt(ii * 4);
|
||||||
moreSizes.add(size);
|
moreSizes.add(size);
|
||||||
totalWords += size;
|
totalWords += size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,19 @@ package capnp;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
class ListPointer extends WirePointer {
|
class ListPointer {
|
||||||
|
public WirePointer ptr;
|
||||||
|
|
||||||
public ListPointer(ByteBuffer buffer, int buffer_offset) {
|
public ListPointer(WirePointer ptr) {
|
||||||
super(buffer, buffer_offset);
|
this.ptr = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte elementSize() {
|
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() {
|
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() {
|
public int inlineCompositeWordCount() {
|
||||||
|
|
|
@ -10,11 +10,11 @@ class StructPointer{
|
||||||
}
|
}
|
||||||
|
|
||||||
public short dataSize() {
|
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() {
|
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() {
|
public int wordSize() {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class StructReader {
|
||||||
|
|
||||||
public byte getShortField(int offset) {
|
public byte getShortField(int offset) {
|
||||||
if ((offset + 1) * 16 <= this.dataSize) {
|
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 {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class StructReader {
|
||||||
|
|
||||||
public int getIntField(int offset) {
|
public int getIntField(int offset) {
|
||||||
if ((offset + 1) * 32 <= this.dataSize) {
|
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 {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@ public class StructReader {
|
||||||
this.pointers + ptrIndex,
|
this.pointers + ptrIndex,
|
||||||
this.nestingLimit);
|
this.nestingLimit);
|
||||||
} else {
|
} else {
|
||||||
|
System.out.println("pointer count: " + this.pointerCount);
|
||||||
return new PointerReader();
|
return new PointerReader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ public class Text {
|
||||||
public final int size; // in bytes
|
public final int size; // in bytes
|
||||||
|
|
||||||
public Reader(ListPointer ptr) {
|
public Reader(ListPointer ptr) {
|
||||||
this.buffer = ptr.buffer;
|
this.buffer = ptr.ptr.buffer;
|
||||||
this.offset = ptr.buffer_offset * 8;
|
this.offset = ptr.ptr.buffer_offset * 8;
|
||||||
this.size = ptr.elementCount();
|
this.size = ptr.elementCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ class WireHelpers {
|
||||||
|
|
||||||
// TODO check for null, follow fars, nestingLimit
|
// TODO check for null, follow fars, nestingLimit
|
||||||
|
|
||||||
ListPointer listPtr = (ListPointer)ref;
|
ListPointer listPtr = new ListPointer(ref);
|
||||||
|
|
||||||
WordPointer ptr = ref.target();
|
WordPointer ptr = ref.target();
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class WireHelpers {
|
||||||
public static Text.Reader readTextPointer(SegmentReader segment,
|
public static Text.Reader readTextPointer(SegmentReader segment,
|
||||||
WirePointer ref) {
|
WirePointer ref) {
|
||||||
ref.target();
|
ref.target();
|
||||||
ListPointer listPtr = (ListPointer)ref;
|
ListPointer listPtr = new ListPointer(ref);
|
||||||
return new Text.Reader(listPtr);
|
return new Text.Reader(listPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue