Creating RpcMethod in My Own Code?

34 views
Skip to first unread message

chh...@mesosphere.io

unread,
Jun 7, 2017, 2:02:17 PM6/7/17
to grpc.io
Hey guys,

Please don't mind if you've seen the same question on the Gitter channel before.

I'm writing a function template handling multiple async gRPC calls in C++,
and I saw that in the generated .grpc.pb.cc file there is an array of method names like
"/package.Service/Method" (I assume it represents the endpoint of the RPC handler?)
that are used to create RpcMethod objects in the stub implementation.
I was wondering if this is considered as internal details that might change over different versions,
or if I can generate the same strings and create RpcMethod objects in my function to avoid using
&Service::Stub::AsyncMethod safely.

Thanks,
Chun-Hung

Vijay Pai

unread,
Jun 7, 2017, 2:38:43 PM6/7/17
to grpc.io, chh...@mesosphere.io
The method name choice is essentially stable since all supported languages interop with the same method names. That said, the existence of classes like RpcMethod is an internal detail and could change (just like all other details in the codegen output that are language-specific).

Chun-Hung Hsiao

unread,
Jun 7, 2017, 9:21:57 PM6/7/17
to Vijay Pai, grpc.io
Hi Vijay,

Thanks for your answer!

One follow-up question: Is it safe to create a stub through its constructor 
Service::Stub(channel) rather than the function Service::NewStub(channel)?
I'm asking this because I'm writing a function like this

template <typename T, typename Request, typename Response>
Response send(
    const shared_ptr<Channel>& channel,
    unique_ptr<ClientAsyncResponseReader<Response>(T::*method)(
        ClienContext*, const Request&, CompletionQueue*),
    const Request& request);

And I'd like to have all type arguments inferred automatically.
However, here I can only get T as a Stub class,
and it is impossible to infer the Service class,
so I cannot use Service::NewStub().

Thank you in advance,
Chun-Hung

Reply all
Reply to author
Forward
0 new messages