more readListPointer

This commit is contained in:
David Renshaw 2014-06-17 21:30:30 -04:00
parent fdfcbd0427
commit 331c4f4e89
2 changed files with 41 additions and 6 deletions

View file

@ -12,7 +12,7 @@ class EncodingSuite extends FunSuite {
val allTypes = message.initRoot(TestAllTypes.Builder.factory);
TestUtil.initTestMessage(allTypes);
TestUtil.checkTestMessage(allTypes);
//TestUtil.checkTestMessage(allTypes.asReader());
TestUtil.checkTestMessage(allTypes.asReader());
}
test("AllTypesMultiSegment") {
@ -21,6 +21,7 @@ class EncodingSuite extends FunSuite {
TestUtil.initTestMessage(allTypes);
TestUtil.checkTestMessage(allTypes);
//TestUtil.checkTestMessage(allTypes.asReader());
}
// to debug, do this:

View file

@ -412,12 +412,46 @@ final class WireHelpers {
StructPointer.ptrCount(tag),
nestingLimit - 1);
}
case FieldSize.VOID : break;
default :
throw new Error("unrecognized element size");
default : {
//# This is a primitive or pointer list, but all such
//# lists can also be interpreted as struct lists. We
//# need to compute the data size and pointer count for
//# such structs.
int dataSize = FieldSize.dataBitsPerElement(ListPointer.elementSize(resolved.ref));
int pointerCount = FieldSize.pointersPerElement(ListPointer.elementSize(resolved.ref));
int step = dataSize + pointerCount * Constants.BITS_PER_POINTER;
// TODO "bounds_check"
//# Verify that the elements are at least as large as
//# the expected type. Note that if we expected
//# InlineComposite, the expected sizes here will be
//# zero, because bounds checking will be performed at
//# field access time. So this check here is for the
//# case where we expected a list of some primitive or
//# pointer type.
int expectedDataBitsPerElement = FieldSize.dataBitsPerElement(expectedElementSize);
int expectedPointersPerElement = FieldSize.pointersPerElement(expectedElementSize);
if (expectedDataBitsPerElement > dataSize) {
throw new DecodeException("Message contains list with incompatible element type.");
}
throw new Error();
if (expectedPointersPerElement > pointerCount) {
throw new DecodeException("Message contains list with incompatible element type.");
}
return new ListReader(resolved.segment,
resolved.ptr * Constants.BYTES_PER_WORD,
ListPointer.elementCount(resolved.ref),
step,
dataSize,
(short)pointerCount,
nestingLimit - 1);
}
}
}
public static Text.Reader readTextPointer(SegmentReader segment,