All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.grpc.cli.DescribeCommand Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.grpc.cli;

import java.util.List;

import com.google.protobuf.ByteString;
import com.google.protobuf.DescriptorProtos;
import com.google.protobuf.util.JsonFormat;

import io.grpc.reflection.v1.MutinyServerReflectionGrpc;
import io.grpc.reflection.v1.ServerReflectionRequest;
import io.grpc.reflection.v1.ServerReflectionResponse;
import io.smallrye.mutiny.Multi;
import picocli.CommandLine;

@CommandLine.Command(name = "describe", sortOptions = false, header = "gRPC describe")
public class DescribeCommand extends GcurlBaseCommand {

    public String getAction() {
        return "describe";
    }

    @Override
    protected void execute(MutinyServerReflectionGrpc.MutinyServerReflectionStub stub) {
        ServerReflectionRequest request = ServerReflectionRequest
                .newBuilder()
                .setFileContainingSymbol(unmatched.get(1))
                .build();
        Multi response = stub.serverReflectionInfo(Multi.createFrom().item(request));
        response.toUni().map(r -> {
            List list = r.getFileDescriptorResponse().getFileDescriptorProtoList();
            for (ByteString bs : list) {
                try {
                    DescriptorProtos.FileDescriptorProto fdp = DescriptorProtos.FileDescriptorProto.parseFrom(bs);
                    log(JsonFormat.printer().print(fdp));
                } catch (RuntimeException e) {
                    throw e;
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            return null;
        }).await().indefinitely();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy