some methods for StructReader

This commit is contained in:
David Renshaw 2014-05-10 08:34:22 -04:00
parent d5554ea341
commit 1ff499697a
2 changed files with 57 additions and 6 deletions

View file

@ -2,6 +2,22 @@ package capnp;
public class PointerReader { public class PointerReader {
public SegmentReader segment; public SegmentReader segment;
public long pointer; public int pointer; // word offset
public int nestingLimit; public int nestingLimit;
public PointerReader() {
this.segment = null;
this.pointer = 0; // XXX
this.nestingLimit = 0x7fffffff;
}
public PointerReader(SegmentReader segment, int pointer, int nestingLimit) {
this.segment = segment;
this.pointer = pointer;
this.nestingLimit = nestingLimit;
}
public void getText() {
throw new Error();
}
} }

View file

@ -2,16 +2,51 @@ package capnp;
public class StructReader { public class StructReader {
public SegmentReader segment; public SegmentReader segment;
public long data; //byte offset to data section public int data; //byte offset to data section
// public WirePointer pointers; public int pointers; // word offset of pointer section
public int dataSize; // in bits public int dataSize; // in bits
public short pointerCount; public short pointerCount;
public short bit0Offset; public byte bit0Offset;
public int nestingLimit; public int nestingLimit;
public <T> T getDataField() { public boolean getBoolField(int offset) {
throw new Error(); // XXX should use unsigned operations
if (offset < this.dataSize) {
if (offset == 0) {
offset = this.bit0Offset;
}
byte b = this.segment.ptr.get(offset / 8);
return (b & (1 << (offset % 8))) != 0;
} else {
return false;
}
}
public byte getByteField(int offset) {
if ((offset + 1) * 8 <= this.dataSize) {
return this.segment.ptr.get(this.data + offset);
} else {
return 0;
}
}
public int getIntField(int offset) {
if ((offset + 1) * 32 <= this.dataSize) {
return this.segment.ptr.getInt((this.data / 4) + offset);
} else {
return 0;
}
}
public PointerReader getPointerField(int ptrIndex) {
if (ptrIndex < this.pointerCount) {
return new PointerReader(this.segment,
this.pointers + ptrIndex,
this.nestingLimit);
} else {
return new PointerReader();
}
} }
} }