鉴于此架构
struct TestObject
{
value1 @0 : Int32 = -5;
value2 @1 : Float32 = 9.4;
}
struct TestContainer
{
object @0: TestObject;
}
是否可以在c ++代码中从TestObject :: Builder获取AnyPointer :: Builder?
这就是我想要做的事情:
::capnp::MallocMessageBuilder message;
auto container = message.initRoot<TestContainer>();
TestObject::Builder objBuilder = container.initObject();
//Get an AnyPointer
capnp::AnyPointer::Builder anyBuilder = capnp::toAny( objBuilder )(); //No this does not work.
MyTestObject test( 41, 643.7f );
test.serialise( anyBuilder );
我要做的是拥有一个带有单个参数类型的抽象接口 例如
class ISerialisable
{
virtual void serialise(capnp::AnyPointer::Builder& any) = 0;
}
class MyTestObject: public ISerialisable
{
void serialise(capnp::AnyPointer::Builder& any) override
{
auto testObjBuilder = any.getAs<TestObject>(); or should initAs be used?
testObject.setValue1( whatever1);
testObject.setValue2( whatever2);
}
}
是否有可能走这条路?