initStructList
This commit is contained in:
parent
ff2116a297
commit
ef068e7221
3 changed files with 46 additions and 3 deletions
|
@ -8,4 +8,10 @@ public final class PointerBuilder {
|
||||||
this.segment = segment;
|
this.segment = segment;
|
||||||
this.pointer = pointer;
|
this.pointer = pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final ListBuilder initStructList(int elementCount, StructSize elementSize) {
|
||||||
|
return WireHelpers.initStructListPointer(this.pointer, this.segment, elementCount, elementSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
public final class StructSize {
|
public final class StructSize {
|
||||||
public final short data;
|
public final short data; // number of words in data section
|
||||||
public final short pointers;
|
public final short pointers; // number of words in pointer section
|
||||||
public final byte preferredListEncoding;
|
public final byte preferredListEncoding;
|
||||||
|
|
||||||
public StructSize(short data, short pointers, byte preferredListEncoding) {
|
public StructSize(short data, short pointers, byte preferredListEncoding) {
|
||||||
|
@ -10,4 +10,9 @@ public final class StructSize {
|
||||||
this.pointers = pointers;
|
this.pointers = pointers;
|
||||||
this.preferredListEncoding = preferredListEncoding;
|
this.preferredListEncoding = preferredListEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int total() {
|
||||||
|
return (int)this.data + (int)this.pointers;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,38 @@ package org.capnproto;
|
||||||
|
|
||||||
final class WireHelpers {
|
final class WireHelpers {
|
||||||
|
|
||||||
|
public static ListBuilder initListPointer(int refOffset,
|
||||||
|
SegmentBuilder segment,
|
||||||
|
int elementCount,
|
||||||
|
byte elementSize) {
|
||||||
|
throw new Error("unimplemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ListBuilder initStructListPointer(int refOffset,
|
||||||
|
SegmentBuilder segment,
|
||||||
|
int elementCount,
|
||||||
|
StructSize elementSize) {
|
||||||
|
if (elementSize.preferredListEncoding != FieldSize.INLINE_COMPOSITE) {
|
||||||
|
//# Small data-only struct. Allocate a list of primitives instead.
|
||||||
|
return initListPointer(refOffset, segment, elementCount,
|
||||||
|
elementSize.preferredListEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wordsPerElement = elementSize.total();
|
||||||
|
|
||||||
|
throw new Error("unimplemented");
|
||||||
|
}
|
||||||
|
|
||||||
public static StructReader readStructPointer(SegmentReader segment,
|
public static StructReader readStructPointer(SegmentReader segment,
|
||||||
int refOffset,
|
int refOffset,
|
||||||
int nestingLimit) {
|
int nestingLimit) {
|
||||||
|
|
||||||
// TODO error handling
|
// TODO error handling
|
||||||
|
|
||||||
|
if (nestingLimit < 0) {
|
||||||
|
throw new DecodeException("Message is too deeply nested or contains cycles.");
|
||||||
|
}
|
||||||
|
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
int ptrOffset = WirePointer.target(refOffset, ref);
|
int ptrOffset = WirePointer.target(refOffset, ref);
|
||||||
int structPtr = WirePointer.structPointer(ref);
|
int structPtr = WirePointer.structPointer(ref);
|
||||||
|
@ -78,6 +104,12 @@ final class WireHelpers {
|
||||||
public static Text.Reader readTextPointer(SegmentReader segment,
|
public static Text.Reader readTextPointer(SegmentReader segment,
|
||||||
int refOffset) {
|
int refOffset) {
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
|
|
||||||
|
if (WirePointer.isNull(ref)) {
|
||||||
|
// XXX should use the default value
|
||||||
|
return new Text.Reader(java.nio.ByteBuffer.wrap(new byte[0]), 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int ptrOffset = WirePointer.target(refOffset, ref);
|
int ptrOffset = WirePointer.target(refOffset, ref);
|
||||||
int listPtr = WirePointer.listPointer(ref);
|
int listPtr = WirePointer.listPointer(ref);
|
||||||
int size = ListPointer.elementCount(listPtr);
|
int size = ListPointer.elementCount(listPtr);
|
||||||
|
@ -93,7 +125,7 @@ final class WireHelpers {
|
||||||
// TODO bounds check?
|
// TODO bounds check?
|
||||||
|
|
||||||
if (size == 0 || segment.buffer.get(8 * ptrOffset + size - 1) != 0) {
|
if (size == 0 || segment.buffer.get(8 * ptrOffset + size - 1) != 0) {
|
||||||
throw new DecodeException("Message containts text that is not NUL-terminated.");
|
throw new DecodeException("Message contains text that is not NUL-terminated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Text.Reader(segment.buffer, ptrOffset, size - 1);
|
return new Text.Reader(segment.buffer, ptrOffset, size - 1);
|
||||||
|
|
Loading…
Reference in a new issue