Implementing generic servers using pycapnp

29 views
Skip to first unread message

Vaci

unread,
Jun 22, 2020, 9:32:55 AM6/22/20
to Cap'n Proto
Given a generic Capnproto interface, such as:

interface Foo(X)
{
    bar @0 (baz :X);
}

How would one implement a server for Foo using pycapnp?

The following python code doesn't work, presumably as Foo.Server is not a concrete type:

class MyFoo(Foo.Server):
    def bar_context(self, ctx, **kwargs):
         pass

When I attempt to pass my server as an interface parameter, I get the error:

"failed: expected capability.getSchema(),extends(interfaceType); Value type mismatch."

I'd be happy to use a Foo(Any).Server, if that was all I could get...

Vaci


Kenton Varda

unread,
Jun 22, 2020, 9:58:10 AM6/22/20
to Vaci, Cap'n Proto
Hi Vaci,

I suspect pycapnp currently lacks support for specifying generic type parameters. You might want to file an issue on pycapnp's github about that.

However, I suspect you can work around it by defining the type specializations you need in a .capnp file (which could be a private file used by your server), like:

    interface FooMyType extends(Foo(MyType)) {}
    # Extend FooMyType in Python when you really want to extend Foo(MyType).

    interface FooAny extends(Foo) {}
    # Extend FooAny in Python when you really want to implement a generic Foo interface.

-Kenton

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/0e8ee233-f7a1-4bee-ad55-71c83225ffc4o%40googlegroups.com.

Vaci

unread,
Jun 22, 2020, 10:11:52 AM6/22/20
to Cap'n Proto
Hi Kenton,

Thanks, that's exactly the solution I came up with!

Regards,
Vaci

PS On an unrelated note,I've found ekam to be a really neat tool!
Reply all
Reply to author
Forward
0 new messages