The docs are super unclear on this, and I'm not even sure I got this right.
First, you need to select what shape of reference you'll use: "ez" or struct (although you could maybe use a struct type as ez? The docs don't discuss this at all.)
If you go with ez, you'll use it like so:
# Client
calculator = client.ez_restore('calculator').cast_as(calculator_capnp.Calculator)
# Server
def restore(ref_id):
if ref_id == 'calculator':
return Calculator()
else:
raise Exception('Unrecognized ref passed to restore')
server = capnp.TwoPartyServer(sock, restore)
Otherwise, your reference can be a struct, and you would use code like this:
# Client
calculator = client.restore(calculator_capnp.ObjRef.new_message(id='calculator')).cast_as(calculator_capnp.Calculator)
# Server
class ObjRestorer(calculator_capnp.ObjRef.Restorer):
def restore(self, objref):
if objref.id == 'calculator':
return Calculator()
else:
raise Exception('Unrecognized ref passed to restore')
server = capnp.TwoPartyServer(sock, ObjRestorer())
A given RPC must have a single restorer style and type, I think. You certainly cannot use multiple struct restorers.