chai2010 / protorpc

prtorpc(2013-2021): Google Protocol Protobufs RPC for Go.
http://godoc.org/github.com/chai2010/protorpc
BSD 3-Clause "New" or "Revised" License
59 stars 14 forks source link

Question regarding generating Stub code in Golang from .proto file using protorpc #1

Closed acmeofevolution closed 8 years ago

acmeofevolution commented 9 years ago

Hi,

I have to implement an RPC client in Golang to communicate with a C++ service (running SunRPC protocol). The RPC service is defined using a .proto file (Google protocol buffers). I was wondering if I can use your version of protorpc as available here to generate the right stub Go classes which then can use SunRPC protocol for the transport layer. As after looking at your examples, I see the generated .pb.go files doesn't look similar to the generated stubs (.h & .cc using --cpp_out option to protoc) from the same .proto file. Also, I do have protoc version 2.6.1 but with that --go_out option and option cc_generic_services = true in .proto file, it doesn't generate any RPC code in .pb.go file as you show in your examples here. Please let me know from where I can get the protoc to generate the right stubs.

I will really appreciate your help in this matter. Look forward to hearing from you.

Thanks in advance.

chai2010 commented 9 years ago

The Go version rpc code start here: https://github.com/chai2010/protorpc/blob/master/internal/service.pb/arith.pb.go#L75

It use "net/rpc" package's framework: https://github.com/chai2010/protorpc/blob/master/internal/service.pb/arith.pb.go#L165

The C++ version use the Go style, not the origin Protobuf RPC style.

If you need use Go RPC client to connect the SunRPC RPC service. You can try modify the client plugin and the rpc protocol:

https://github.com/chai2010/protorpc/blob/master/client.go https://github.com/chai2010/protorpc/blob/master/conn.go https://github.com/chai2010/protorpc/blob/master/wire.go

The protorpc protocol is defined here: https://github.com/chai2010/protorpc/blob/master/internal/wire.pb/wire.proto

acmeofevolution commented 9 years ago

Thanks for your reply. Sorry, but can you please clarify if I can use your existing protorpc to generate the correct Go Client Stub or even that would require me to extend the current protorpc plugin to generate the right "Go Client Stub" ?

chai2010 commented 9 years ago

The most important point is the RPC protocol(Server and Client must use the same protocol): https://github.com/chai2010/protorpc/blob/master/internal/wire.pb/wire.proto

The second important is the RPC protocol implement: https://github.com/chai2010/protorpc/blob/master/client.go https://github.com/chai2010/protorpc/blob/master/conn.go https://github.com/chai2010/protorpc/blob/master/wire.go

The stub code is not the important thing. You can write it by hand. (If you can write the stub by hand, then you can generate the stub by tool. like this: https://github.com/chai2010/protorpc/blob/master/protoc-gen-go/protorpc.go)