more ListList
This commit is contained in:
parent
a5e91d9f7d
commit
da13c77541
9 changed files with 122 additions and 15 deletions
|
@ -300,9 +300,10 @@ private:
|
|||
return kj::strTree( "org.capnproto.DataList");
|
||||
case schema::Type::ENUM:
|
||||
return kj::strTree("org.capnproto.EnumList");
|
||||
case schema::Type::LIST:
|
||||
return kj::strTree("org.capnproto.ListList");
|
||||
case schema::Type::INTERFACE:
|
||||
case schema::Type::ANY_POINTER:
|
||||
case schema::Type::LIST:
|
||||
KJ_FAIL_REQUIRE("unimplemented");
|
||||
}
|
||||
KJ_UNREACHABLE;
|
||||
|
@ -1063,6 +1064,15 @@ private:
|
|||
fieldSize = kj::str("org.capnproto.FieldSize.POINTER");
|
||||
break;
|
||||
case schema::Type::LIST:
|
||||
primitiveElement = false;
|
||||
fieldSize = kj::str("org.capnproto.FieldSize.POINTER");
|
||||
elementReaderType = kj::str(typeName(typeBody.getList().getElementType()), ".Reader");
|
||||
readerClass = kj::str("Reader<", elementReaderType, ">");
|
||||
elementBuilderType = kj::str(typeName(typeBody.getList().getElementType()), ".Builder");
|
||||
builderClass = kj::str("Builder<", elementBuilderType, ">");
|
||||
readerFactoryArg = kj::str(typeName(typeBody.getList().getElementType()), ".factory, ");
|
||||
builderFactoryArg = kj::str(typeName(typeBody.getList().getElementType()), ".factory, ");
|
||||
break;
|
||||
case schema::Type::ANY_POINTER:
|
||||
primitiveElement = false;
|
||||
break;
|
||||
|
|
|
@ -53,6 +53,8 @@ struct TestAllTypes {
|
|||
# interfaceList @33 : List(Void);
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct TestDefaults {
|
||||
voidField @0 : Void = void;
|
||||
boolField @1 : Bool = true;
|
||||
|
@ -192,6 +194,48 @@ struct TestGroups {
|
|||
}
|
||||
}
|
||||
|
||||
struct TestLists {
|
||||
# Small structs, when encoded as list, will be encoded as primitive lists rather than struct
|
||||
# lists, to save space.
|
||||
struct Struct0 { f @0 :Void; }
|
||||
struct Struct1 { f @0 :Bool; }
|
||||
struct Struct8 { f @0 :UInt8; }
|
||||
struct Struct16 { f @0 :UInt16; }
|
||||
struct Struct32 { f @0 :UInt32; }
|
||||
struct Struct64 { f @0 :UInt64; }
|
||||
struct StructP { f @0 :Text; }
|
||||
|
||||
# Versions of the above which cannot be encoded as primitive lists.
|
||||
struct Struct0c { f @0 :Void; pad @1 :Text; }
|
||||
struct Struct1c { f @0 :Bool; pad @1 :Text; }
|
||||
struct Struct8c { f @0 :UInt8; pad @1 :Text; }
|
||||
struct Struct16c { f @0 :UInt16; pad @1 :Text; }
|
||||
struct Struct32c { f @0 :UInt32; pad @1 :Text; }
|
||||
struct Struct64c { f @0 :UInt64; pad @1 :Text; }
|
||||
struct StructPc { f @0 :Text; pad @1 :UInt64; }
|
||||
|
||||
list0 @0 :List(Struct0);
|
||||
list1 @1 :List(Struct1);
|
||||
list8 @2 :List(Struct8);
|
||||
list16 @3 :List(Struct16);
|
||||
list32 @4 :List(Struct32);
|
||||
list64 @5 :List(Struct64);
|
||||
listP @6 :List(StructP);
|
||||
|
||||
int32ListList @7 :List(List(Int32));
|
||||
#textListList @8 :List(List(Text));
|
||||
#structListList @9 :List(List(TestAllTypes));
|
||||
#boolListListList @10 :List(List(List(Bool)));
|
||||
#enumListList @11 :List(List(TestEnum));
|
||||
}
|
||||
|
||||
struct TestFieldZeroIsBit {
|
||||
bit @0 :Bool;
|
||||
secondBit @1 :Bool = true;
|
||||
thirdField @2 :UInt8 = 123;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct TestOldVersion {
|
||||
# A subset of TestNewVersion.
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
package org.capnproto;
|
||||
|
||||
public final class DataList {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.POINTER));
|
||||
}
|
||||
|
||||
public final Builder fromPointerBuilder(PointerBuilder builder) {
|
||||
return new Builder(builder.getList(FieldSize.POINTER));
|
||||
}
|
||||
|
||||
public final Builder initFromPointerBuilder(PointerBuilder builder, int size) {
|
||||
return new Builder(builder.initList(FieldSize.POINTER, size));
|
||||
}
|
||||
}
|
||||
public static final Factory factory = new Factory();
|
||||
|
||||
public static final class Reader implements Iterable<Data.Reader> {
|
||||
public final ListReader reader;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ public class EnumList {
|
|||
return values[index];
|
||||
}
|
||||
|
||||
public static final class Factory<T extends java.lang.Enum> {
|
||||
public static final class Factory<T extends java.lang.Enum> implements ListFactory<Builder<T>, Reader<T>>{
|
||||
public final T values[];
|
||||
|
||||
public Factory(T values[]) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package org.capnproto;
|
||||
|
||||
public interface ListFactory<Reader, Builder> extends FromPointerBuilder<Builder>, FromPointerReader<Reader> {
|
||||
public interface ListFactory<Builder, Reader> extends FromPointerBuilder<Builder>, FromPointerReader<Reader> {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package org.capnproto;
|
||||
|
||||
public final class ListList {
|
||||
public static final class Factory<ElementReader, ElementBuilder> implements ListFactory<Reader<ElementReader>,
|
||||
Builder<ElementBuilder>> {
|
||||
public final ListFactory<ElementReader, ElementBuilder> factory;
|
||||
public static final class Factory<ElementBuilder, ElementReader>
|
||||
implements ListFactory<Builder<ElementBuilder>, Reader<ElementReader>> {
|
||||
|
||||
public Factory(ListFactory<ElementReader, ElementBuilder> factory) {
|
||||
public final ListFactory<ElementBuilder, ElementReader> factory;
|
||||
|
||||
public Factory(ListFactory<ElementBuilder, ElementReader> factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.capnproto;
|
|||
|
||||
public class PrimitiveList {
|
||||
public static class Void {
|
||||
public static final class Factory {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.VOID));
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class PrimitiveList {
|
|||
}
|
||||
|
||||
public static class Boolean {
|
||||
public static final class Factory {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.BIT));
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class PrimitiveList {
|
|||
}
|
||||
|
||||
public static class Byte {
|
||||
public static final class Factory {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.BYTE));
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ public class PrimitiveList {
|
|||
}
|
||||
|
||||
public static class Short {
|
||||
public static final class Factory {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.TWO_BYTES));
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class PrimitiveList {
|
|||
}
|
||||
|
||||
public static class Int {
|
||||
public static final class Factory {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.FOUR_BYTES));
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ public class PrimitiveList {
|
|||
}
|
||||
|
||||
public static class Float {
|
||||
public static final class Factory {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.FOUR_BYTES));
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ public class PrimitiveList {
|
|||
|
||||
|
||||
public static class Long {
|
||||
public static final class Factory {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.EIGHT_BYTES));
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ public class PrimitiveList {
|
|||
}
|
||||
|
||||
public static class Double {
|
||||
public static final class Factory {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.EIGHT_BYTES));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,28 @@
|
|||
package org.capnproto;
|
||||
|
||||
public final class StructList {
|
||||
public static final class Factory<ElementBuilder, ElementReader>
|
||||
implements ListFactory<Builder<ElementBuilder>, Reader<ElementReader>> {
|
||||
|
||||
public final StructFactory<ElementBuilder, ElementReader> factory;
|
||||
|
||||
public Factory(StructFactory<ElementBuilder, ElementReader> factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public final Reader<ElementReader> fromPointerReader(PointerReader reader) {
|
||||
return new Reader<ElementReader>(factory, reader.getList(FieldSize.INLINE_COMPOSITE));
|
||||
}
|
||||
|
||||
public final Builder<ElementBuilder> fromPointerBuilder(PointerBuilder builder) {
|
||||
return new Builder<ElementBuilder>(factory, builder.getList(FieldSize.INLINE_COMPOSITE));
|
||||
}
|
||||
|
||||
public final Builder<ElementBuilder> initFromPointerBuilder(PointerBuilder builder, int size) {
|
||||
return new Builder<ElementBuilder>(factory, builder.initList(FieldSize.INLINE_COMPOSITE, size));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Reader<T> implements Iterable<T> {
|
||||
public final ListReader reader;
|
||||
public final FromStructReader<T> factory;
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
package org.capnproto;
|
||||
|
||||
public final class TextList {
|
||||
public static final class Factory implements ListFactory<Builder, Reader> {
|
||||
public final Reader fromPointerReader(PointerReader reader) {
|
||||
return new Reader(reader.getList(FieldSize.POINTER));
|
||||
}
|
||||
|
||||
public final Builder fromPointerBuilder(PointerBuilder builder) {
|
||||
return new Builder(builder.getList(FieldSize.POINTER));
|
||||
}
|
||||
|
||||
public final Builder initFromPointerBuilder(PointerBuilder builder, int size) {
|
||||
return new Builder(builder.initList(FieldSize.POINTER, size));
|
||||
}
|
||||
}
|
||||
public static final Factory factory = new Factory();
|
||||
|
||||
public static final class Reader implements Iterable<Text.Reader> {
|
||||
public final ListReader reader;
|
||||
|
||||
|
|
Loading…
Reference in a new issue