Esempio n. 1
0
 def CallMethod(self, method_descriptor, rpc_controller, request,
                response_class, done):
     call = Call()
     call.method = method_descriptor.name
     call.request = request.SerializeToString()
     self.token += 1
     call.token = self.token
     d = Deferred()
     d.addCallback(self.parseResponse, response_class)
     d.addCallback(done)
     self.pending[self.token] = d
     box = Box()
     box.call = call.SerializeToString()
     self.sendString(box.SerializeToString())
Esempio n. 2
0
 def stringReceived(self, data):
     box = Box()
     box.ParseFromString(data)
     if box.call != "":
         call = Call()
         call.ParseFromString(box.call)
         method = self.service.GetDescriptor().FindMethodByName(call.method)
         if method:
             request = self.service.GetRequestClass(method)()
             request.ParseFromString(call.request)
             controller = Controller()
             d = Deferred()
             d.addCallback(self.buildResult, call)
             d.addCallback(self.boxResult)
             d.addCallback(
                 lambda box: self.sendString(box.SerializeToString()))
             self.service.CallMethod(method, controller, request,
                                     d.callback)
     elif box.result != "":
         result = Result()
         result.ParseFromString(box.result)
         token = result.token
         if self.pending.has_key(token):
             self.pending[token].callback(result)