how to get grpc method option

1,741 views
Skip to first unread message

soun...@gmail.com

unread,
Apr 23, 2016, 2:45:15 PM4/23/16
to grpc.io
hi guys:

I have a simple grpc server called server.proto

code below:

extend google.protobuf.MethodOptions {
    Message msg = 50056;
}

message Message {
    string tool = 1;
}

service Hello {
    rpc Say(Request) returns (Response) {
        option (msg).tool = "telephone";
    }
}

This could genertate file called server_pb2.py

But how to get method Say Option "tool" ?

Thanks

Jan Tattermusch

unread,
Jun 7, 2016, 6:44:39 PM6/7/16
to grpc.io, soun...@gmail.com
Hi,

it is unclear to me what your question actually is.

Guo Jing

unread,
Jun 7, 2016, 9:15:32 PM6/7/16
to Jan Tattermusch, grpc.io
I want to get customized option from gRPC server identified file with Python. 
--
-----------------------
ret

Nathaniel Manista

unread,
Jun 8, 2016, 12:41:06 PM6/8/16
to Guo Jing, Jan Tattermusch, grpc.io
I'm also unclear, but that's likely because I don't know all the features of Protocol Buffers.

To help us understand, could you write some sample application code illustrating what you would like your code to be able to do and how you would like gRPC to behave?
-Nathaniel

soun...@gmail.com

unread,
Jun 8, 2016, 1:05:33 PM6/8/16
to grpc.io, soun...@gmail.com
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.

I want this because I have a project call gRPC gateway, which is translate gRPC to HTTP. https://github.com/qiajigou/c3po-grpc-gateway .

I posted this on github issue https://github.com/grpc/grpc/issues/6276 .


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():
                        method_mapping[m.name][i.name] = j
    return method_mapping

在 2016年4月24日星期日 UTC+8上午2:45:15,soun...@gmail.com写道:

Eric Anderson

unread,
Jun 8, 2016, 6:22:05 PM6/8/16
to Nathaniel Manista, Guo Jing, Jan Tattermusch, grpc.io
On Wed, Jun 8, 2016 at 9:40 AM, 'Nathaniel Manista' via grpc.io <grp...@googlegroups.com> wrote:
I'm also unclear, but that's likely because I don't know all the features of Protocol Buffers.

Protobuf options would generally be provided by providing the raw protobuf descriptors for methods. In Java, that's the sort of thing that would be available after supporting grpc reflection. I'd expect it would be similar in Python, but it would depend on the reflection design in Python.

Masood Malekghassemi

unread,
Jun 8, 2016, 6:35:43 PM6/8/16
to Eric Anderson, Nathaniel Manista, Guo Jing, Jan Tattermusch, grpc.io
We don't yet support method options on generated stubs.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oOTJ3qMhxoNGD%2BveHGDp4bfgA5YNRV8xMRQ_7VRrJAh1Q%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Guo Jing

unread,
Jun 9, 2016, 5:38:28 AM6/9/16
to Masood Malekghassemi, Eric Anderson, Nathaniel Manista, Jan Tattermusch, grpc.io
Anyway thanks. 


2016年6月9日星期四,Masood Malekghassemi <at...@google.com> 写道:
We don't yet support method options on generated stubs.
On Wed, Jun 8, 2016 at 3:21 PM, 'Eric Anderson' via grpc.io <grp...@googlegroups.com> wrote:
On Wed, Jun 8, 2016 at 9:40 AM, 'Nathaniel Manista' via grpc.io <grp...@googlegroups.com> wrote:
I'm also unclear, but that's likely because I don't know all the features of Protocol Buffers.

Protobuf options would generally be provided by providing the raw protobuf descriptors for methods. In Java, that's the sort of thing that would be available after supporting grpc reflection. I'd expect it would be similar in Python, but it would depend on the reflection design in Python.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages