# 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);
        }
    });

- Related Packages
  Package
  Description
  com.codename1.annotations
  Codename One specific Java annotations used by the build pipeline and the ParparVM bytecode translator to mark methods and classes for special treatment -- e.g.
  com.codename1.annotations.rest
- Class
  Description
  GrpcClient
  Marks an interface as a gRPC client that the build-time annotation processor wires up to a generated gRPC-Web implementation.
  ProtoEnum
  Marks a Java `enum` as a Protocol Buffers enum.
  ProtoField
  Binds a `ProtoMessage` field to a protobuf field tag.
  ProtoField.WireKind
  Integer encoding selectors.
  ProtoMessage
  Marks a POJO (or Java 17+ record) as a Protocol Buffers message.
  Rpc
  Binds a `GrpcClient` interface method to a gRPC unary RPC.