(De)Serializing interfaces

nims via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 23 00:57:38 PDT 2015

On Sunday, 23 August 2015 at 03:25:27 UTC, Kapps wrote:
> I've never used Orange, but one thing you could try is casting 
> your object from MyInterface to Object, and registering the 
> type Foobar like in 
> http://dsource.org/projects/orange/wiki/Tutorials/SerializeBase, then serializing/deserializing it as Object rather than MyInterface. I'm not sure if this will work, but it's worth a try if it doesn't handle interfaces. Interfaces are a bit odd in some ways, as they are not necessarily classes

> (and thus not implicitly convertible to Object)
I suspect that's what Orange is having trouble with.
Error: function pointer *serializer (Serializer, const(Object), 
Mode) is not callable using argument types (Serializer, 
MyInterface, Mode)
Error: template 
cannot deduce function from argument types !()(MyInterface), 
candidates are:
orange.serialization.Serializer.Serializer.serializeBaseTypes(T : 
Object)(inout T value)
Error: template instance 
orange.serialization.Serializer.Serializer.objectStructSerializeHelper!(MyInterface) error instantiating
    instantiated from here: serializeObject!(MyInterface)
    instantiated from here: serializeInternal!(MyInterface)
    instantiated from here: serializePointer!(MyInterface*)
    ... (2 instantiations, -v to show) ...
    instantiated from here: serializeInternal!(Foobar)
test.d(27):        instantiated from here: serialize!(Foobar)

I also can't cast MyInterface to Foo because at compile time I 
have no idea whether Foo or another type implementing MyInterface 
is behind it. Registering doesn't change that.

More information about the Digitalmars-d-learn mailing list