diff --git a/compiler/src/main/cpp/capnpc-java.c++ b/compiler/src/main/cpp/capnpc-java.c++ index fa404e0..a541cbb 100644 --- a/compiler/src/main/cpp/capnpc-java.c++ +++ b/compiler/src/main/cpp/capnpc-java.c++ @@ -1201,8 +1201,7 @@ private: spaces(indent), " return ", fullName, ".STRUCT_SIZE;\n", spaces(indent), " }\n", spaces(indent), " public final Reader asReader(Builder builder) {\n", - spaces(indent), " throw new Error();\n", -// spaces(indent), " return new Reader(builder._builder.asReader());\n", + spaces(indent), " return builder.asReader();\n", spaces(indent), " }\n", spaces(indent), " }\n", diff --git a/runtime/src/main/java/org/capnproto/StructBuilder.java b/runtime/src/main/java/org/capnproto/StructBuilder.java index 91d592f..efb64e2 100644 --- a/runtime/src/main/java/org/capnproto/StructBuilder.java +++ b/runtime/src/main/java/org/capnproto/StructBuilder.java @@ -19,17 +19,17 @@ public class StructBuilder { this.bit0Offset = bit0Offset; } - public final boolean _getBooleanField(int offset) { + protected final boolean _getBooleanField(int offset) { int bitOffset = (offset == 0 ? this.bit0Offset : offset); int position = this.data + (bitOffset / 8); return (this.segment.buffer.get(position) & (1 << (bitOffset % 8))) != 0; } - public final boolean getBooleanField(int offset, boolean mask) { + protected final boolean getBooleanField(int offset, boolean mask) { return this._getBooleanField(offset) ^ mask; } - public final void _setBooleanField(int offset, boolean value) { + protected final void _setBooleanField(int offset, boolean value) { int bitOffset = offset; if (offset == 0) { bitOffset = this.bit0Offset; } byte bitnum = (byte)(bitOffset % 8); @@ -39,111 +39,111 @@ public class StructBuilder { (byte)((oldValue & (~(1 << bitnum))) | (( value ? 1 : 0) << bitnum))); } - public final void _setBooleanField(int offset, boolean value, boolean mask) { + protected final void _setBooleanField(int offset, boolean value, boolean mask) { this._setBooleanField(offset, value ^ mask); } - public final byte _getByteField(int offset) { + protected final byte _getByteField(int offset) { return this.segment.buffer.get(this.data + offset); } - public final byte _getByteField(int offset, byte mask) { + protected final byte _getByteField(int offset, byte mask) { return (byte)(this._getByteField(offset) ^ mask); } - public final void _setByteField(int offset, byte value) { + protected final void _setByteField(int offset, byte value) { this.segment.buffer.put(this.data + offset, value); } - public final void _setByteField(int offset, byte value, byte mask) { + protected final void _setByteField(int offset, byte value, byte mask) { this._setByteField(offset, (byte) (value ^ mask)); } - public final short _getShortField(int offset) { + protected final short _getShortField(int offset) { return this.segment.buffer.getShort(this.data + offset * 2); } - public final short _getShortField(int offset, short mask) { + protected final short _getShortField(int offset, short mask) { return (short)(this._getShortField(offset) ^ mask); } - public final void _setShortField(int offset, short value) { + protected final void _setShortField(int offset, short value) { this.segment.buffer.putShort(this.data + offset * 2, value); } - public final void _setShortField(int offset, short value, short mask) { + protected final void _setShortField(int offset, short value, short mask) { this._setShortField(offset, (short)(value ^ mask)); } - public final int _getIntField(int offset) { + protected final int _getIntField(int offset) { return this.segment.buffer.getInt(this.data + offset * 4); } - public final int _getIntField(int offset, int mask) { + protected final int _getIntField(int offset, int mask) { return this._getIntField(offset) ^ mask; } - public final void _setIntField(int offset, int value) { + protected final void _setIntField(int offset, int value) { this.segment.buffer.putInt(this.data + offset * 4, value); } - public final void _setIntField(int offset, int value, int mask) { + protected final void _setIntField(int offset, int value, int mask) { this._setIntField(offset, value ^ mask); } - public final long _getLongField(int offset) { + protected final long _getLongField(int offset) { return this.segment.buffer.getLong(this.data + offset * 8); } - public final long _getLongField(int offset, long mask) { + protected final long _getLongField(int offset, long mask) { return this._getLongField(offset) ^ mask; } - public final void _setLongField(int offset, long value) { + protected final void _setLongField(int offset, long value) { this.segment.buffer.putLong(this.data + offset * 8, value); } - public final void _setLongField(int offset, long value, long mask) { + protected final void _setLongField(int offset, long value, long mask) { this._setLongField(offset, value ^ mask); } - public final float _getFloatField(int offset) { + protected final float _getFloatField(int offset) { return this.segment.buffer.getFloat(this.data + offset * 4); } - public final float _getFloatField(int offset, int mask) { + protected final float _getFloatField(int offset, int mask) { return Float.intBitsToFloat( this.segment.buffer.getInt(this.data + offset * 4) ^ mask); } - public final void _setFloatField(int offset, float value) { + protected final void _setFloatField(int offset, float value) { this.segment.buffer.putFloat(this.data + offset * 4, value); } - public final void _setFloatField(int offset, float value, int mask) { + protected final void _setFloatField(int offset, float value, int mask) { this.segment.buffer.putInt(this.data + offset * 4, Float.floatToIntBits(value) ^ mask); } - public final double _getDoubleField(int offset) { + protected final double _getDoubleField(int offset) { return this.segment.buffer.getDouble(this.data + offset * 8); } - public final double _getDoubleField(int offset, long mask) { + protected final double _getDoubleField(int offset, long mask) { return Double.longBitsToDouble( this.segment.buffer.getLong(this.data + offset * 8) ^ mask); } - public final void _setDoubleField(int offset, double value) { + protected final void _setDoubleField(int offset, double value) { this.segment.buffer.putDouble(this.data + offset * 8, value); } - public final void _setDoubleField(int offset, double value, long mask) { + protected final void _setDoubleField(int offset, double value, long mask) { this.segment.buffer.putLong(this.data + offset * 8, Double.doubleToLongBits(value) ^ mask); } - public final PointerBuilder _getPointerField(int index) { + protected final PointerBuilder _getPointerField(int index) { return new PointerBuilder(this.segment, this.pointers + index); } diff --git a/runtime/src/main/java/org/capnproto/StructReader.java b/runtime/src/main/java/org/capnproto/StructReader.java index 1176dae..e7f2f1b 100644 --- a/runtime/src/main/java/org/capnproto/StructReader.java +++ b/runtime/src/main/java/org/capnproto/StructReader.java @@ -32,7 +32,7 @@ public class StructReader { this.nestingLimit = nestingLimit; } - public final boolean _getBooleanField(int offset) { + protected final boolean _getBooleanField(int offset) { // XXX should use unsigned operations if (offset < this.dataSize) { if (offset == 0) { @@ -46,11 +46,11 @@ public class StructReader { } } - public final boolean _getBooleanField(int offset, boolean mask) { + protected final boolean _getBooleanField(int offset, boolean mask) { return this._getBooleanField(offset) ^ mask; } - public final byte _getByteField(int offset) { + protected final byte _getByteField(int offset) { if ((offset + 1) * 8 <= this.dataSize) { return this.segment.buffer.get(this.data + offset); } else { @@ -58,11 +58,11 @@ public class StructReader { } } - public final byte _getByteField(int offset, byte mask) { + protected final byte _getByteField(int offset, byte mask) { return (byte)(this._getByteField(offset) ^ mask); } - public final short _getShortField(int offset) { + protected final short _getShortField(int offset) { if ((offset + 1) * 16 <= this.dataSize) { return this.segment.buffer.getShort(this.data + offset * 2); } else { @@ -70,11 +70,11 @@ public class StructReader { } } - public final short _getShortField(int offset, short mask) { + protected final short _getShortField(int offset, short mask) { return (short)(this._getShortField(offset) ^ mask); } - public final int _getIntField(int offset) { + protected final int _getIntField(int offset) { if ((offset + 1) * 32 <= this.dataSize) { return this.segment.buffer.getInt(this.data + offset * 4); } else { @@ -82,11 +82,11 @@ public class StructReader { } } - public final int _getIntField(int offset, int mask) { + protected final int _getIntField(int offset, int mask) { return this._getIntField(offset) ^ mask; } - public final long _getLongField(int offset) { + protected final long _getLongField(int offset) { if ((offset + 1) * 64 <= this.dataSize) { return this.segment.buffer.getLong(this.data + offset * 8); } else { @@ -94,11 +94,11 @@ public class StructReader { } } - public final long _getLongField(int offset, long mask) { + protected final long _getLongField(int offset, long mask) { return this._getLongField(offset) ^ mask; } - public final float _getFloatField(int offset) { + protected final float _getFloatField(int offset) { if ((offset + 1) * 32 <= this.dataSize) { return this.segment.buffer.getFloat(this.data + offset * 4); } else { @@ -106,7 +106,7 @@ public class StructReader { } } - public final float _getFloatField(int offset, int mask) { + protected final float _getFloatField(int offset, int mask) { if ((offset + 1) * 32 <= this.dataSize) { return Float.intBitsToFloat(this.segment.buffer.getInt(this.data + offset * 4) ^ mask); } else { @@ -114,7 +114,7 @@ public class StructReader { } } - public final double _getDoubleField(int offset) { + protected final double _getDoubleField(int offset) { if ((offset + 1) * 64 <= this.dataSize) { return this.segment.buffer.getDouble(this.data + offset * 8); } else { @@ -122,7 +122,7 @@ public class StructReader { } } - public final double _getDoubleField(int offset, long mask) { + protected final double _getDoubleField(int offset, long mask) { if ((offset + 1) * 64 <= this.dataSize) { return Double.longBitsToDouble(this.segment.buffer.getLong(this.data + offset * 8) ^ mask); } else { @@ -130,7 +130,7 @@ public class StructReader { } } - public final PointerReader _getPointerField(int ptrIndex) { + protected final PointerReader _getPointerField(int ptrIndex) { if (ptrIndex < this.pointerCount) { return new PointerReader(this.segment, this.pointers + ptrIndex, diff --git a/runtime/src/test/scala/org/capnproto/LayoutTest.scala b/runtime/src/test/scala/org/capnproto/LayoutTest.scala index 85a466a..a7f4150 100644 --- a/runtime/src/test/scala/org/capnproto/LayoutTest.scala +++ b/runtime/src/test/scala/org/capnproto/LayoutTest.scala @@ -17,8 +17,8 @@ class LayoutSuite extends FunSuite { val pointerReader = new PointerReader(arena.tryGetSegment(0), 0, 0x7fffffff); val reader = pointerReader.getStruct(); - assert(reader.getLongField(0) === 0xefcdab8967452301L); - assert(reader.getLongField(1) === 0L); + assert(reader._getLongField(0) === 0xefcdab8967452301L); + assert(reader._getLongField(1) === 0L); assert(reader.getIntField(0) === 0x67452301); assert(reader.getIntField(1) === 0xefcdab89);