add AnyStruct
This commit is contained in:
parent
e04adc90b6
commit
cefd8eaaa2
5 changed files with 87 additions and 13 deletions
|
@ -83,13 +83,13 @@
|
|||
<phase>generate-test-sources</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<mkdir dir="src/test/generated"/>
|
||||
<mkdir dir="src/test/generated/org/capnproto/test"/>
|
||||
<exec executable="capnp" failonerror="true">
|
||||
<arg value="compile"/>
|
||||
<arg value="-I"/>
|
||||
<arg value="src/main/schema/"/>
|
||||
<arg value="--src-prefix=src/test/schema/"/>
|
||||
<arg value="-o../capnpc-java:src/test/generated"/>
|
||||
<arg value="-o../capnpc-java:src/test/generated/org/capnproto/test"/>
|
||||
<arg value="src/test/schema/test.capnp"/>
|
||||
<arg value="src/test/schema/test-import.capnp"/>
|
||||
<env key="CAPNP_LITE" value="1"/>
|
||||
|
|
|
@ -412,6 +412,8 @@ private:
|
|||
switch (type.whichAnyPointerKind()) {
|
||||
case schema::Type::AnyPointer::Unconstrained::CAPABILITY:
|
||||
return kj::strTree("org.capnproto.Capability.", suffix);
|
||||
case schema::Type::AnyPointer::Unconstrained::STRUCT:
|
||||
return kj::strTree("org.capnproto.AnyStruct.", suffix);
|
||||
default:
|
||||
return kj::strTree("org.capnproto.AnyPointer.", suffix);
|
||||
}
|
||||
|
@ -775,8 +777,10 @@ private:
|
|||
|
||||
} else {
|
||||
switch (type.whichAnyPointerKind()) {
|
||||
case schema::Type::AnyPointer::Unconstrained::CAPABILITY:
|
||||
return kj::str("org.capnproto.Capability.factory");
|
||||
case schema::Type::AnyPointer::Unconstrained::CAPABILITY:
|
||||
return kj::str("org.capnproto.Capability.factory");
|
||||
case schema::Type::AnyPointer::Unconstrained::STRUCT:
|
||||
return kj::str("org.capnproto.AnyStruct.factory");
|
||||
default:
|
||||
return kj::str("org.capnproto.AnyPointer.factory");
|
||||
}
|
||||
|
@ -1035,7 +1039,7 @@ private:
|
|||
kind = FieldKind::ANY_POINTER;
|
||||
break;
|
||||
case schema::Type::AnyPointer::Unconstrained::STRUCT:
|
||||
kind = FieldKind::STRUCT;
|
||||
kind = FieldKind::ANY_POINTER;
|
||||
break;
|
||||
case schema::Type::AnyPointer::Unconstrained::LIST:
|
||||
kind = FieldKind::LIST;
|
||||
|
@ -1967,14 +1971,14 @@ private:
|
|||
}
|
||||
|
||||
if (resultProto.getIsGeneric()) {
|
||||
auto resultFactoryArgs = getFactoryArguments(resultSchema, paramSchema);
|
||||
resultFactory = resultFactoryArgs.size() == 0
|
||||
? kj::str(shortResultType, ".factory")
|
||||
: kj::strTree("newFactory(",
|
||||
kj::StringTree(KJ_MAP(arg, resultFactoryArgs) {
|
||||
return kj::strTree(arg);
|
||||
}, ", "),
|
||||
")").flatten();
|
||||
auto resultFactoryArgs = getFactoryArguments(resultSchema, paramSchema);
|
||||
resultFactory = resultFactoryArgs.size() == 0
|
||||
? kj::str(shortResultType, ".factory")
|
||||
: kj::strTree("newFactory(",
|
||||
kj::StringTree(KJ_MAP(arg, resultFactoryArgs) {
|
||||
return kj::strTree(arg);
|
||||
}, ", "),
|
||||
")").flatten();
|
||||
}
|
||||
|
||||
auto paramBuilder = kj::str(shortParamType, ".Builder");
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.capnproto.test;
|
||||
|
||||
import org.capnproto.test.Test;
|
||||
import org.capnproto.*;
|
||||
import org.capnproto.Void;
|
||||
import org.junit.Assert;
|
||||
|
@ -845,6 +846,13 @@ public class EncodingTest {
|
|||
TestUtil.checkTestMessage(listReader.get(1));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testAnyStruct() {
|
||||
MessageBuilder builder = new MessageBuilder();
|
||||
var root = builder.initRoot(Test.TestAnyOthers.factory);
|
||||
var anyStruct = root.initAnyStructField();
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testCopyAnyPointer() {
|
||||
MessageBuilder message1 = new MessageBuilder();
|
||||
|
|
|
@ -148,6 +148,12 @@ struct TestAnyPointer {
|
|||
# in the struct.
|
||||
}
|
||||
|
||||
struct TestAnyOthers {
|
||||
anyStructField @0 :AnyStruct;
|
||||
#anyListField @1 :AnyPointer; # not currently implemented
|
||||
#capabilityField @2 :Capability;
|
||||
}
|
||||
|
||||
struct TestOutOfOrder {
|
||||
foo @3 :Text;
|
||||
bar @2 :Text;
|
||||
|
|
56
runtime/src/main/java/org/capnproto/AnyStruct.java
Normal file
56
runtime/src/main/java/org/capnproto/AnyStruct.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package org.capnproto;
|
||||
|
||||
public class AnyStruct {
|
||||
|
||||
public static final org.capnproto.StructSize STRUCT_SIZE = new org.capnproto.StructSize((short)0,(short)0);
|
||||
|
||||
public static final class Factory extends org.capnproto.StructFactory<Builder, Reader> {
|
||||
public Factory() {
|
||||
}
|
||||
public final Reader constructReader(org.capnproto.SegmentReader segment, int data,int pointers, int dataSize, short pointerCount, int nestingLimit) {
|
||||
return new Reader(segment,data,pointers,dataSize,pointerCount,nestingLimit);
|
||||
}
|
||||
public final Builder constructBuilder(org.capnproto.SegmentBuilder segment, int data,int pointers, int dataSize, short pointerCount) {
|
||||
return new Builder(segment, data, pointers, dataSize, pointerCount);
|
||||
}
|
||||
public final org.capnproto.StructSize structSize() {
|
||||
return AnyStruct.STRUCT_SIZE;
|
||||
}
|
||||
public final Reader asReader(Builder builder) {
|
||||
return builder.asReader();
|
||||
}
|
||||
}
|
||||
|
||||
public static final Factory factory = new Factory();
|
||||
|
||||
public static final org.capnproto.StructList.Factory<Builder,Reader> listFactory =
|
||||
new org.capnproto.StructList.Factory<>(factory);
|
||||
|
||||
public static final class Builder extends org.capnproto.StructBuilder {
|
||||
Builder(org.capnproto.SegmentBuilder segment, int data, int pointers,int dataSize, short pointerCount){
|
||||
super(segment, data, pointers, dataSize, pointerCount);
|
||||
}
|
||||
public final Reader asReader() {
|
||||
return new Reader(segment, data, pointers, dataSize, pointerCount, 0x7fffffff);
|
||||
}
|
||||
|
||||
public final <T> T initAs(StructBuilder.Factory<T> factory) {
|
||||
return factory.constructBuilder(this.segment, this.capTable, this.data, this.pointers, this.dataSize, this.pointerCount);
|
||||
}
|
||||
|
||||
public final <T> T setAs(StructBuilder.Factory<T> factory) {
|
||||
return factory.constructBuilder(this.segment, this.capTable, this.data, this.pointers, this.dataSize, this.pointerCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class Reader extends org.capnproto.StructReader {
|
||||
Reader(org.capnproto.SegmentReader segment, int data, int pointers,int dataSize, short pointerCount, int nestingLimit){
|
||||
super(segment, data, pointers, dataSize, pointerCount, nestingLimit);
|
||||
}
|
||||
|
||||
public final <T> T getAs(StructReader.Factory<T> factory) {
|
||||
return factory.constructReader(this.segment, this.capTable, this.data, this.pointers, this.dataSize, this.pointerCount, this.nestingLimit);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue