Java IDL for gRPC / protobuf (Protocl Buffers)

2019-04-17 06:31发布

问题:

Is it possible to define Protocol Buffers using Java?

That is instead of

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

I would like to have

public interface Greeter {
    @Grpc
    HelloReply sayHello (HelloRequest req);

}

@GrpcMessage()
public class HelloReply{
    @GrpcField(1)
    string name;
} 

That is annotation like Hibernate/JPA over my POJO, instead of heaps of generated code.

I only could find Protocol Buffers Dynamic Schema https://github.com/os72/protobuf-dynamic

回答1:

Have a look at protostuff: https://github.com/protostuff/protostuff It supports what you want for protobuf (although not for grpc, perhaps it can be enhanced)