package io.grpc.stub; import com.google.common.base.Preconditions; import io.grpc.CallOptions; import io.grpc.Channel; import io.grpc.ClientCall; import io.grpc.ClientInterceptor; import io.grpc.ForwardingClientCall; import io.grpc.ForwardingClientCallListener; import io.grpc.Metadata; import io.grpc.MethodDescriptor; import io.grpc.Status; import java.util.concurrent.atomic.AtomicReference; /* loaded from: classes6.dex */ public final class MetadataUtils { private MetadataUtils() { } @Deprecated public static > T attachHeaders(T t, Metadata metadata) { return (T) t.withInterceptors(newAttachHeadersInterceptor(metadata)); } public static ClientInterceptor newAttachHeadersInterceptor(Metadata metadata) { return new HeaderAttachingClientInterceptor(metadata); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class HeaderAttachingClientInterceptor implements ClientInterceptor { private final Metadata extraHeaders; HeaderAttachingClientInterceptor(Metadata metadata) { this.extraHeaders = (Metadata) Preconditions.checkNotNull(metadata, "extraHeaders"); } @Override // io.grpc.ClientInterceptor public final ClientCall interceptCall(MethodDescriptor methodDescriptor, CallOptions callOptions, Channel channel) { return new HeaderAttachingClientCall(this, channel.newCall(methodDescriptor, callOptions)); } /* loaded from: classes6.dex */ final class HeaderAttachingClientCall extends ForwardingClientCall.SimpleForwardingClientCall { final HeaderAttachingClientInterceptor this$0; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ HeaderAttachingClientCall(HeaderAttachingClientInterceptor headerAttachingClientInterceptor, ClientCall clientCall) { super(clientCall); this.this$0 = headerAttachingClientInterceptor; } @Override // io.grpc.ForwardingClientCall, io.grpc.ClientCall public final void start(ClientCall.Listener listener, Metadata metadata) { metadata.merge(this.this$0.extraHeaders); super.start(listener, metadata); } } } @Deprecated public static > T captureMetadata(T t, AtomicReference atomicReference, AtomicReference atomicReference2) { return (T) t.withInterceptors(newCaptureMetadataInterceptor(atomicReference, atomicReference2)); } public static ClientInterceptor newCaptureMetadataInterceptor(AtomicReference atomicReference, AtomicReference atomicReference2) { return new MetadataCapturingClientInterceptor(atomicReference, atomicReference2); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class MetadataCapturingClientInterceptor implements ClientInterceptor { final AtomicReference headersCapture; final AtomicReference trailersCapture; MetadataCapturingClientInterceptor(AtomicReference atomicReference, AtomicReference atomicReference2) { this.headersCapture = (AtomicReference) Preconditions.checkNotNull(atomicReference, "headersCapture"); this.trailersCapture = (AtomicReference) Preconditions.checkNotNull(atomicReference2, "trailersCapture"); } @Override // io.grpc.ClientInterceptor public final ClientCall interceptCall(MethodDescriptor methodDescriptor, CallOptions callOptions, Channel channel) { return new MetadataCapturingClientCall(this, channel.newCall(methodDescriptor, callOptions)); } /* loaded from: classes6.dex */ final class MetadataCapturingClientCall extends ForwardingClientCall.SimpleForwardingClientCall { final MetadataCapturingClientInterceptor this$0; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ MetadataCapturingClientCall(MetadataCapturingClientInterceptor metadataCapturingClientInterceptor, ClientCall clientCall) { super(clientCall); this.this$0 = metadataCapturingClientInterceptor; } @Override // io.grpc.ForwardingClientCall, io.grpc.ClientCall public final void start(ClientCall.Listener listener, Metadata metadata) { this.this$0.headersCapture.set(null); this.this$0.trailersCapture.set(null); super.start(new MetadataCapturingClientCallListener(this, listener), metadata); } /* loaded from: classes6.dex */ final class MetadataCapturingClientCallListener extends ForwardingClientCallListener.SimpleForwardingClientCallListener { final MetadataCapturingClientCall this$1; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ MetadataCapturingClientCallListener(MetadataCapturingClientCall metadataCapturingClientCall, ClientCall.Listener listener) { super(listener); this.this$1 = metadataCapturingClientCall; } @Override // io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener, io.grpc.ForwardingClientCallListener, io.grpc.PartialForwardingClientCallListener, io.grpc.ClientCall.Listener public final void onHeaders(Metadata metadata) { this.this$1.this$0.headersCapture.set(metadata); super.onHeaders(metadata); } @Override // io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener, io.grpc.ForwardingClientCallListener, io.grpc.PartialForwardingClientCallListener, io.grpc.ClientCall.Listener public final void onClose(Status status, Metadata metadata) { this.this$1.this$0.trailersCapture.set(metadata); super.onClose(status, metadata); } } } } }