working WirePointer static methods
This commit is contained in:
parent
edc75358bb
commit
5ee4fe295c
6 changed files with 79 additions and 13 deletions
|
@ -2,7 +2,7 @@ package org.capnproto;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
class ListPointer {
|
final class ListPointer {
|
||||||
public WirePointer ptr;
|
public WirePointer ptr;
|
||||||
|
|
||||||
public ListPointer(WirePointer ptr) {
|
public ListPointer(WirePointer ptr) {
|
||||||
|
@ -13,11 +13,23 @@ class ListPointer {
|
||||||
return (byte)(this.ptr.buffer.getInt(this.ptr.buffer_offset * 8 + 4) & 7);
|
return (byte)(this.ptr.buffer.getInt(this.ptr.buffer_offset * 8 + 4) & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte elementSize(int elementSizeAndCount) {
|
||||||
|
return (byte) (elementSizeAndCount & 7);
|
||||||
|
}
|
||||||
|
|
||||||
public int elementCount() {
|
public int elementCount() {
|
||||||
return this.ptr.buffer.getInt(this.ptr.buffer_offset * 8 + 4) >> 3;
|
return this.ptr.buffer.getInt(this.ptr.buffer_offset * 8 + 4) >> 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int elementCount(int elementSizeAndCount) {
|
||||||
|
return elementSizeAndCount >> 3;
|
||||||
|
}
|
||||||
|
|
||||||
public int inlineCompositeWordCount() {
|
public int inlineCompositeWordCount() {
|
||||||
return this.elementCount();
|
return this.elementCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int inlineCompositeWordCount(int elementSizeAndCount) {
|
||||||
|
return elementCount(elementSizeAndCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ public class PointerReader {
|
||||||
|
|
||||||
public Text.Reader getText() {
|
public Text.Reader getText() {
|
||||||
return WireHelpers.readTextPointer(this.segment,
|
return WireHelpers.readTextPointer(this.segment,
|
||||||
new WirePointer(this.segment.ptr,
|
this.pointer);
|
||||||
this.pointer));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.capnproto;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
class StructPointer{
|
final class StructPointer{
|
||||||
public WirePointer ptr;
|
public WirePointer ptr;
|
||||||
|
|
||||||
public StructPointer(WirePointer ptr) {
|
public StructPointer(WirePointer ptr) {
|
||||||
|
@ -13,11 +13,23 @@ class StructPointer{
|
||||||
return this.ptr.buffer.getShort(this.ptr.buffer_offset * 8 + 4);
|
return this.ptr.buffer.getShort(this.ptr.buffer_offset * 8 + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static short dataSize(int structRef) {
|
||||||
|
return (short)(structRef & 0xffff);
|
||||||
|
}
|
||||||
|
|
||||||
public short ptrCount() {
|
public short ptrCount() {
|
||||||
return this.ptr.buffer.getShort(this.ptr.buffer_offset * 8 + 6);
|
return this.ptr.buffer.getShort(this.ptr.buffer_offset * 8 + 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static short ptrCount(int structRef) {
|
||||||
|
return (short)(structRef >> 16);
|
||||||
|
}
|
||||||
|
|
||||||
public int wordSize() {
|
public int wordSize() {
|
||||||
return this.dataSize() + this.ptrCount();
|
return this.dataSize() + this.ptrCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int wordSize(int structRef) {
|
||||||
|
return (int)dataSize(structRef) + (int)ptrCount(structRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ public class Text {
|
||||||
public final int offset; // in bytes
|
public final int offset; // in bytes
|
||||||
public final int size; // in bytes
|
public final int size; // in bytes
|
||||||
|
|
||||||
public Reader(WordPointer ptr, int size) {
|
public Reader(ByteBuffer buffer, int offset, int size) {
|
||||||
this.buffer = ptr.buffer;
|
this.buffer = buffer;
|
||||||
this.offset = ptr.offset * 8;
|
this.offset = offset * 8;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,10 +72,12 @@ class WireHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text.Reader readTextPointer(SegmentReader segment,
|
public static Text.Reader readTextPointer(SegmentReader segment,
|
||||||
WirePointer ref) {
|
int refOffset) {
|
||||||
WordPointer ptr = ref.target();
|
long ref = WirePointer.get(segment.ptr, refOffset);
|
||||||
ListPointer listPtr = new ListPointer(ref);
|
int ptrOffset = WirePointer.target(refOffset, ref);
|
||||||
int size = listPtr.elementCount();
|
long ptr = WirePointer.get(segment.ptr, ptrOffset);
|
||||||
return new Text.Reader(ptr, size);
|
int listPtr = WirePointer.listPointer(ref);
|
||||||
|
int size = ListPointer.elementCount(listPtr);
|
||||||
|
return new Text.Reader(segment.ptr, ptrOffset, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package org.capnproto;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
class WirePointer {
|
final class WirePointer {
|
||||||
public final ByteBuffer buffer;
|
public final ByteBuffer buffer;
|
||||||
public final int buffer_offset; // in words
|
public final int buffer_offset; // in words
|
||||||
|
|
||||||
|
@ -25,20 +25,61 @@ class WirePointer {
|
||||||
return this.buffer.getLong(this.buffer_offset * 8) == 0;
|
return this.buffer.getLong(this.buffer_offset * 8) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isNull(long wirePointer) {
|
||||||
|
return wirePointer == 0;
|
||||||
|
}
|
||||||
|
|
||||||
public int offsetAndKind() {
|
public int offsetAndKind() {
|
||||||
return this.buffer.getInt(this.buffer_offset * 8);
|
return this.buffer.getInt(this.buffer_offset * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int offsetAndKind(long wirePointer) {
|
||||||
|
return (int)(wirePointer & 0xffffffff);
|
||||||
|
}
|
||||||
|
|
||||||
public byte kind() {
|
public byte kind() {
|
||||||
return (byte) (this.offsetAndKind() & 3);
|
return (byte) (this.offsetAndKind() & 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte kind(long wirePointer) {
|
||||||
|
return (byte)(offsetAndKind(wirePointer) & 3);
|
||||||
|
}
|
||||||
|
|
||||||
public WordPointer target() {
|
public WordPointer target() {
|
||||||
return new WordPointer(buffer,
|
return new WordPointer(buffer,
|
||||||
this.buffer_offset + 1 + (this.offsetAndKind() >> 2));
|
this.buffer_offset + 1 + (this.offsetAndKind() >> 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int target(int offset, long wirePointer) {
|
||||||
|
return offset + 1 + (offsetAndKind(wirePointer) >> 2);
|
||||||
|
}
|
||||||
|
|
||||||
public int inlineCompositeListElementCount() {
|
public int inlineCompositeListElementCount() {
|
||||||
return this.offsetAndKind() >> 2;
|
return this.offsetAndKind() >> 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int inlineCompositeListElementCount(long wirePointer) {
|
||||||
|
return offsetAndKind(wirePointer) >> 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// offset is in words
|
||||||
|
public static int upper32Bits(ByteBuffer buffer, int offset) {
|
||||||
|
return buffer.getInt(offset * 8 + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int upper32Bits(long wirePointer) {
|
||||||
|
return (int)(wirePointer >> 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int listPointer(long wirePointer) {
|
||||||
|
return upper32Bits(wirePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int structPointer(long wirePointer) {
|
||||||
|
return upper32Bits(wirePointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long get(ByteBuffer buffer, int offset) {
|
||||||
|
return buffer.getLong(offset * 8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue