Service Factory?

28 views
Skip to first unread message

rthompson....@gmail.com

unread,
Jun 29, 2009, 1:15:06 PM6/29/09
to Protocol Buffers
What can you do with a ServiceDescriptor? Is there a
DynamicServiceFactory similar to the DynamicMessageFactory where you
can instantiate a service when all you have is a ServiceDescriptor, or
some other equivalent way of doing it?

Thanks!

Kenton Varda

unread,
Jun 29, 2009, 6:56:14 PM6/29/09
to rthompson....@gmail.com, Protocol Buffers
Protocol Buffers does not include an RPC implementation, only abstract interfaces for one.  ServiceDescriptor is useful for implementing your own RPC system on top of protocol buffers -- it allows you to define your services directly in the .proto file even though protocol buffers itself does not provide RPC.

rthompson....@gmail.com

unread,
Jun 30, 2009, 12:26:55 PM6/30/09
to Protocol Buffers
Is there a C++ equivalent to

http://code.google.com/apis/protocolbuffers/docs/reference/python/google.protobuf-module.html
?

which is used to create protocol service and service stub classes from
ServiceDescriptor objects at runtime.

On Jun 29, 3:56 pm, Kenton Varda <ken...@google.com> wrote:
> Protocol Buffers does not include an RPC implementation, only abstract
> interfaces for one.  ServiceDescriptor is useful for implementing your own
> RPC system on top of protocol buffers -- it allows you to define your
> services directly in the .proto file even though protocol buffers itself
> does not provide RPC.
>
> On Mon, Jun 29, 2009 at 10:15 AM, rthompson.dtisoft....@gmail.com <

rthompson....@gmail.com

unread,
Jun 30, 2009, 2:05:46 PM6/30/09
to Protocol Buffers
More specifically the service_reflection class.

On Jun 30, 9:26 am, "rthompson.dtisoft....@gmail.com"
<rthompson.dtisoft....@gmail.com> wrote:
> Is there a C++ equivalent to
>
> http://code.google.com/apis/protocolbuffers/docs/reference/python/goo...

Kenton Varda

unread,
Jun 30, 2009, 4:33:57 PM6/30/09
to rthompson....@gmail.com, Protocol Buffers
Yes.  In C++ the protocol compiler will generate a service interface and a stub implementation when given a .proto file containing a service definition.  This is equivalent to what Python's service_reflection module does.

But this is not an RPC implementation.  You still have to add your own networking layer.

rthompson....@gmail.com

unread,
Jun 30, 2009, 5:03:09 PM6/30/09
to Protocol Buffers
Right, but I'm importing a .proto file at runtime using the Importer
class. This ultimately leaves me with a ServiceDescriptor. I'd like
to instantiate that Service from the ServiceDescriptor.
The python code has a ServiceStubBuilder class. Where is there a
ServiceStubBuilder in the C++ API?


On Jun 30, 1:33 pm, Kenton Varda <ken...@google.com> wrote:
> Yes.  In C++ the protocol compiler will generate a service interface and a
> stub implementation when given a .proto file containing a service
> definition.  This is equivalent to what Python's service_reflection module
> does.
> But this is not an RPC implementation.  You still have to add your own
> networking layer.
>
> On Tue, Jun 30, 2009 at 9:26 AM, rthompson.dtisoft....@gmail.com <
>
>
>
> rthompson.dtisoft....@gmail.com> wrote:
>
> > Is there a C++ equivalent to
>
> >http://code.google.com/apis/protocolbuffers/docs/reference/python/goo...

Kenton Varda

unread,
Jun 30, 2009, 5:08:39 PM6/30/09
to rthompson....@gmail.com, Protocol Buffers
Oh, you want something like DynamicMessage except for services?  DynamicServiceStub, perhaps?  There is no such thing included in the library, but it would be really trivial to write.  All you need to do is implement the Service interface as a wrapper around the RpcChannel interface.  Have GetRequestPrototype() and GetResponsePrototype() return DynamicMessages, and have CallMethod() just call the RpcChannel's CallMethod().

rthompson....@gmail.com

unread,
Jun 30, 2009, 7:28:01 PM6/30/09
to Protocol Buffers
I'm confused. Shouldn't I just create a class called
DynamicServiceStub and have it inherit from "class LIBPROTOBUF_EXPORT
Service"?
And then implement a method like "Service* DynamicServiceStub::New
(ServiceDescriptor*, RpcChannel* ) " ?

I'm just doing this on the client side. If we did this on the server
side, we'd have to implement the Rpc's at runtime...and that doesn't
sound like a good idea.

If I get this working, I'd like to pass it back to you guys to perhaps
use it in the next release.


On Jun 30, 2:08 pm, Kenton Varda <ken...@google.com> wrote:
> Oh, you want something like DynamicMessage except for services?
>  DynamicServiceStub, perhaps?  There is no such thing included in the
> library, but it would be really trivial to write.  All you need to do is
> implement the Service interface as a wrapper around the RpcChannel
> interface.  Have GetRequestPrototype() and GetResponsePrototype() return
> DynamicMessages, and have CallMethod() just call the RpcChannel's
> CallMethod().
> On Tue, Jun 30, 2009 at 2:03 PM, rthompson.dtisoft....@gmail.com <

Kenton Varda

unread,
Jun 30, 2009, 8:06:23 PM6/30/09
to rthompson....@gmail.com, Protocol Buffers
On Tue, Jun 30, 2009 at 4:28 PM, rthompson.dtisoft.com@gmail.com <rthompson.dtisoft.com@gmail.com> wrote:

I'm confused. Shouldn't I just create a class called
DynamicServiceStub and have it inherit from "class LIBPROTOBUF_EXPORT
Service"?
And then implement a method like "Service* DynamicServiceStub::New
(ServiceDescriptor*, RpcChannel* )  " ?

Yes, that is what I was suggesting.
 
If I get this working, I'd like to pass it back to you guys to perhaps
use it in the next release.

Honestly, I'm having some trouble thinking of use cases for this.  How do you intend to use this class?  Why not just call RpcChannel directly instead?

rthompson....@gmail.com

unread,
Jul 1, 2009, 7:04:28 PM7/1/09
to Protocol Buffers
That worked! Thanks!

On Jun 30, 5:06 pm, Kenton Varda <ken...@google.com> wrote:
> On Tue, Jun 30, 2009 at 4:28 PM, rthompson.dtisoft....@gmail.com <
Reply all
Reply to author
Forward
0 new messages