package io.grpc; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import java.io.InputStream; import java.util.concurrent.atomic.AtomicReferenceArray; /* loaded from: classes6.dex */ public final class MethodDescriptor { static final boolean $assertionsDisabled = false; private final String fullMethodName; private final boolean idempotent; private final AtomicReferenceArray rawMethodNames; private final Marshaller requestMarshaller; private final Marshaller responseMarshaller; private final boolean safe; private final boolean sampledToLocalTracing; private final Object schemaDescriptor; private final String serviceName; private final MethodType type; /* loaded from: classes6.dex */ public interface Marshaller { T parse(InputStream inputStream); InputStream stream(T t); } /* loaded from: classes6.dex */ public interface PrototypeMarshaller extends ReflectableMarshaller { T getMessagePrototype(); } /* loaded from: classes6.dex */ public interface ReflectableMarshaller extends Marshaller { Class getMessageClass(); } /* JADX INFO: Access modifiers changed from: package-private */ public final Object getRawMethodName(int i) { return this.rawMethodNames.get(i); } /* JADX INFO: Access modifiers changed from: package-private */ public final void setRawMethodName(int i, Object obj) { this.rawMethodNames.lazySet(i, obj); } @Deprecated public static MethodDescriptor create(MethodType methodType, String str, Marshaller marshaller, Marshaller marshaller2) { return new MethodDescriptor<>(methodType, str, marshaller, marshaller2, null, false, false, false); } private MethodDescriptor(MethodType methodType, String str, Marshaller marshaller, Marshaller marshaller2, Object obj, boolean z, boolean z2, boolean z3) { this.rawMethodNames = new AtomicReferenceArray<>(2); this.type = (MethodType) Preconditions.checkNotNull(methodType, "type"); this.fullMethodName = (String) Preconditions.checkNotNull(str, "fullMethodName"); this.serviceName = extractFullServiceName(str); this.requestMarshaller = (Marshaller) Preconditions.checkNotNull(marshaller, "requestMarshaller"); this.responseMarshaller = (Marshaller) Preconditions.checkNotNull(marshaller2, "responseMarshaller"); this.schemaDescriptor = obj; this.idempotent = z; this.safe = z2; this.sampledToLocalTracing = z3; } public final String getBareMethodName() { return extractBareMethodName(this.fullMethodName); } public final RespT parseResponse(InputStream inputStream) { return this.responseMarshaller.parse(inputStream); } public final InputStream streamRequest(ReqT reqt) { return this.requestMarshaller.stream(reqt); } public final ReqT parseRequest(InputStream inputStream) { return this.requestMarshaller.parse(inputStream); } public final InputStream streamResponse(RespT respt) { return this.responseMarshaller.stream(respt); } public static String generateFullMethodName(String str, String str2) { StringBuilder sb = new StringBuilder(); sb.append((String) Preconditions.checkNotNull(str, "fullServiceName")); sb.append("/"); sb.append((String) Preconditions.checkNotNull(str2, "methodName")); return sb.toString(); } public static String extractFullServiceName(String str) { int lastIndexOf = ((String) Preconditions.checkNotNull(str, "fullMethodName")).lastIndexOf(47); if (lastIndexOf == -1) { return null; } return str.substring(0, lastIndexOf); } public static String extractBareMethodName(String str) { int lastIndexOf = ((String) Preconditions.checkNotNull(str, "fullMethodName")).lastIndexOf(47); if (lastIndexOf == -1) { return null; } return str.substring(lastIndexOf + 1); } public static Builder newBuilder() { return newBuilder(null, null); } public static Builder newBuilder(Marshaller marshaller, Marshaller marshaller2) { return new Builder().setRequestMarshaller(marshaller).setResponseMarshaller(marshaller2); } public final Builder toBuilder() { return (Builder) toBuilder(this.requestMarshaller, this.responseMarshaller); } public final Builder toBuilder(Marshaller marshaller, Marshaller marshaller2) { return newBuilder().setRequestMarshaller(marshaller).setResponseMarshaller(marshaller2).setType(this.type).setFullMethodName(this.fullMethodName).setIdempotent(this.idempotent).setSafe(this.safe).setSampledToLocalTracing(this.sampledToLocalTracing).setSchemaDescriptor(this.schemaDescriptor); } /* loaded from: classes6.dex */ public static final class Builder { private String fullMethodName; private boolean idempotent; private Marshaller requestMarshaller; private Marshaller responseMarshaller; private boolean safe; private boolean sampledToLocalTracing; private Object schemaDescriptor; private MethodType type; private Builder() { } public final MethodDescriptor build() { return new MethodDescriptor<>(this.type, this.fullMethodName, this.requestMarshaller, this.responseMarshaller, this.schemaDescriptor, this.idempotent, this.safe, this.sampledToLocalTracing); } public final Builder setType(MethodType methodType) { this.type = methodType; return this; } public final Builder setSchemaDescriptor(Object obj) { this.schemaDescriptor = obj; return this; } public final Builder setSampledToLocalTracing(boolean z) { this.sampledToLocalTracing = z; return this; } public final Builder setSafe(boolean z) { this.safe = z; if (z) { this.idempotent = true; } return this; } public final Builder setResponseMarshaller(Marshaller marshaller) { this.responseMarshaller = marshaller; return this; } public final Builder setRequestMarshaller(Marshaller marshaller) { this.requestMarshaller = marshaller; return this; } public final Builder setIdempotent(boolean z) { this.idempotent = z; if (!z) { this.safe = false; } return this; } public final Builder setFullMethodName(String str) { this.fullMethodName = str; return this; } } public final String toString() { return MoreObjects.toStringHelper(this).add("fullMethodName", this.fullMethodName).add("type", this.type).add("idempotent", this.idempotent).add("safe", this.safe).add("sampledToLocalTracing", this.sampledToLocalTracing).add("requestMarshaller", this.requestMarshaller).add("responseMarshaller", this.responseMarshaller).add("schemaDescriptor", this.schemaDescriptor).omitNullValues().toString(); } public final boolean isSampledToLocalTracing() { return this.sampledToLocalTracing; } public final boolean isSafe() { return this.safe; } public final boolean isIdempotent() { return this.idempotent; } public final MethodType getType() { return this.type; } public final String getServiceName() { return this.serviceName; } public final Object getSchemaDescriptor() { return this.schemaDescriptor; } public final Marshaller getResponseMarshaller() { return this.responseMarshaller; } /* loaded from: classes6.dex */ public enum MethodType { UNARY, CLIENT_STREAMING, SERVER_STREAMING, BIDI_STREAMING, UNKNOWN; public final boolean serverSendsOneMessage() { return this == UNARY || this == CLIENT_STREAMING; } public final boolean clientSendsOneMessage() { return this == UNARY || this == SERVER_STREAMING; } } public final Marshaller getRequestMarshaller() { return this.requestMarshaller; } public final String getFullMethodName() { return this.fullMethodName; } }