xref: /aosp_15_r20/external/flatbuffers/grpc/examples/README.md (revision 890232f25432b36107d06881e0a25aaa6b473652)
1*890232f2SAndroid Build Coastguard Worker## Languages known issues
2*890232f2SAndroid Build Coastguard Worker
3*890232f2SAndroid Build Coastguard Worker### Python
4*890232f2SAndroid Build Coastguard Worker
5*890232f2SAndroid Build Coastguard Worker- Assert the type required in your server/client since python is able to receive `Bytes array` or `utf8 strings`.
6*890232f2SAndroid Build Coastguard Worker
7*890232f2SAndroid Build Coastguard Worker```python
8*890232f2SAndroid Build Coastguard Workerdef SayHello(self, request, context):
9*890232f2SAndroid Build Coastguard Worker    # request might be a byte array or a utf8 string
10*890232f2SAndroid Build Coastguard Worker
11*890232f2SAndroid Build Coastguard Worker    r = HelloRequest.HelloRequest().GetRootAs(request, 0)
12*890232f2SAndroid Build Coastguard Worker    reply = "Unknown"
13*890232f2SAndroid Build Coastguard Worker    if r.Name():
14*890232f2SAndroid Build Coastguard Worker        reply = r.Name()
15*890232f2SAndroid Build Coastguard Worker    # Issues might happen if type checking isnt present.
16*890232f2SAndroid Build Coastguard Worker    # thus encoding it as a `reply.decode('UTF-8')`
17*890232f2SAndroid Build Coastguard Worker    return build_reply("welcome " + reply.decode('UTF-8'))
18*890232f2SAndroid Build Coastguard Worker
19*890232f2SAndroid Build Coastguard Worker```
20*890232f2SAndroid Build Coastguard Worker
21*890232f2SAndroid Build Coastguard WorkerThis can be prevented by making sure all the requests coming to/from python are `Bytes array`
22*890232f2SAndroid Build Coastguard Worker
23*890232f2SAndroid Build Coastguard Worker```python
24*890232f2SAndroid Build Coastguard Workerdef say_hello(stub, builder):
25*890232f2SAndroid Build Coastguard Worker    hello_request = bytes(builder.Output())
26*890232f2SAndroid Build Coastguard Worker    reply = stub.SayHello(hello_request)
27*890232f2SAndroid Build Coastguard Worker    r = HelloReply.HelloReply.GetRootAs(reply)
28*890232f2SAndroid Build Coastguard Worker    print(r.Message())
29*890232f2SAndroid Build Coastguard Worker```
30*890232f2SAndroid Build Coastguard Worker
31*890232f2SAndroid Build Coastguard Worker### Go
32*890232f2SAndroid Build Coastguard Worker
33*890232f2SAndroid Build Coastguard Worker- Always requires the `content-type` of the payload to be set to `application/grpc+flatbuffers`
34*890232f2SAndroid Build Coastguard Worker
35*890232f2SAndroid Build Coastguard Workerexample: `.SayHello(ctx, b, grpc.CallContentSubtype("flatbuffers"))`