This commit is contained in:
David Renshaw 2014-10-06 22:05:01 -04:00
parent 25a537c323
commit 24e4183fc0
4 changed files with 47 additions and 48 deletions

View file

@ -1201,8 +1201,7 @@ private:
spaces(indent), " return ", fullName, ".STRUCT_SIZE;\n", spaces(indent), " return ", fullName, ".STRUCT_SIZE;\n",
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " public final Reader asReader(Builder builder) {\n", spaces(indent), " public final Reader asReader(Builder builder) {\n",
spaces(indent), " throw new Error();\n", spaces(indent), " return builder.asReader();\n",
// spaces(indent), " return new Reader(builder._builder.asReader());\n",
spaces(indent), " }\n", spaces(indent), " }\n",
spaces(indent), " }\n", spaces(indent), " }\n",

View file

@ -19,17 +19,17 @@ public class StructBuilder {
this.bit0Offset = bit0Offset; this.bit0Offset = bit0Offset;
} }
public final boolean _getBooleanField(int offset) { protected final boolean _getBooleanField(int offset) {
int bitOffset = (offset == 0 ? this.bit0Offset : offset); int bitOffset = (offset == 0 ? this.bit0Offset : offset);
int position = this.data + (bitOffset / 8); int position = this.data + (bitOffset / 8);
return (this.segment.buffer.get(position) & (1 << (bitOffset % 8))) != 0; 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; return this._getBooleanField(offset) ^ mask;
} }
public final void _setBooleanField(int offset, boolean value) { protected final void _setBooleanField(int offset, boolean value) {
int bitOffset = offset; int bitOffset = offset;
if (offset == 0) { bitOffset = this.bit0Offset; } if (offset == 0) { bitOffset = this.bit0Offset; }
byte bitnum = (byte)(bitOffset % 8); byte bitnum = (byte)(bitOffset % 8);
@ -39,111 +39,111 @@ public class StructBuilder {
(byte)((oldValue & (~(1 << bitnum))) | (( value ? 1 : 0) << bitnum))); (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); 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); 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); 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); 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)); 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); 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); 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); 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)); 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); 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; 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); 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); 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); 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; 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); 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); 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); 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( return Float.intBitsToFloat(
this.segment.buffer.getInt(this.data + offset * 4) ^ mask); 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); 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, this.segment.buffer.putInt(this.data + offset * 4,
Float.floatToIntBits(value) ^ mask); 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); 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( return Double.longBitsToDouble(
this.segment.buffer.getLong(this.data + offset * 8) ^ mask); 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); 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, this.segment.buffer.putLong(this.data + offset * 8,
Double.doubleToLongBits(value) ^ mask); Double.doubleToLongBits(value) ^ mask);
} }
public final PointerBuilder _getPointerField(int index) { protected final PointerBuilder _getPointerField(int index) {
return new PointerBuilder(this.segment, this.pointers + index); return new PointerBuilder(this.segment, this.pointers + index);
} }

View file

@ -32,7 +32,7 @@ public class StructReader {
this.nestingLimit = nestingLimit; this.nestingLimit = nestingLimit;
} }
public final boolean _getBooleanField(int offset) { protected final boolean _getBooleanField(int offset) {
// XXX should use unsigned operations // XXX should use unsigned operations
if (offset < this.dataSize) { if (offset < this.dataSize) {
if (offset == 0) { 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; return this._getBooleanField(offset) ^ mask;
} }
public final byte _getByteField(int offset) { protected final byte _getByteField(int offset) {
if ((offset + 1) * 8 <= this.dataSize) { if ((offset + 1) * 8 <= this.dataSize) {
return this.segment.buffer.get(this.data + offset); return this.segment.buffer.get(this.data + offset);
} else { } 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); return (byte)(this._getByteField(offset) ^ mask);
} }
public final short _getShortField(int offset) { protected final short _getShortField(int offset) {
if ((offset + 1) * 16 <= this.dataSize) { if ((offset + 1) * 16 <= this.dataSize) {
return this.segment.buffer.getShort(this.data + offset * 2); return this.segment.buffer.getShort(this.data + offset * 2);
} else { } 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); return (short)(this._getShortField(offset) ^ mask);
} }
public final int _getIntField(int offset) { protected final int _getIntField(int offset) {
if ((offset + 1) * 32 <= this.dataSize) { if ((offset + 1) * 32 <= this.dataSize) {
return this.segment.buffer.getInt(this.data + offset * 4); return this.segment.buffer.getInt(this.data + offset * 4);
} else { } 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; return this._getIntField(offset) ^ mask;
} }
public final long _getLongField(int offset) { protected final long _getLongField(int offset) {
if ((offset + 1) * 64 <= this.dataSize) { if ((offset + 1) * 64 <= this.dataSize) {
return this.segment.buffer.getLong(this.data + offset * 8); return this.segment.buffer.getLong(this.data + offset * 8);
} else { } 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; return this._getLongField(offset) ^ mask;
} }
public final float _getFloatField(int offset) { protected final float _getFloatField(int offset) {
if ((offset + 1) * 32 <= this.dataSize) { if ((offset + 1) * 32 <= this.dataSize) {
return this.segment.buffer.getFloat(this.data + offset * 4); return this.segment.buffer.getFloat(this.data + offset * 4);
} else { } 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) { if ((offset + 1) * 32 <= this.dataSize) {
return Float.intBitsToFloat(this.segment.buffer.getInt(this.data + offset * 4) ^ mask); return Float.intBitsToFloat(this.segment.buffer.getInt(this.data + offset * 4) ^ mask);
} else { } 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) { if ((offset + 1) * 64 <= this.dataSize) {
return this.segment.buffer.getDouble(this.data + offset * 8); return this.segment.buffer.getDouble(this.data + offset * 8);
} else { } 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) { if ((offset + 1) * 64 <= this.dataSize) {
return Double.longBitsToDouble(this.segment.buffer.getLong(this.data + offset * 8) ^ mask); return Double.longBitsToDouble(this.segment.buffer.getLong(this.data + offset * 8) ^ mask);
} else { } else {
@ -130,7 +130,7 @@ public class StructReader {
} }
} }
public final PointerReader _getPointerField(int ptrIndex) { protected final PointerReader _getPointerField(int ptrIndex) {
if (ptrIndex < this.pointerCount) { if (ptrIndex < this.pointerCount) {
return new PointerReader(this.segment, return new PointerReader(this.segment,
this.pointers + ptrIndex, this.pointers + ptrIndex,

View file

@ -17,8 +17,8 @@ class LayoutSuite extends FunSuite {
val pointerReader = new PointerReader(arena.tryGetSegment(0), 0, 0x7fffffff); val pointerReader = new PointerReader(arena.tryGetSegment(0), 0, 0x7fffffff);
val reader = pointerReader.getStruct(); val reader = pointerReader.getStruct();
assert(reader.getLongField(0) === 0xefcdab8967452301L); assert(reader._getLongField(0) === 0xefcdab8967452301L);
assert(reader.getLongField(1) === 0L); assert(reader._getLongField(1) === 0L);
assert(reader.getIntField(0) === 0x67452301); assert(reader.getIntField(0) === 0x67452301);
assert(reader.getIntField(1) === 0xefcdab89); assert(reader.getIntField(1) === 0xefcdab89);