def Sum(self, Int_iterator, context): result = 0 for i in Int_iterator: result += i.value rsp = helloWorld_pb2.Int(value=result) return rsp
def getSumAsync(stub, value): req = (helloWorld_pb2.Int(value=i) for i in range(value)) rspFuture = stub.Sum.future(req) rsp = rspFuture.result() print("Async") print(f"Sum range({value}) => {rsp.value}")
def getDoubleAsync(stub, value): req = helloWorld_pb2.Int(value=value) rspFuture = stub.Double.future(req) rsp = rspFuture.result() print("Async") print(f"double {value} => {rsp.value}")
def DoubleIter(self, Int_iterator, context): for i in Int_iterator: rsp = helloWorld_pb2.Int(value=i.value * 2) yield rsp
def Range(self, Int, context): for i in range(Int.value): rsp = helloWorld_pb2.Int(value=i) yield rsp
def Double(self, Int, context): rsp = helloWorld_pb2.Int(value=Int.value * 2) return rsp
def getDoubleIter(stub, value): req = (helloWorld_pb2.Int(value=i) for i in range(value)) rsp = stub.DoubleIter(req) for i in rsp: print(f"double range({value}) => {i.value * 2}")
def getSumSync(stub, value): req = (helloWorld_pb2.Int(value=i) for i in range(value)) rsp = stub.Sum(req) print(f"Sum range({value}) => {rsp.value}")
def getRange(stub, value): req = helloWorld_pb2.Int(value=value) rsp = stub.Range(req) for i in rsp: print(f"range {value} => {i.value}")
def getDoubleSync(stub, value): req = helloWorld_pb2.Int(value=value) rsp = stub.Double(req) print(f"double {value} => {rsp.value}")