From be23d22a891c9a1d951d3752a0a847168987b105 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Sat, 11 Oct 2014 12:46:47 -0400 Subject: [PATCH] allow the List(Primitive) -> List(Struct) upgrade path, for now --- .../main/java/org/capnproto/ListBuilder.java | 33 ++++++++++--------- .../main/java/org/capnproto/ListReader.java | 17 +++++----- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/runtime/src/main/java/org/capnproto/ListBuilder.java b/runtime/src/main/java/org/capnproto/ListBuilder.java index aab8d63..6ba11f3 100644 --- a/runtime/src/main/java/org/capnproto/ListBuilder.java +++ b/runtime/src/main/java/org/capnproto/ListBuilder.java @@ -51,65 +51,66 @@ public class ListBuilder { } protected boolean _getBooleanElement(int index) { - byte b = this.segment.buffer.get(this.ptr + index / 8); - return (b & (1 << (index % 8))) != 0; + long bindex = 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); + return this.segment.buffer.get(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected short _getShortElement(int index) { - return this.segment.buffer.getShort(this.ptr + index * 2); + return this.segment.buffer.getShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected int _getIntElement(int index) { - return this.segment.buffer.getInt(this.ptr + index * 4); + return this.segment.buffer.getInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected long _getLongElement(int index) { - return this.segment.buffer.getLong(this.ptr + index * 8); + return this.segment.buffer.getLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected float _getFloatElement(int index) { - return this.segment.buffer.getFloat(this.ptr + index * 4); + return this.segment.buffer.getFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected double _getDoubleElement(int index) { - return this.segment.buffer.getDouble(this.ptr + index * 8); + return this.segment.buffer.getDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected void _setBooleanElement(int index, boolean value) { - int bitOffset = index; + long bitOffset = index * this.step; byte bitnum = (byte)(bitOffset % 8); - int position = this.ptr + (bitOffset / 8); + int position = (int)(this.ptr + (bitOffset / 8)); byte oldValue = this.segment.buffer.get(position); this.segment.buffer.put(position, (byte)((oldValue & (~(1 << bitnum))) | (( value ? 1 : 0) << bitnum))); } protected void _setByteElement(int index, byte value) { - this.segment.buffer.put(this.ptr + index, value); + this.segment.buffer.put(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); } protected void _setShortElement(int index, short value) { - this.segment.buffer.putShort(this.ptr + index * 2, value); + this.segment.buffer.putShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); } protected void _setIntElement(int index, int value) { - this.segment.buffer.putInt(this.ptr + index * 4, value); + this.segment.buffer.putInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); } protected void _setLongElement(int index, long value) { - this.segment.buffer.putLong(this.ptr + index * 8, value); + this.segment.buffer.putLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); } protected void _setFloatElement(int index, float value) { - this.segment.buffer.putFloat(this.ptr + index * 4, value); + this.segment.buffer.putFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); } protected void _setDoubleElement(int index, double value) { - this.segment.buffer.putDouble(this.ptr + index * 8, value); + this.segment.buffer.putDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE, value); } protected final T _getStructElement(StructBuilder.Factory factory, int index) { diff --git a/runtime/src/main/java/org/capnproto/ListReader.java b/runtime/src/main/java/org/capnproto/ListReader.java index 88a5a65..ccc900e 100644 --- a/runtime/src/main/java/org/capnproto/ListReader.java +++ b/runtime/src/main/java/org/capnproto/ListReader.java @@ -67,32 +67,33 @@ public class ListReader { } protected boolean _getBooleanElement(int index) { - byte b = this.segment.buffer.get(this.ptr + index / 8); - return (b & (1 << (index % 8))) != 0; + long bindex = 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); + return this.segment.buffer.get(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected short _getShortElement(int index) { - return this.segment.buffer.getShort(this.ptr + index * 2); + return this.segment.buffer.getShort(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected int _getIntElement(int index) { - return this.segment.buffer.getInt(this.ptr + index * 4); + return this.segment.buffer.getInt(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected long _getLongElement(int index) { - return this.segment.buffer.getLong(this.ptr + index * 8); + return this.segment.buffer.getLong(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected float _getFloatElement(int index) { - return this.segment.buffer.getFloat(this.ptr + index * 4); + return this.segment.buffer.getFloat(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected double _getDoubleElement(int index) { - return this.segment.buffer.getDouble(this.ptr + index * 8); + return this.segment.buffer.getDouble(this.ptr + index * this.step / Constants.BITS_PER_BYTE); } protected T _getStructElement(StructReader.Factory factory, int index) {