Dávid Tóth
Dávid Tóth

Reputation: 3245

gRPC generated code misses service implementation

Following the tutorial I successfully generated the code I expected with protocol buffers:

protoc service.proto --proto_path="../proto/" --cpp_out="../cxx/gen/" --plugin=protoc-gen-grpc=`which grpc_cpp_plugin`

The models are generated as usable classes without error, but the service implementation differs from the one described in the above tutorial. The proto file looks like this:

syntax = "proto3";
option cc_enable_arenas = true;
option cc_generic_services = true;

package my_package;

message Service_slot{...}

message Slot_status{...}

message Slot_request{...}

message Service_slot{...}

service My_service{
  rpc add_slot(Service_slot) returns (Slot_status) {}
  rpc update_slot(Service_slot) returns (Slot_status) {}
  rpc request_action(Slot_request) returns (Slot_status) {}
}

What I could identify as a service looks like this(in service.pb.h):

class My_service: public ::google::protobuf::Service {
 protected:
  // This class should be treated as an abstract interface.
  inline My_service() {};
 public:
  virtual ~My_service();

  typedef My_service_Stub Stub;

  static const ::google::protobuf::ServiceDescriptor* descriptor();

  virtual void add_slot(::google::protobuf::RpcController* controller,
                       const ::my_package::Service_slot* request,
                       ::my_package::Slot_status* response,
                       ::google::protobuf::Closure* done);
  //... (others left out for clairty)
 private:
  GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(My_service);
};

but it's nothing like what' described in the tutorial. Not even sure how to provide those arguments. I've done this in Java, and there the server I implemented was based on a classname ending with grpc, but I found nothing like this here.

Upvotes: 1

Views: 787

Answers (1)

Dávid Tóth
Dávid Tóth

Reputation: 3245

I was missing the --grpc_out="../cxx/gen" argument. With the command

protoc service.proto --proto_path="../proto/" --cpp_out="../cxx/gen/" --grpc_out="../cxx/gen --plugin=protoc-gen-grpc=`which grpc_cpp_plugin`

The service code now generates into the service.grpc.pb.cc file.

Upvotes: 2

Related Questions