(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.
/usr/local/include/d/orange/serialization/Serializer.di(254): 
Error: function pointer *serializer (Serializer, const(Object), 
Mode) is not callable using argument types (Serializer, 
MyInterface, Mode)
/usr/local/include/d/orange/serialization/Serializer.di(902): 
Error: template 
orange.serialization.Serializer.Serializer.serializeBaseTypes 
cannot deduce function from argument types !()(MyInterface), 
candidates are:
/usr/local/include/d/orange/serialization/Serializer.di(970):     
    
orange.serialization.Serializer.Serializer.serializeBaseTypes(T : 
Object)(inout T value)
/usr/local/include/d/orange/serialization/Serializer.di(259): 
Error: template instance 
orange.serialization.Serializer.Serializer.objectStructSerializeHelper!(MyInterface) error instantiating
/usr/local/include/d/orange/serialization/Serializer.di(157):     
    instantiated from here: serializeObject!(MyInterface)
/usr/local/include/d/orange/serialization/Serializer.di(386):     
    instantiated from here: serializeInternal!(MyInterface)
/usr/local/include/d/orange/serialization/Serializer.di(892):     
    instantiated from here: serializePointer!(MyInterface*)
/usr/local/include/d/orange/serialization/Serializer.di(259):     
    ... (2 instantiations, -v to show) ...
/usr/local/include/d/orange/serialization/Serializer.di(129):     
    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