1*890232f2SAndroid Build Coastguard Workerimport sys 2*890232f2SAndroid Build Coastguard Workerimport argparse 3*890232f2SAndroid Build Coastguard Workerimport grpc 4*890232f2SAndroid Build Coastguard Worker 5*890232f2SAndroid Build Coastguard Workersys.path.insert(0, '../../../../../flatbuffers/python') 6*890232f2SAndroid Build Coastguard Worker 7*890232f2SAndroid Build Coastguard Workerimport flatbuffers 8*890232f2SAndroid Build Coastguard Workerfrom models import HelloReply, HelloRequest, greeter_grpc_fb 9*890232f2SAndroid Build Coastguard Worker 10*890232f2SAndroid Build Coastguard Workerparser = argparse.ArgumentParser() 11*890232f2SAndroid Build Coastguard Workerparser.add_argument("port", help="server port to connect to", default=3000) 12*890232f2SAndroid Build Coastguard Workerparser.add_argument("name", help="name to be sent to server", default="flatbuffers") 13*890232f2SAndroid Build Coastguard Worker 14*890232f2SAndroid Build Coastguard Workerdef say_hello(stub, hello_request): 15*890232f2SAndroid Build Coastguard Worker reply = stub.SayHello(hello_request) 16*890232f2SAndroid Build Coastguard Worker r = HelloReply.HelloReply.GetRootAs(reply) 17*890232f2SAndroid Build Coastguard Worker print(r.Message()) 18*890232f2SAndroid Build Coastguard Worker 19*890232f2SAndroid Build Coastguard Workerdef say_many_hellos(stub, hello_request): 20*890232f2SAndroid Build Coastguard Worker greetings = stub.SayManyHellos(hello_request) 21*890232f2SAndroid Build Coastguard Worker for greeting in greetings: 22*890232f2SAndroid Build Coastguard Worker r = HelloReply.HelloReply.GetRootAs(greeting) 23*890232f2SAndroid Build Coastguard Worker print(r.Message()) 24*890232f2SAndroid Build Coastguard Worker 25*890232f2SAndroid Build Coastguard Workerdef main(): 26*890232f2SAndroid Build Coastguard Worker args = parser.parse_args() 27*890232f2SAndroid Build Coastguard Worker 28*890232f2SAndroid Build Coastguard Worker with grpc.insecure_channel('localhost:' + args.port) as channel: 29*890232f2SAndroid Build Coastguard Worker builder = flatbuffers.Builder() 30*890232f2SAndroid Build Coastguard Worker ind = builder.CreateString(args.name) 31*890232f2SAndroid Build Coastguard Worker HelloRequest.HelloRequestStart(builder) 32*890232f2SAndroid Build Coastguard Worker HelloRequest.HelloRequestAddName(builder, ind) 33*890232f2SAndroid Build Coastguard Worker root = HelloRequest.HelloRequestEnd(builder) 34*890232f2SAndroid Build Coastguard Worker builder.Finish(root) 35*890232f2SAndroid Build Coastguard Worker output = bytes(builder.Output()) 36*890232f2SAndroid Build Coastguard Worker stub = greeter_grpc_fb.GreeterStub(channel) 37*890232f2SAndroid Build Coastguard Worker say_hello(stub, output) 38*890232f2SAndroid Build Coastguard Worker say_many_hellos(stub, output) 39*890232f2SAndroid Build Coastguard Worker 40*890232f2SAndroid Build Coastguard Workermain()