From 2ede4244b1f3eaf2c4c7a722c3b25dbb8ac98454 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Wed, 8 Oct 2014 13:37:26 -0400 Subject: [PATCH] RefDefault --- .../main/java/org/capnproto/AnyPointer.java | 2 +- runtime/src/main/java/org/capnproto/Data.java | 10 +++++++ .../src/main/java/org/capnproto/DataList.java | 8 ++--- .../org/capnproto/FromPointerBuilder.java | 2 +- .../FromPointerBuilderRefDefault.java | 5 ++++ .../java/org/capnproto/FromPointerReader.java | 2 +- .../FromPointerReaderRefDefault.java | 5 ++++ .../main/java/org/capnproto/ListBuilder.java | 14 ++------- .../main/java/org/capnproto/ListFactory.java | 29 +++++++++++++++---- .../src/main/java/org/capnproto/ListList.java | 4 +-- .../main/java/org/capnproto/ListReader.java | 4 +-- .../java/org/capnproto/StructBuilder.java | 5 ++-- .../java/org/capnproto/StructFactory.java | 24 +++++++++++---- .../main/java/org/capnproto/StructReader.java | 23 ++++++++------- runtime/src/main/java/org/capnproto/Text.java | 15 +++++++++- .../src/main/java/org/capnproto/TextList.java | 8 ++--- 16 files changed, 106 insertions(+), 54 deletions(-) create mode 100644 runtime/src/main/java/org/capnproto/FromPointerBuilderRefDefault.java create mode 100644 runtime/src/main/java/org/capnproto/FromPointerReaderRefDefault.java diff --git a/runtime/src/main/java/org/capnproto/AnyPointer.java b/runtime/src/main/java/org/capnproto/AnyPointer.java index 8df2e646..9da64459 100644 --- a/runtime/src/main/java/org/capnproto/AnyPointer.java +++ b/runtime/src/main/java/org/capnproto/AnyPointer.java @@ -14,7 +14,7 @@ public Reader(SegmentReader segment, int pointer, int nestingLimit) { } public final T getAs(FromPointerReader factory) { - return factory.fromPointerReader(this.segment, this.pointer, null, 0, this.nestingLimit); + return factory.fromPointerReader(this.segment, this.pointer, this.nestingLimit); } } diff --git a/runtime/src/main/java/org/capnproto/Data.java b/runtime/src/main/java/org/capnproto/Data.java index ec0df654..607d46fa 100644 --- a/runtime/src/main/java/org/capnproto/Data.java +++ b/runtime/src/main/java/org/capnproto/Data.java @@ -4,13 +4,18 @@ public final class Data { public static final class Factory implements FromPointerReaderBlobDefault, + FromPointerReader, FromPointerBuilderBlobDefault, + FromPointerBuilder, SetPointerBuilder, InitSizedFromPointerBuilder { public final Reader fromPointerReaderBlobDefault(SegmentReader segment, int pointer, java.nio.ByteBuffer defaultBuffer, int defaultOffset, int defaultSize) { return WireHelpers.readDataPointer(segment, pointer, defaultBuffer, defaultOffset, defaultSize); } + public final Reader fromPointerReader(SegmentReader segment, int pointer, int nestingLimit) { + return WireHelpers.readDataPointer(segment, pointer, null, 0, 0); + } public final Builder fromPointerBuilderBlobDefault(SegmentBuilder segment, int pointer, java.nio.ByteBuffer defaultBuffer, int defaultOffset, int defaultSize) { return WireHelpers.getWritableDataPointer(pointer, @@ -19,6 +24,11 @@ public final Builder fromPointerBuilderBlobDefault(SegmentBuilder segment, int p defaultOffset, defaultSize); } + public final Builder fromPointerBuilder(SegmentBuilder segment, int pointer) { + return WireHelpers.getWritableDataPointer(pointer, + segment, + null, 0, 0); + } public final Builder initSizedFromPointerBuilder(SegmentBuilder segment, int pointer, int size) { return WireHelpers.initDataPointer(pointer, segment, size); diff --git a/runtime/src/main/java/org/capnproto/DataList.java b/runtime/src/main/java/org/capnproto/DataList.java index 7a4055e8..54540236 100644 --- a/runtime/src/main/java/org/capnproto/DataList.java +++ b/runtime/src/main/java/org/capnproto/DataList.java @@ -30,7 +30,7 @@ public Reader(SegmentReader segment, } public Data.Reader get(int index) { - return _getPointerElement(Data.factory, index, null, 0, 0); + return _getPointerElement(Data.factory, index); } public final class Iterator implements java.util.Iterator { @@ -41,7 +41,7 @@ public Iterator(Reader list) { } public Data.Reader next() { - return _getPointerElement(Data.factory, idx++, null, 0, 0); + return this.list._getPointerElement(Data.factory, idx++); } public boolean hasNext() { return idx < list.size(); @@ -65,7 +65,7 @@ public Builder(SegmentBuilder segment, int ptr, } public final Data.Builder get(int index) { - return _getPointerElement(Data.factory, index, null, 0, 0); + return _getPointerElement(Data.factory, index); } public final void set(int index, Data.Reader value) { @@ -80,7 +80,7 @@ public Iterator(Builder list) { } public Data.Builder next() { - return this.list._getPointerElement(Data.factory, idx++, null, 0, 0); + return this.list._getPointerElement(Data.factory, idx++); } public boolean hasNext() { return this.idx < this.list.size(); diff --git a/runtime/src/main/java/org/capnproto/FromPointerBuilder.java b/runtime/src/main/java/org/capnproto/FromPointerBuilder.java index 78ac0e5d..ed75af34 100644 --- a/runtime/src/main/java/org/capnproto/FromPointerBuilder.java +++ b/runtime/src/main/java/org/capnproto/FromPointerBuilder.java @@ -1,5 +1,5 @@ package org.capnproto; public interface FromPointerBuilder { - T fromPointerBuilder(SegmentBuilder segment, int pointer, SegmentReader defaultSegment, int defaultOffset); + T fromPointerBuilder(SegmentBuilder segment, int pointer); } diff --git a/runtime/src/main/java/org/capnproto/FromPointerBuilderRefDefault.java b/runtime/src/main/java/org/capnproto/FromPointerBuilderRefDefault.java new file mode 100644 index 00000000..b1aca353 --- /dev/null +++ b/runtime/src/main/java/org/capnproto/FromPointerBuilderRefDefault.java @@ -0,0 +1,5 @@ +package org.capnproto; + +public interface FromPointerBuilderRefDefault { + T fromPointerBuilderRefDefault(SegmentBuilder segment, int pointer, SegmentReader defaultSegment, int defaultOffset); +} diff --git a/runtime/src/main/java/org/capnproto/FromPointerReader.java b/runtime/src/main/java/org/capnproto/FromPointerReader.java index 77b602df..4b891fb5 100644 --- a/runtime/src/main/java/org/capnproto/FromPointerReader.java +++ b/runtime/src/main/java/org/capnproto/FromPointerReader.java @@ -1,5 +1,5 @@ package org.capnproto; public interface FromPointerReader { - T fromPointerReader(SegmentReader segment, int pointer, SegmentReader defaultSegment, int defaultOffset, int nestingLimit); + T fromPointerReader(SegmentReader segment, int pointer, int nestingLimit); } diff --git a/runtime/src/main/java/org/capnproto/FromPointerReaderRefDefault.java b/runtime/src/main/java/org/capnproto/FromPointerReaderRefDefault.java new file mode 100644 index 00000000..cb329d4c --- /dev/null +++ b/runtime/src/main/java/org/capnproto/FromPointerReaderRefDefault.java @@ -0,0 +1,5 @@ +package org.capnproto; + +public interface FromPointerReaderRefDefault { + T fromPointerReaderRefDefault(SegmentReader segment, int pointer, SegmentReader defaultSegment, int defaultOffset, int nestingLimit); +} diff --git a/runtime/src/main/java/org/capnproto/ListBuilder.java b/runtime/src/main/java/org/capnproto/ListBuilder.java index 35f8ae17..07095223 100644 --- a/runtime/src/main/java/org/capnproto/ListBuilder.java +++ b/runtime/src/main/java/org/capnproto/ListBuilder.java @@ -104,22 +104,12 @@ protected final T _getStructElement(StructBuilder.Factory factory, int in (byte)(indexBit % 8)); } - protected final T _getPointerElement(FromPointerBuilder factory, int index, SegmentReader defaultSegment, int defaultOffset) { + 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, - defaultSegment, defaultOffset); - } - - protected final T _getPointerElement(FromPointerBuilderBlobDefault factory, int index, - java.nio.ByteBuffer defaultBuffer, int defaultOffset, int defaultSize) { - return factory.fromPointerBuilderBlobDefault( - this.segment, - (this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD, - defaultBuffer, defaultOffset, defaultSize); + (this.ptr + (index * this.step / Constants.BITS_PER_BYTE)) / Constants.BYTES_PER_WORD); } - protected final T _initPointerElement(InitFromPointerBuilder factory, int index) { return factory.initFromPointerBuilder( this.segment, diff --git a/runtime/src/main/java/org/capnproto/ListFactory.java b/runtime/src/main/java/org/capnproto/ListFactory.java index bf28be74..c2129428 100644 --- a/runtime/src/main/java/org/capnproto/ListFactory.java +++ b/runtime/src/main/java/org/capnproto/ListFactory.java @@ -1,17 +1,21 @@ package org.capnproto; public abstract class ListFactory - implements ListBuilder.Factory, FromPointerBuilder, + implements ListBuilder.Factory, + FromPointerBuilder, + FromPointerBuilderRefDefault, InitSizedFromPointerBuilder, SetPointerBuilder, - ListReader.Factory, FromPointerReader { + ListReader.Factory, + FromPointerReader, + FromPointerReaderRefDefault { final byte elementSize; ListFactory(byte elementSize) {this.elementSize = elementSize;} - public final Reader fromPointerReader(SegmentReader segment, int pointer, - SegmentReader defaultSegment, int defaultOffset, - int nestingLimit) { + public final Reader fromPointerReaderRefDefault(SegmentReader segment, int pointer, + SegmentReader defaultSegment, int defaultOffset, + int nestingLimit) { return WireHelpers.readListPointer(this, segment, pointer, @@ -21,7 +25,12 @@ public final Reader fromPointerReader(SegmentReader segment, int pointer, nestingLimit); } - public Builder fromPointerBuilder(SegmentBuilder segment, int pointer, SegmentReader defaultSegment, int defaultOffset) { + public final Reader fromPointerReader(SegmentReader segment, int pointer, int nestingLimit) { + return fromPointerReaderRefDefault(segment, pointer, null, 0, nestingLimit); + } + + public Builder fromPointerBuilderRefDefault(SegmentBuilder segment, int pointer, + SegmentReader defaultSegment, int defaultOffset) { return WireHelpers.getWritableListPointer(this, pointer, segment, @@ -30,6 +39,14 @@ public Builder fromPointerBuilder(SegmentBuilder segment, int pointer, SegmentRe defaultOffset); } + public Builder fromPointerBuilder(SegmentBuilder segment, int pointer) { + return WireHelpers.getWritableListPointer(this, + pointer, + segment, + this.elementSize, + null, 0); + } + public Builder initSizedFromPointerBuilder(SegmentBuilder segment, int pointer, int elementCount) { return WireHelpers.initListPointer(this, pointer, segment, elementCount, this.elementSize); } diff --git a/runtime/src/main/java/org/capnproto/ListList.java b/runtime/src/main/java/org/capnproto/ListList.java index 9abb7b8a..b43f3fd4 100644 --- a/runtime/src/main/java/org/capnproto/ListList.java +++ b/runtime/src/main/java/org/capnproto/ListList.java @@ -41,7 +41,7 @@ public Reader(FromPointerReader factory, } public T get(int index) { - return _getPointerElement(this.factory, index, null, 0); + return _getPointerElement(this.factory, index); } } @@ -62,7 +62,7 @@ public final T init(int index, int size) { } public final T get(int index) { - return _getPointerElement(this.factory, index, null, 0); + return _getPointerElement(this.factory, index); } } } diff --git a/runtime/src/main/java/org/capnproto/ListReader.java b/runtime/src/main/java/org/capnproto/ListReader.java index 9bcbdb42..17a291bf 100644 --- a/runtime/src/main/java/org/capnproto/ListReader.java +++ b/runtime/src/main/java/org/capnproto/ListReader.java @@ -86,11 +86,9 @@ protected T _getStructElement(StructReader.Factory factory, int index) { this.structPointerCount, (byte) (indexBit % 8), this.nestingLimit - 1); } - protected T _getPointerElement(FromPointerReader factory, int index, SegmentReader defaultSegment, int defaultOffset) { + 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, - defaultSegment, - defaultOffset, this.nestingLimit); } diff --git a/runtime/src/main/java/org/capnproto/StructBuilder.java b/runtime/src/main/java/org/capnproto/StructBuilder.java index 578e89ab..69c56d72 100644 --- a/runtime/src/main/java/org/capnproto/StructBuilder.java +++ b/runtime/src/main/java/org/capnproto/StructBuilder.java @@ -159,8 +159,9 @@ protected final void _clearPointerField(int ptrIndex) { this.segment.buffer.putLong(pointer * 8, 0L); } - protected final T _getPointerField(FromPointerBuilder factory, int index, SegmentReader defaultSegment, int defaultOffset) { - return factory.fromPointerBuilder(this.segment, this.pointers + index, defaultSegment, defaultOffset); + protected final T _getPointerField(FromPointerBuilderRefDefault factory, int index, + SegmentReader defaultSegment, int defaultOffset) { + return factory.fromPointerBuilderRefDefault(this.segment, this.pointers + index, defaultSegment, defaultOffset); } protected final T _getPointerField(FromPointerBuilderBlobDefault factory, int index, diff --git a/runtime/src/main/java/org/capnproto/StructFactory.java b/runtime/src/main/java/org/capnproto/StructFactory.java index 6a849162..e0cf0693 100644 --- a/runtime/src/main/java/org/capnproto/StructFactory.java +++ b/runtime/src/main/java/org/capnproto/StructFactory.java @@ -1,23 +1,35 @@ package org.capnproto; public abstract class StructFactory - implements FromPointerBuilder, StructBuilder.Factory, + implements FromPointerBuilder, + FromPointerBuilderRefDefault, + StructBuilder.Factory, InitFromPointerBuilder, SetPointerBuilder, - FromPointerReader, StructReader.Factory { - public final Reader fromPointerReader(SegmentReader segment, int pointer, - SegmentReader defaultSegment, int defaultOffset, - int nestingLimit) { + FromPointerReader, + FromPointerReaderRefDefault, + StructReader.Factory { + public final Reader fromPointerReaderRefDefault(SegmentReader segment, int pointer, + SegmentReader defaultSegment, int defaultOffset, + int nestingLimit) { return WireHelpers.readStructPointer(this, segment, pointer, defaultSegment, defaultOffset, nestingLimit); } - public final Builder fromPointerBuilder(SegmentBuilder segment, int pointer, SegmentReader defaultSegment, int defaultOffset) { + public final Reader fromPointerReader(SegmentReader segment, int pointer, int nestingLimit) { + return fromPointerReaderRefDefault(segment, pointer, null, 0, nestingLimit); + } + public final Builder fromPointerBuilderRefDefault(SegmentBuilder segment, int pointer, + SegmentReader defaultSegment, int defaultOffset) { return WireHelpers.getWritableStructPointer(this, pointer, segment, this.structSize(), defaultSegment, defaultOffset); } + public final Builder fromPointerBuilder(SegmentBuilder segment, int pointer) { + return WireHelpers.getWritableStructPointer(this, pointer, segment, this.structSize(), + null, 0); + } public final Builder initFromPointerBuilder(SegmentBuilder segment, int pointer) { return WireHelpers.initStructPointer(this, pointer, segment, this.structSize()); } diff --git a/runtime/src/main/java/org/capnproto/StructReader.java b/runtime/src/main/java/org/capnproto/StructReader.java index 3207e6ff..214f939c 100644 --- a/runtime/src/main/java/org/capnproto/StructReader.java +++ b/runtime/src/main/java/org/capnproto/StructReader.java @@ -139,19 +139,20 @@ protected final boolean _pointerFieldIsNull(int ptrIndex) { return this.segment.buffer.getLong((this.pointers + ptrIndex) * Constants.BYTES_PER_WORD) == 0; } - protected final T _getPointerField(FromPointerReader factory, int ptrIndex, SegmentReader defaultSegment, int defaultOffset) { + protected final T _getPointerField(FromPointerReaderRefDefault factory, int ptrIndex, + SegmentReader defaultSegment, int defaultOffset) { if (ptrIndex < this.pointerCount) { - return factory.fromPointerReader(this.segment, - this.pointers + ptrIndex, - defaultSegment, - defaultOffset, - this.nestingLimit); + return factory.fromPointerReaderRefDefault(this.segment, + this.pointers + ptrIndex, + defaultSegment, + defaultOffset, + this.nestingLimit); } else { - return factory.fromPointerReader(SegmentReader.EMPTY, - 0, - defaultSegment, - defaultOffset, - this.nestingLimit); + return factory.fromPointerReaderRefDefault(SegmentReader.EMPTY, + 0, + defaultSegment, + defaultOffset, + this.nestingLimit); } } diff --git a/runtime/src/main/java/org/capnproto/Text.java b/runtime/src/main/java/org/capnproto/Text.java index d1ac749b..3cbc613a 100644 --- a/runtime/src/main/java/org/capnproto/Text.java +++ b/runtime/src/main/java/org/capnproto/Text.java @@ -3,8 +3,11 @@ import java.nio.ByteBuffer; public final class Text { - public static final class Factory implements FromPointerReaderBlobDefault, + public static final class Factory implements + FromPointerReaderBlobDefault, + FromPointerReader, FromPointerBuilderBlobDefault, + FromPointerBuilder, SetPointerBuilder, InitSizedFromPointerBuilder { public final Reader fromPointerReaderBlobDefault(SegmentReader segment, int pointer, java.nio.ByteBuffer defaultBuffer, @@ -12,6 +15,10 @@ public final Reader fromPointerReaderBlobDefault(SegmentReader segment, int poin return WireHelpers.readTextPointer(segment, pointer, defaultBuffer, defaultOffset, defaultSize); } + public final Reader fromPointerReader(SegmentReader segment, int pointer, int nestingLimit) { + return WireHelpers.readTextPointer(segment, pointer, null, 0, 0); + } + public final Builder fromPointerBuilderBlobDefault(SegmentBuilder segment, int pointer, java.nio.ByteBuffer defaultBuffer, int defaultOffset, int defaultSize) { return WireHelpers.getWritableTextPointer(pointer, @@ -21,6 +28,12 @@ public final Builder fromPointerBuilderBlobDefault(SegmentBuilder segment, int p defaultSize); } + public final Builder fromPointerBuilder(SegmentBuilder segment, int pointer) { + return WireHelpers.getWritableTextPointer(pointer, + segment, + null, 0, 0); + } + public final Builder initSizedFromPointerBuilder(SegmentBuilder segment, int pointer, int size) { return WireHelpers.initTextPointer(pointer, segment, size); } diff --git a/runtime/src/main/java/org/capnproto/TextList.java b/runtime/src/main/java/org/capnproto/TextList.java index 844ced13..7252870d 100644 --- a/runtime/src/main/java/org/capnproto/TextList.java +++ b/runtime/src/main/java/org/capnproto/TextList.java @@ -30,7 +30,7 @@ public Reader(SegmentReader segment, } public Text.Reader get(int index) { - return _getPointerElement(Text.factory, index, null, 0, 0); + return _getPointerElement(Text.factory, index); } public final class Iterator implements java.util.Iterator { @@ -41,7 +41,7 @@ public Iterator(Reader list) { } public Text.Reader next() { - return _getPointerElement(Text.factory, idx++, null, 0, 0); + return this.list._getPointerElement(Text.factory, idx++); } public boolean hasNext() { return idx < list.size(); @@ -65,7 +65,7 @@ public Builder(SegmentBuilder segment, int ptr, } public final Text.Builder get(int index) { - return _getPointerElement(Text.factory, index, null, 0, 0); + return _getPointerElement(Text.factory, index); } public final void set(int index, Text.Reader value) { @@ -80,7 +80,7 @@ public Iterator(Builder list) { } public Text.Builder next() { - return this.list._getPointerElement(Text.factory, idx++, null, 0, 0); + return this.list._getPointerElement(Text.factory, idx++); } public boolean hasNext() { return this.idx < this.list.size();