diff --git a/compiler/src/test/scala/org/capnproto/EncodingTest.scala b/compiler/src/test/scala/org/capnproto/EncodingTest.scala index 83e3ffb..ec5a6e2 100644 --- a/compiler/src/test/scala/org/capnproto/EncodingTest.scala +++ b/compiler/src/test/scala/org/capnproto/EncodingTest.scala @@ -438,6 +438,123 @@ class EncodingSuite extends FunSuite { root.getAnyPointerField().getAs(new StructList.Factory(TestAllTypes.factory)); } + test("LongUint8List") { + { + val message = new MessageBuilder(); + val allTypes = message.initRoot(TestAllTypes.factory); + val length = (1 << 28) + 1; + val list = allTypes.initUInt8List(length); + list.size() should equal (length); + list.set(length - 1, 3); + list.get(length - 1) should equal (3); + allTypes.asReader().getUInt8List().get(length - 1) should equal (3); + } + } + + + test("LongUint16List") { + { + val message = new MessageBuilder(); + val allTypes = message.initRoot(TestAllTypes.factory); + val length = (1 << 27) + 1; + val list = allTypes.initUInt16List(length); + list.size() should equal (length); + list.set(length - 1, 3); + list.get(length - 1) should equal (3); + allTypes.asReader().getUInt16List().get(length - 1) should equal (3); + } + } + + test("LongUint32List") { + { + val message = new MessageBuilder(); + val allTypes = message.initRoot(TestAllTypes.factory); + val length = (1 << 26) + 1; + val list = allTypes.initUInt32List(length); + list.size() should equal (length); + list.set(length - 1, 3); + list.get(length - 1) should equal (3); + allTypes.asReader().getUInt32List().get(length - 1) should equal (3); + } + } + + test("LongUint64List") { + { + val message = new MessageBuilder(); + val allTypes = message.initRoot(TestAllTypes.factory); + val length = (1 << 25) + 1; + val list = allTypes.initUInt64List(length); + list.size() should equal (length); + list.set(length - 1, 3); + list.get(length - 1) should equal (3); + allTypes.asReader().getUInt64List().get(length - 1) should equal (3); + } + } + + test("LongFloat32List") { + { + val message = new MessageBuilder(); + val allTypes = message.initRoot(TestAllTypes.factory); + val length = (1 << 26) + 1; + val list = allTypes.initFloat32List(length); + list.size() should equal (length); + list.set(length - 1, 3.14f); + list.get(length - 1) should equal (3.14f); + allTypes.asReader().getFloat32List().get(length - 1) should equal (3.14f); + } + } + + test("LongFloat64List") { + { + val message = new MessageBuilder(); + val allTypes = message.initRoot(TestAllTypes.factory); + val length = (1 << 25) + 1; + val list = allTypes.initFloat64List(length); + list.size() should equal (length); + list.set(length - 1, 3.14); + list.get(length - 1) should equal (3.14); + allTypes.asReader().getFloat64List().get(length - 1) should equal (3.14); + } + } + + test("LongStructList") { + { + val message = new MessageBuilder(); + val allTypes = message.initRoot(TestAllTypes.factory); + val length = (1 << 21) + 1; + val list = allTypes.initStructList(length); + list.size() should equal (length); + list.get(length - 1).setUInt8Field(3); + allTypes.asReader().getStructList().get(length - 1).getUInt8Field() should equal (3); + } + } + + test("LongTextList") { + { + val message = new MessageBuilder(); + val allTypes = message.initRoot(TestAllTypes.factory); + val length = (1 << 25) + 1; + val list = allTypes.initTextList(length); + list.size() should equal (length); + list.set(length - 1, new Text.Reader("foo")); + allTypes.asReader().getTextList().get(length - 1).toString() should equal ("foo"); + } + } + + + test("LongListList") { + { + val message = new MessageBuilder(); + val root = message.initRoot(TestLists.factory); + val length = (1 << 25) + 1; + val list = root.initStructListList(length); + list.size() should equal (length); + list.init(length - 1, 3); + list.get(length - 1).size() should equal (3); + root.asReader().getStructListList().get(length - 1).size() should equal (3); + } + } + // to debug, do this: //Serialize.write((new java.io.FileOutputStream("/Users/dwrensha/Desktop/test.dat")).getChannel(), diff --git a/runtime/src/main/java/org/capnproto/ListBuilder.java b/runtime/src/main/java/org/capnproto/ListBuilder.java index c10bd22..42f5ebc 100644 --- a/runtime/src/main/java/org/capnproto/ListBuilder.java +++ b/runtime/src/main/java/org/capnproto/ListBuilder.java @@ -51,33 +51,33 @@ public class ListBuilder { } protected boolean _getBooleanElement(int index) { - long bindex = index * this.step; + long bindex = (long)index * this.step; byte b = this.segment.buffer.get(this.ptr + (int)(bindex / Constants.BITS_PER_BYTE)); return (b & (1 << (bindex % 8))) != 0; } protected byte _getByteElement(int index) { - return this.segment.buffer.get(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.get(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected short _getShortElement(int index) { - return this.segment.buffer.getShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getShort(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected int _getIntElement(int index) { - return this.segment.buffer.getInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getInt(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected long _getLongElement(int index) { - return this.segment.buffer.getLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getLong(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected float _getFloatElement(int index) { - return this.segment.buffer.getFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getFloat(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected double _getDoubleElement(int index) { - return this.segment.buffer.getDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getDouble(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected void _setBooleanElement(int index, boolean value) { @@ -90,32 +90,32 @@ public class ListBuilder { } protected void _setByteElement(int index, byte value) { - this.segment.buffer.put(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); + this.segment.buffer.put(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE), value); } protected void _setShortElement(int index, short value) { - this.segment.buffer.putShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); + this.segment.buffer.putShort(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE), value); } protected void _setIntElement(int index, int value) { - this.segment.buffer.putInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); + this.segment.buffer.putInt(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE), value); } protected void _setLongElement(int index, long value) { - this.segment.buffer.putLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); + this.segment.buffer.putLong(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE), value); } protected void _setFloatElement(int index, float value) { - this.segment.buffer.putFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); + this.segment.buffer.putFloat(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE), value); } protected void _setDoubleElement(int index, double value) { - this.segment.buffer.putDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); + this.segment.buffer.putDouble(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE), value); } protected final T _getStructElement(StructBuilder.Factory factory, int index) { - int indexBit = index * this.step; - int structData = this.ptr + indexBit / 8 ; + long indexBit = (long) index * this.step; + int structData = this.ptr + (int)(indexBit / Constants.BITS_PER_BYTE); int structPointers = (structData + (this.structDataSize / 8)) / 8; return factory.constructBuilder(this.segment, @@ -128,19 +128,19 @@ public class ListBuilder { protected final T _getPointerElement(FromPointerBuilder factory, int index) { return factory.fromPointerBuilder( this.segment, - (this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD); + (this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD); } protected final T _initPointerElement(FromPointerBuilder factory, int index, int elementCount) { return factory.initFromPointerBuilder( this.segment, - (this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, + (this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, elementCount); } protected final void _setPointerElement(SetPointerBuilder factory, int index, Reader value) { factory.setPointerBuilder(this.segment, - (this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, + (this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, value); } diff --git a/runtime/src/main/java/org/capnproto/ListReader.java b/runtime/src/main/java/org/capnproto/ListReader.java index 33d96fd..c63c368 100644 --- a/runtime/src/main/java/org/capnproto/ListReader.java +++ b/runtime/src/main/java/org/capnproto/ListReader.java @@ -67,41 +67,41 @@ public class ListReader { } protected boolean _getBooleanElement(int index) { - long bindex = index * this.step; + long bindex = (long)index * this.step; byte b = this.segment.buffer.get(this.ptr + (int)(bindex / Constants.BITS_PER_BYTE)); return (b & (1 << (bindex % 8))) != 0; } protected byte _getByteElement(int index) { - return this.segment.buffer.get(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.get(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected short _getShortElement(int index) { - return this.segment.buffer.getShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getShort(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected int _getIntElement(int index) { - return this.segment.buffer.getInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getInt(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected long _getLongElement(int index) { - return this.segment.buffer.getLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getLong(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected float _getFloatElement(int index) { - return this.segment.buffer.getFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getFloat(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected double _getDoubleElement(int index) { - return this.segment.buffer.getDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE); + return this.segment.buffer.getDouble(this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)); } protected T _getStructElement(StructReader.Factory factory, int index) { // TODO check nesting limit - int indexBit = index * this.step; - int structData = this.ptr + (indexBit / 8); - int structPointers = structData + (this.structDataSize / 8); + long indexBit = (long)index * this.step; + int structData = this.ptr + (int)(indexBit / Constants.BITS_PER_BYTE); + int structPointers = structData + (this.structDataSize / Constants.BITS_PER_BYTE); return factory.constructReader(this.segment, structData, structPointers / 8, this.structDataSize, this.structPointerCount, this.nestingLimit - 1); @@ -109,7 +109,7 @@ public class ListReader { protected T _getPointerElement(FromPointerReader factory, int index) { return factory.fromPointerReader(this.segment, - (this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, + (this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, this.nestingLimit); } @@ -117,7 +117,7 @@ public class ListReader { java.nio.ByteBuffer defaultBuffer, int defaultOffset, int defaultSize) { return factory.fromPointerReaderBlobDefault( this.segment, - (this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, + (this.ptr + (int)((long)index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, defaultBuffer, defaultOffset, defaultSize);