package io.netty.handler.codec.http2;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.logging.LogLevel;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.logging.InternalLogLevel;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

/* JADX INFO: loaded from: classes.dex */
public class Http2FrameLogger extends ChannelHandlerAdapter {
    private static final int BUFFER_LENGTH_THRESHOLD = 64;
    private final InternalLogLevel level;
    private final InternalLogger logger;

    public enum Direction {
        INBOUND,
        OUTBOUND
    }

    public Http2FrameLogger(LogLevel logLevel) {
        this(logLevel.toInternalLevel(), InternalLoggerFactory.getInstance((Class<?>) Http2FrameLogger.class));
    }

    public Http2FrameLogger(LogLevel logLevel, Class<?> cls) {
        this(logLevel.toInternalLevel(), InternalLoggerFactory.getInstance(cls));
    }

    public Http2FrameLogger(LogLevel logLevel, String str) {
        this(logLevel.toInternalLevel(), InternalLoggerFactory.getInstance(str));
    }

    private Http2FrameLogger(InternalLogLevel internalLogLevel, InternalLogger internalLogger) {
        this.level = (InternalLogLevel) ObjectUtil.checkNotNull(internalLogLevel, "level");
        this.logger = (InternalLogger) ObjectUtil.checkNotNull(internalLogger, "logger");
    }

    private String toString(ByteBuf byteBuf) {
        if (!this.logger.isEnabled(this.level)) {
            return "";
        }
        if (this.level == InternalLogLevel.TRACE || byteBuf.readableBytes() <= 64) {
            return ByteBufUtil.hexDump(byteBuf);
        }
        return ByteBufUtil.hexDump(byteBuf, byteBuf.readerIndex(), Math.min(byteBuf.readableBytes(), 64)) + "...";
    }

    public void logData(Direction direction, ChannelHandlerContext channelHandlerContext, int i2, ByteBuf byteBuf, int i3, boolean z2) {
        this.logger.log(this.level, "{} {} DATA: streamId={} padding={} endStream={} length={} bytes={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(i2), Integer.valueOf(i3), Boolean.valueOf(z2), Integer.valueOf(byteBuf.readableBytes()), toString(byteBuf));
    }

    public void logGoAway(Direction direction, ChannelHandlerContext channelHandlerContext, int i2, long j2, ByteBuf byteBuf) {
        this.logger.log(this.level, "{} {} GO_AWAY: lastStreamId={} errorCode={} length={} bytes={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(i2), Long.valueOf(j2), Integer.valueOf(byteBuf.readableBytes()), toString(byteBuf));
    }

    public void logHeaders(Direction direction, ChannelHandlerContext channelHandlerContext, int i2, Http2Headers http2Headers, int i3, short s2, boolean z2, int i4, boolean z3) {
        this.logger.log(this.level, "{} {} HEADERS: streamId={} headers={} streamDependency={} weight={} exclusive={} padding={} endStream={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(i2), http2Headers, Integer.valueOf(i3), Short.valueOf(s2), Boolean.valueOf(z2), Integer.valueOf(i4), Boolean.valueOf(z3));
    }

    public void logHeaders(Direction direction, ChannelHandlerContext channelHandlerContext, int i2, Http2Headers http2Headers, int i3, boolean z2) {
        this.logger.log(this.level, "{} {} HEADERS: streamId={} headers={} padding={} endStream={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(i2), http2Headers, Integer.valueOf(i3), Boolean.valueOf(z2));
    }

    public void logPing(Direction direction, ChannelHandlerContext channelHandlerContext, long j2) {
        this.logger.log(this.level, "{} {} PING: ack=false bytes={}", channelHandlerContext.channel(), direction.name(), Long.valueOf(j2));
    }

    public void logPingAck(Direction direction, ChannelHandlerContext channelHandlerContext, long j2) {
        this.logger.log(this.level, "{} {} PING: ack=true bytes={}", channelHandlerContext.channel(), direction.name(), Long.valueOf(j2));
    }

    public void logPriority(Direction direction, ChannelHandlerContext channelHandlerContext, int i2, int i3, short s2, boolean z2) {
        this.logger.log(this.level, "{} {} PRIORITY: streamId={} streamDependency={} weight={} exclusive={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(i2), Integer.valueOf(i3), Short.valueOf(s2), Boolean.valueOf(z2));
    }

    public void logPushPromise(Direction direction, ChannelHandlerContext channelHandlerContext, int i2, int i3, Http2Headers http2Headers, int i4) {
        this.logger.log(this.level, "{} {} PUSH_PROMISE: streamId={} promisedStreamId={} headers={} padding={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(i2), Integer.valueOf(i3), http2Headers, Integer.valueOf(i4));
    }

    public void logRstStream(Direction direction, ChannelHandlerContext channelHandlerContext, int i2, long j2) {
        this.logger.log(this.level, "{} {} RST_STREAM: streamId={} errorCode={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(i2), Long.valueOf(j2));
    }

    public void logSettings(Direction direction, ChannelHandlerContext channelHandlerContext, Http2Settings http2Settings) {
        this.logger.log(this.level, "{} {} SETTINGS: ack=false settings={}", channelHandlerContext.channel(), direction.name(), http2Settings);
    }

    public void logSettingsAck(Direction direction, ChannelHandlerContext channelHandlerContext) {
        this.logger.log(this.level, "{} {} SETTINGS: ack=true", channelHandlerContext.channel(), direction.name());
    }

    public void logUnknownFrame(Direction direction, ChannelHandlerContext channelHandlerContext, byte b2, int i2, Http2Flags http2Flags, ByteBuf byteBuf) {
        this.logger.log(this.level, "{} {} UNKNOWN: frameType={} streamId={} flags={} length={} bytes={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(b2 & 255), Integer.valueOf(i2), Short.valueOf(http2Flags.value()), Integer.valueOf(byteBuf.readableBytes()), toString(byteBuf));
    }

    public void logWindowsUpdate(Direction direction, ChannelHandlerContext channelHandlerContext, int i2, int i3) {
        this.logger.log(this.level, "{} {} WINDOW_UPDATE: streamId={} windowSizeIncrement={}", channelHandlerContext.channel(), direction.name(), Integer.valueOf(i2), Integer.valueOf(i3));
    }
}
