mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 23:42:02 +00:00
Working on a python example plus fixing python grpc code (#6456)
Refactored python grpc code gen Adds example server & client + fixes ci Fixes generated code Making sure we encode the reply string as utf8 Adds Readme details to clarify issue regarding encoding when python is sending/receiving
This commit is contained in:
@@ -1,5 +1,33 @@
|
||||
## Languages known issues
|
||||
|
||||
### Python
|
||||
|
||||
- Assert the type required in your server/client since python is able to receive `Bytes array` or `utf8 strings`.
|
||||
|
||||
```python
|
||||
def SayHello(self, request, context):
|
||||
# request might be a byte array or a utf8 string
|
||||
|
||||
r = HelloRequest.HelloRequest().GetRootAs(request, 0)
|
||||
reply = "Unknown"
|
||||
if r.Name():
|
||||
reply = r.Name()
|
||||
# Issues might happen if type checking isnt present.
|
||||
# thus encoding it as a `reply.decode('UTF-8')`
|
||||
return build_reply("welcome " + reply.decode('UTF-8'))
|
||||
|
||||
```
|
||||
|
||||
This can be prevented by making sure all the requests coming to/from python are `Bytes array`
|
||||
|
||||
```python
|
||||
def say_hello(stub, builder):
|
||||
hello_request = bytes(builder.Output())
|
||||
reply = stub.SayHello(hello_request)
|
||||
r = HelloReply.HelloReply.GetRootAs(reply)
|
||||
print(r.Message())
|
||||
```
|
||||
|
||||
### Go
|
||||
|
||||
- Always requires the `content-type` of the payload to be set to `application/grpc+flatbuffers`
|
||||
|
||||
Reference in New Issue
Block a user