add AnyList
This commit is contained in:
parent
e9493cf2e1
commit
837f1b324c
3 changed files with 69 additions and 6 deletions
|
@ -414,6 +414,8 @@ private:
|
|||
return kj::strTree("org.capnproto.Capability.", suffix);
|
||||
case schema::Type::AnyPointer::Unconstrained::STRUCT:
|
||||
return kj::strTree("org.capnproto.AnyStruct.", suffix);
|
||||
case schema::Type::AnyPointer::Unconstrained::LIST:
|
||||
return kj::strTree("org.capnproto.AnyList.", suffix);
|
||||
default:
|
||||
return kj::strTree("org.capnproto.AnyPointer.", suffix);
|
||||
}
|
||||
|
@ -781,6 +783,8 @@ private:
|
|||
return kj::str("org.capnproto.Capability.factory");
|
||||
case schema::Type::AnyPointer::Unconstrained::STRUCT:
|
||||
return kj::str("org.capnproto.AnyStruct.factory");
|
||||
case schema::Type::AnyPointer::Unconstrained::LIST:
|
||||
return kj::str("org.capnproto.AnyList.factory");
|
||||
default:
|
||||
return kj::str("org.capnproto.AnyPointer.factory");
|
||||
}
|
||||
|
@ -1042,7 +1046,8 @@ private:
|
|||
kind = FieldKind::ANY_POINTER;
|
||||
break;
|
||||
case schema::Type::AnyPointer::Unconstrained::LIST:
|
||||
kind = FieldKind::LIST;
|
||||
kind = FieldKind::ANY_POINTER;
|
||||
break;
|
||||
case schema::Type::AnyPointer::Unconstrained::CAPABILITY:
|
||||
kind = FieldKind::INTERFACE;
|
||||
break;
|
||||
|
|
|
@ -60,11 +60,11 @@ struct TestAnyPointer {
|
|||
# in the struct.
|
||||
}
|
||||
|
||||
#struct TestAnyOthers {
|
||||
# anyStructField @0 :AnyStruct;
|
||||
# anyListField @1 :AnyList;
|
||||
# capabilityField @2 :Capability;
|
||||
#}
|
||||
struct TestAnyOthers {
|
||||
anyStructField @0 :AnyStruct;
|
||||
anyListField @1 :AnyList;
|
||||
capabilityField @2 :Capability;
|
||||
}
|
||||
|
||||
struct TestOutOfOrder {
|
||||
foo @3 :Text;
|
||||
|
|
58
runtime/src/main/java/org/capnproto/AnyList.java
Normal file
58
runtime/src/main/java/org/capnproto/AnyList.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package org.capnproto;
|
||||
|
||||
public class AnyList {
|
||||
|
||||
public static final class Factory extends ListFactory<Builder, Reader> {
|
||||
|
||||
Factory() {
|
||||
super(ElementSize.VOID);
|
||||
}
|
||||
|
||||
public final Reader asReader(Builder builder) {
|
||||
return builder.asReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder constructBuilder(SegmentBuilder segment, int ptr, int elementCount, int step, int structDataSize, short structPointerCount) {
|
||||
return new Builder(segment, ptr, elementCount, step, structDataSize, structPointerCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader constructReader(SegmentReader segment, int ptr, int elementCount, int step, int structDataSize, short structPointerCount, int nestingLimit) {
|
||||
return new Reader(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Factory factory = new Factory();
|
||||
|
||||
public static final ListList.Factory<Builder,Reader> listFactory =
|
||||
new ListList.Factory<>(factory);
|
||||
|
||||
public static final class Builder extends ListBuilder {
|
||||
Builder(SegmentBuilder segment, int ptr, int elementCount, int step, int structDataSize, short structPointerCount){
|
||||
super(segment, ptr, elementCount, step, structDataSize, structPointerCount);
|
||||
}
|
||||
|
||||
public final Reader asReader() {
|
||||
return new Reader(this.segment, this.ptr, this.elementCount, this.step, this.structDataSize, this.structPointerCount, 0x7fffffff);
|
||||
}
|
||||
|
||||
public final <T> T initAs(Factory<T> factory) {
|
||||
return factory.constructBuilder(this.segment, this.ptr, this.elementCount, this.step, this.structDataSize, this.structPointerCount);
|
||||
}
|
||||
|
||||
public final <T> T setAs(Factory<T> factory) {
|
||||
return factory.constructBuilder(this.segment, this.ptr, this.elementCount, this.step, this.structDataSize, this.structPointerCount);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Reader extends ListReader {
|
||||
Reader(SegmentReader segment, int ptr, int elementCount, int step, int structDataSize, short structPointerCount, int nestingLimit){
|
||||
super(segment, ptr, elementCount, step, structDataSize, structPointerCount, nestingLimit);
|
||||
}
|
||||
|
||||
public final <T> T getAs(Factory<T> factory) {
|
||||
return factory.constructReader(this.segment, this.ptr, this.elementCount, this.step, this.structDataSize, this.structPointerCount, this.nestingLimit);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue