249 lines
8.8 KiB
Java
249 lines
8.8 KiB
Java
|
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<ReqT, RespT> {
|
||
|
static final boolean $assertionsDisabled = false;
|
||
|
private final String fullMethodName;
|
||
|
private final boolean idempotent;
|
||
|
private final AtomicReferenceArray<Object> rawMethodNames;
|
||
|
private final Marshaller<ReqT> requestMarshaller;
|
||
|
private final Marshaller<RespT> 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> {
|
||
|
T parse(InputStream inputStream);
|
||
|
|
||
|
InputStream stream(T t);
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public interface PrototypeMarshaller<T> extends ReflectableMarshaller<T> {
|
||
|
T getMessagePrototype();
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public interface ReflectableMarshaller<T> extends Marshaller<T> {
|
||
|
Class<T> 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 <RequestT, ResponseT> MethodDescriptor<RequestT, ResponseT> create(MethodType methodType, String str, Marshaller<RequestT> marshaller, Marshaller<ResponseT> marshaller2) {
|
||
|
return new MethodDescriptor<>(methodType, str, marshaller, marshaller2, null, false, false, false);
|
||
|
}
|
||
|
|
||
|
private MethodDescriptor(MethodType methodType, String str, Marshaller<ReqT> marshaller, Marshaller<RespT> 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 <ReqT, RespT> Builder<ReqT, RespT> newBuilder() {
|
||
|
return newBuilder(null, null);
|
||
|
}
|
||
|
|
||
|
public static <ReqT, RespT> Builder<ReqT, RespT> newBuilder(Marshaller<ReqT> marshaller, Marshaller<RespT> marshaller2) {
|
||
|
return new Builder().setRequestMarshaller(marshaller).setResponseMarshaller(marshaller2);
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> toBuilder() {
|
||
|
return (Builder<ReqT, RespT>) toBuilder(this.requestMarshaller, this.responseMarshaller);
|
||
|
}
|
||
|
|
||
|
public final <NewReqT, NewRespT> Builder<NewReqT, NewRespT> toBuilder(Marshaller<NewReqT> marshaller, Marshaller<NewRespT> 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<ReqT, RespT> {
|
||
|
private String fullMethodName;
|
||
|
private boolean idempotent;
|
||
|
private Marshaller<ReqT> requestMarshaller;
|
||
|
private Marshaller<RespT> responseMarshaller;
|
||
|
private boolean safe;
|
||
|
private boolean sampledToLocalTracing;
|
||
|
private Object schemaDescriptor;
|
||
|
private MethodType type;
|
||
|
|
||
|
private Builder() {
|
||
|
}
|
||
|
|
||
|
public final MethodDescriptor<ReqT, RespT> build() {
|
||
|
return new MethodDescriptor<>(this.type, this.fullMethodName, this.requestMarshaller, this.responseMarshaller, this.schemaDescriptor, this.idempotent, this.safe, this.sampledToLocalTracing);
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> setType(MethodType methodType) {
|
||
|
this.type = methodType;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> setSchemaDescriptor(Object obj) {
|
||
|
this.schemaDescriptor = obj;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> setSampledToLocalTracing(boolean z) {
|
||
|
this.sampledToLocalTracing = z;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> setSafe(boolean z) {
|
||
|
this.safe = z;
|
||
|
if (z) {
|
||
|
this.idempotent = true;
|
||
|
}
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> setResponseMarshaller(Marshaller<RespT> marshaller) {
|
||
|
this.responseMarshaller = marshaller;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> setRequestMarshaller(Marshaller<ReqT> marshaller) {
|
||
|
this.requestMarshaller = marshaller;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> setIdempotent(boolean z) {
|
||
|
this.idempotent = z;
|
||
|
if (!z) {
|
||
|
this.safe = false;
|
||
|
}
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Builder<ReqT, RespT> 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<RespT> 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<ReqT> getRequestMarshaller() {
|
||
|
return this.requestMarshaller;
|
||
|
}
|
||
|
|
||
|
public final String getFullMethodName() {
|
||
|
return this.fullMethodName;
|
||
|
}
|
||
|
}
|