package cn.thinkingdata.logbus.grpc.demo.proto;

import com.google.protobuf.InvalidProtocolBufferException;

import static io.grpc.MethodDescriptor.generateFullMethodName;

/**
 */
public final class ParserGrpc {

  private ParserGrpc() {}

  public static final String SERVICE_NAME = "proto.Parser";

  // Static method descriptors that strictly reflect the proto.
  private static volatile io.grpc.MethodDescriptor<ParserOuterClass.Request,
      ParserOuterClass.Response> getParseMethod;

  @io.grpc.stub.annotations.RpcMethod(
      fullMethodName = SERVICE_NAME + '/' + "Parse",
      requestType = ParserOuterClass.Request.class,
      responseType = ParserOuterClass.Response.class,
      methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
  public static io.grpc.MethodDescriptor<ParserOuterClass.Request,
      ParserOuterClass.Response> getParseMethod() {
    io.grpc.MethodDescriptor<ParserOuterClass.Request, ParserOuterClass.Response> getParseMethod;
    if ((getParseMethod = ParserGrpc.getParseMethod) == null) {
      synchronized (ParserGrpc.class) {
        if ((getParseMethod = ParserGrpc.getParseMethod) == null) {
          ParserGrpc.getParseMethod = getParseMethod =
              io.grpc.MethodDescriptor.<ParserOuterClass.Request, ParserOuterClass.Response>newBuilder()
              .setType(io.grpc.MethodDescriptor.MethodType.UNARY)
              .setFullMethodName(generateFullMethodName(SERVICE_NAME, "Parse"))
              .setSampledToLocalTracing(true)
              .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
                  ParserOuterClass.Request.getDefaultInstance()))
              .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
                  ParserOuterClass.Response.getDefaultInstance()))
              .setSchemaDescriptor(new ParserMethodDescriptorSupplier("Parse"))
              .build();
        }
      }
    }
    return getParseMethod;
  }

  /**
   * Creates a new async stub that supports all call types for the service
   */
  public static ParserStub newStub(io.grpc.Channel channel) {
    io.grpc.stub.AbstractStub.StubFactory<ParserStub> factory =
      new io.grpc.stub.AbstractStub.StubFactory<ParserStub>() {
        @java.lang.Override
        public ParserStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
          return new ParserStub(channel, callOptions);
        }
      };
    return ParserStub.newStub(factory, channel);
  }

  /**
   * Creates a new blocking-style stub that supports unary and streaming output calls on the service
   */
  public static ParserBlockingStub newBlockingStub(
      io.grpc.Channel channel) {
    io.grpc.stub.AbstractStub.StubFactory<ParserBlockingStub> factory =
      new io.grpc.stub.AbstractStub.StubFactory<ParserBlockingStub>() {
        @java.lang.Override
        public ParserBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
          return new ParserBlockingStub(channel, callOptions);
        }
      };
    return ParserBlockingStub.newStub(factory, channel);
  }

  /**
   * Creates a new ListenableFuture-style stub that supports unary calls on the service
   */
  public static ParserFutureStub newFutureStub(
      io.grpc.Channel channel) {
    io.grpc.stub.AbstractStub.StubFactory<ParserFutureStub> factory =
      new io.grpc.stub.AbstractStub.StubFactory<ParserFutureStub>() {
        @java.lang.Override
        public ParserFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
          return new ParserFutureStub(channel, callOptions);
        }
      };
    return ParserFutureStub.newStub(factory, channel);
  }

  /**
   */
  public static abstract class ParserImplBase implements io.grpc.BindableService {

    /**
     */
    public void parse(ParserOuterClass.Request request,
        io.grpc.stub.StreamObserver<ParserOuterClass.Response> responseObserver) {
      io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getParseMethod(), responseObserver);
    }

    @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
      return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
          .addMethod(
            getParseMethod(),
            io.grpc.stub.ServerCalls.asyncUnaryCall(
              new MethodHandlers<
                ParserOuterClass.Request,
                ParserOuterClass.Response>(
                  this, METHODID_PARSE)))
          .build();
    }
  }

  /**
   */
  public static final class ParserStub extends io.grpc.stub.AbstractAsyncStub<ParserStub> {
    private ParserStub(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @java.lang.Override
    protected ParserStub build(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      return new ParserStub(channel, callOptions);
    }

    /**
     */
    public void parse(ParserOuterClass.Request request,
        io.grpc.stub.StreamObserver<ParserOuterClass.Response> responseObserver) {
      io.grpc.stub.ClientCalls.asyncUnaryCall(
          getChannel().newCall(getParseMethod(), getCallOptions()), request, responseObserver);
    }
  }

  /**
   */
  public static final class ParserBlockingStub extends io.grpc.stub.AbstractBlockingStub<ParserBlockingStub> {
    private ParserBlockingStub(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @java.lang.Override
    protected ParserBlockingStub build(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      return new ParserBlockingStub(channel, callOptions);
    }

    /**
     */
    public ParserOuterClass.Response parse(ParserOuterClass.Request request) {
      return io.grpc.stub.ClientCalls.blockingUnaryCall(
          getChannel(), getParseMethod(), getCallOptions(), request);
    }
  }

  /**
   */
  public static final class ParserFutureStub extends io.grpc.stub.AbstractFutureStub<ParserFutureStub> {
    private ParserFutureStub(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      super(channel, callOptions);
    }

    @java.lang.Override
    protected ParserFutureStub build(
        io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
      return new ParserFutureStub(channel, callOptions);
    }

    /**
     */
    public com.google.common.util.concurrent.ListenableFuture<ParserOuterClass.Response> parse(
        ParserOuterClass.Request request) {
      return io.grpc.stub.ClientCalls.futureUnaryCall(
          getChannel().newCall(getParseMethod(), getCallOptions()), request);
    }
  }

  private static final int METHODID_PARSE = 0;

  private static final class MethodHandlers<Req, Resp> implements
      io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
      io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
    private final ParserImplBase serviceImpl;
    private final int methodId;

    MethodHandlers(ParserImplBase serviceImpl, int methodId) {
      this.serviceImpl = serviceImpl;
      this.methodId = methodId;
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("unchecked")
    public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
      switch (methodId) {
        case METHODID_PARSE:
          serviceImpl.parse((ParserOuterClass.Request) request,
              (io.grpc.stub.StreamObserver<ParserOuterClass.Response>) responseObserver);
          break;
        default:
          throw new AssertionError();
      }
    }

    @java.lang.Override
    @java.lang.SuppressWarnings("unchecked")
    public io.grpc.stub.StreamObserver<Req> invoke(
        io.grpc.stub.StreamObserver<Resp> responseObserver) {
      switch (methodId) {
        default:
          throw new AssertionError();
      }
    }
  }

  private static abstract class ParserBaseDescriptorSupplier
      implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
    ParserBaseDescriptorSupplier() {}

    @java.lang.Override
    public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
      return ParserOuterClass.getDescriptor();
    }

    @java.lang.Override
    public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
      return getFileDescriptor().findServiceByName("Parser");
    }
  }

  private static final class ParserFileDescriptorSupplier
      extends ParserBaseDescriptorSupplier {
    ParserFileDescriptorSupplier() {}
  }

  private static final class ParserMethodDescriptorSupplier
      extends ParserBaseDescriptorSupplier
      implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
    private final String methodName;

    ParserMethodDescriptorSupplier(String methodName) {
      this.methodName = methodName;
    }

    @java.lang.Override
    public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
      return getServiceDescriptor().findMethodByName(methodName);
    }
  }

  private static volatile io.grpc.ServiceDescriptor serviceDescriptor;

  public static io.grpc.ServiceDescriptor getServiceDescriptor() {
    io.grpc.ServiceDescriptor result = serviceDescriptor;
    if (result == null) {
      synchronized (ParserGrpc.class) {
        result = serviceDescriptor;
        if (result == null) {
          serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
              .setSchemaDescriptor(new ParserFileDescriptorSupplier())
              .addMethod(getParseMethod())
              .build();
        }
      }
    }
    return result;
  }
}
