DataList and some StructList tests
This commit is contained in:
parent
3c6d02ecdd
commit
5f5cb24241
5 changed files with 123 additions and 4 deletions
|
@ -297,6 +297,7 @@ private:
|
||||||
case schema::Type::TEXT:
|
case schema::Type::TEXT:
|
||||||
return kj::strTree( "org.capnproto.TextList");
|
return kj::strTree( "org.capnproto.TextList");
|
||||||
case schema::Type::DATA:
|
case schema::Type::DATA:
|
||||||
|
return kj::strTree( "org.capnproto.DataList");
|
||||||
case schema::Type::ENUM:
|
case schema::Type::ENUM:
|
||||||
case schema::Type::INTERFACE:
|
case schema::Type::INTERFACE:
|
||||||
case schema::Type::ANY_POINTER:
|
case schema::Type::ANY_POINTER:
|
||||||
|
@ -1049,8 +1050,11 @@ private:
|
||||||
case schema::Type::TEXT:
|
case schema::Type::TEXT:
|
||||||
primitiveElement = false;
|
primitiveElement = false;
|
||||||
fieldSize = kj::str("org.capnproto.FieldSize.POINTER");
|
fieldSize = kj::str("org.capnproto.FieldSize.POINTER");
|
||||||
|
break;
|
||||||
case schema::Type::DATA:
|
case schema::Type::DATA:
|
||||||
|
primitiveElement = false;
|
||||||
|
fieldSize = kj::str("org.capnproto.FieldSize.POINTER");
|
||||||
|
break;
|
||||||
case schema::Type::LIST:
|
case schema::Type::LIST:
|
||||||
case schema::Type::ANY_POINTER:
|
case schema::Type::ANY_POINTER:
|
||||||
primitiveElement = false;
|
primitiveElement = false;
|
||||||
|
|
|
@ -52,6 +52,11 @@ object TestUtil {
|
||||||
textList.set(1, new Text.Reader("xyzzy"));
|
textList.set(1, new Text.Reader("xyzzy"));
|
||||||
textList.set(2, new Text.Reader("thud"));
|
textList.set(2, new Text.Reader("thud"));
|
||||||
|
|
||||||
|
val structList = builder.initStructList(3);
|
||||||
|
structList.get(0).setTextField(new Text.Reader("structlist 1"));
|
||||||
|
structList.get(1).setTextField(new Text.Reader("structlist 2"));
|
||||||
|
structList.get(2).setTextField(new Text.Reader("structlist 3"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,6 +103,15 @@ object TestUtil {
|
||||||
assert(textList.get(0).toString() == "plugh");
|
assert(textList.get(0).toString() == "plugh");
|
||||||
assert(textList.get(1).toString() == "xyzzy");
|
assert(textList.get(1).toString() == "xyzzy");
|
||||||
assert(textList.get(2).toString() == "thud");
|
assert(textList.get(2).toString() == "thud");
|
||||||
|
|
||||||
|
/*
|
||||||
|
val structList = builder.getStructList();
|
||||||
|
assert(3 == structList.size());
|
||||||
|
assert(structList.get(0).getTextField().toString() == "structlist 1")
|
||||||
|
assert(structList.get(1).getTextField().toString() == "structlist 2")
|
||||||
|
assert(structList.get(2).getTextField().toString() == "structlist 3")
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkTestMessage(reader : TestAllTypes.Reader) {
|
def checkTestMessage(reader : TestAllTypes.Reader) {
|
||||||
|
@ -144,6 +158,13 @@ object TestUtil {
|
||||||
assert(textList.get(1).toString() == "xyzzy");
|
assert(textList.get(1).toString() == "xyzzy");
|
||||||
assert(textList.get(2).toString() == "thud");
|
assert(textList.get(2).toString() == "thud");
|
||||||
|
|
||||||
|
|
||||||
|
val structList = reader.getStructList();
|
||||||
|
assert(3 == structList.size());
|
||||||
|
assert(structList.get(0).getTextField().toString() == "structlist 1")
|
||||||
|
assert(structList.get(1).getTextField().toString() == "structlist 2")
|
||||||
|
assert(structList.get(2).getTextField().toString() == "structlist 3")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ struct TestAllTypes {
|
||||||
float32List @27 : List(Float32);
|
float32List @27 : List(Float32);
|
||||||
float64List @28 : List(Float64);
|
float64List @28 : List(Float64);
|
||||||
textList @29 : List(Text);
|
textList @29 : List(Text);
|
||||||
# dataList @30 : List(Data);
|
dataList @30 : List(Data);
|
||||||
# structList @31 : List(TestAllTypes);
|
structList @31 : List(TestAllTypes);
|
||||||
# enumList @32 : List(TestEnum);
|
# enumList @32 : List(TestEnum);
|
||||||
# interfaceList @33 : List(Void);
|
# interfaceList @33 : List(Void);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ public final class ArrayInputStream implements BufferedInputStream {
|
||||||
int available = this.buf.remaining();
|
int available = this.buf.remaining();
|
||||||
int size = dst.remaining();
|
int size = dst.remaining();
|
||||||
|
|
||||||
ByteBuffer slice = buf.slice();
|
ByteBuffer slice = this.buf.slice();
|
||||||
slice.limit(size);
|
slice.limit(size);
|
||||||
dst.put(slice);
|
dst.put(slice);
|
||||||
|
|
||||||
|
|
94
runtime/src/main/java/org/capnproto/DataList.java
Normal file
94
runtime/src/main/java/org/capnproto/DataList.java
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
package org.capnproto;
|
||||||
|
|
||||||
|
public final class DataList {
|
||||||
|
public static final class Reader implements Iterable<Data.Reader> {
|
||||||
|
public final ListReader reader;
|
||||||
|
|
||||||
|
public Reader(ListReader reader) {
|
||||||
|
this.reader = reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.reader.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Data.Reader get(int index) {
|
||||||
|
return this.reader.getPointerElement(index).getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final class Iterator implements java.util.Iterator<Data.Reader> {
|
||||||
|
public Reader list;
|
||||||
|
public int idx = 0;
|
||||||
|
public Iterator(Reader list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Data.Reader next() {
|
||||||
|
return this.list.reader.getPointerElement(idx++).getData();
|
||||||
|
}
|
||||||
|
public boolean hasNext() {
|
||||||
|
return idx < list.size();
|
||||||
|
}
|
||||||
|
public void remove() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.util.Iterator<Data.Reader> iterator() {
|
||||||
|
return new Iterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Builder implements Iterable<Data.Builder> {
|
||||||
|
public final ListBuilder builder;
|
||||||
|
|
||||||
|
public Builder(ListBuilder builder) {
|
||||||
|
this.builder = builder;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// init
|
||||||
|
Builder(PointerBuilder builder, int size) {
|
||||||
|
this.builder = builder.initStructList(size, factory.structSize());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public int size() {
|
||||||
|
return this.builder.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Data.Builder get(int index) {
|
||||||
|
return this.builder.getPointerElement(index).getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final void set(int index, Data.Reader value) {
|
||||||
|
this.builder.getPointerElement(index).setData(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class Iterator implements java.util.Iterator<Data.Builder> {
|
||||||
|
public Builder list;
|
||||||
|
public int idx = 0;
|
||||||
|
public Iterator(Builder list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Data.Builder next() {
|
||||||
|
return this.list.builder.getPointerElement(idx++).getData();
|
||||||
|
}
|
||||||
|
public boolean hasNext() {
|
||||||
|
return this.idx < this.list.size();
|
||||||
|
}
|
||||||
|
public void remove() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.util.Iterator<Data.Builder> iterator() {
|
||||||
|
return new Iterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue