mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-18 18:18:55 +00:00
[gRPC] Update the code generator for Python to produce typed handlers (#8326)
* Move `namer.h` and `idl_namer.h` to `include/codegen` so they can be reused from `grpc` dirqectory. * [gRPC] Update the Python generator to produce typed handlers and Python stubs if requested. * [gRPC] Document the newly added compiler flags.
This commit is contained in:
58
tests/service_test_generated.py
Normal file
58
tests/service_test_generated.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace: example
|
||||
|
||||
import flatbuffers
|
||||
from typing import Any
|
||||
class HelloRequest(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf, offset: int = 0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = HelloRequest()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def GetRootAsHelloRequest(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
# HelloRequest
|
||||
def Init(self, buf: bytes, pos: int):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
def HelloRequestStart(builder: flatbuffers.Builder):
|
||||
builder.StartObject(0)
|
||||
|
||||
def HelloRequestEnd(builder: flatbuffers.Builder) -> int:
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
|
||||
class HelloResponse(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf, offset: int = 0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = HelloResponse()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def GetRootAsHelloResponse(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
# HelloResponse
|
||||
def Init(self, buf: bytes, pos: int):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
def HelloResponseStart(builder: flatbuffers.Builder):
|
||||
builder.StartObject(0)
|
||||
|
||||
def HelloResponseEnd(builder: flatbuffers.Builder) -> int:
|
||||
return builder.EndObject()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user