hello
I know protobuf has custom options. C++/GO support this maybe. I think I should read these options in Python. That is the problem I meet.
I have a very simple requirement. ONE PROTOBUF, TWO SERVICES CODE. one is gRPC code, other is HTTP code. Even I could to more.
This is protobuf code:
```
service SimpleService {
rpc Hello(HelloRequest) returns (HelloResponse){
option (mo).method = "GET";
option (mo).url = "/hello";
}
}
```
After generate code into server_pb2, I could do like:
```
from xx import server_pb2
server = server_pb2.beta_Server()
server.start()
# this is gRPC server
```
or
```
from xx import server_pb2
@app.route(server_pb2.Hello.url, method=server_pb2.Hello.method)
def hello():
return
# This is a http
```
or... A lot we could do.
Any way I get the options, not official supported, but work.
def get_service_identify_from_pb_file(pb2):
method_mapping = dict()
p = descriptor_pb2.FileDescriptorProto()
pb2.DESCRIPTOR.CopyToProto(p)
for s in p.service:
for m in s.method:
if not method_mapping.get(
m.name):
method_mapping[
m.name] = dict()
for k, v in m.options._fields.items():
if hasattr(v, '_fields'):
for i, j in v._fields.items():
return method_mapping