Package com.codename1.annotations.grpc


package com.codename1.annotations.grpc

gRPC-Web client annotations. GrpcClient marks an interface as a gRPC client; Rpc binds each method to a unary RPC. ProtoMessage marks a POJO as a protobuf message; ProtoField tags each field; ProtoEnum marks an enum as protobuf-encoded.

The Codename One Maven plugin's cn1:generate-grpc mojo emits these annotations from a user-supplied .proto file; the RestClient / ProtoMessage annotation processors then emit the implementation code at build time. End-to-end usage:

// generated by cn1:generate-grpc
@ProtoMessage
public final class HelloRequest {
    @ProtoField(tag = 1) public String name;
}

@ProtoMessage
public final class HelloReply {
    @ProtoField(tag = 1) public String message;
}

@GrpcClient("helloworld.Greeter")
public interface GreeterGrpc {
    @Rpc("SayHello")
    void sayHello(HelloRequest req,
                  OnComplete<Response<HelloReply>> callback);

    static GreeterGrpc of(String baseUrl) {
        return GrpcClients.create(GreeterGrpc.class, baseUrl);
    }
}

// call site
GreeterGrpc g = GreeterGrpc.of("https://api.example.com");
HelloRequest req = new HelloRequest();
req.name = "world";
g.sayHello(req, resp -> {
    if (resp.getResponseCode() == 200) {
        System.out.println(resp.getResponseData().message);
    }
});
  • Class
    Description
    Marks an interface as a gRPC client that the build-time annotation processor wires up to a generated gRPC-Web implementation.
    Marks a Java enum as a Protocol Buffers enum.
    Binds a ProtoMessage field to a protobuf field tag.
    Integer encoding selectors.
    Marks a POJO (or Java 17+ record) as a Protocol Buffers message.
    Binds a GrpcClient interface method to a gRPC unary RPC.