def _service_handle(self, buf): service, arg = call.decode_req(buf) with self.lock: if service in self.service_handlers: hanlder = self.service_handlers[service] else: return call.encode_res_error("service doesn't exist") try: return call.encode_res(hanlder(arg)) except ServiceFailed as e: return call.encode_res_error(str(e))
def test_decode_res(self): self.assertEqual(123, call.decode_res(call.encode_res(123)))
def test_encode_res(self): self.assertEqual(msgpack.packb(['ok', 123]), call.encode_res(123))