package io.netty.handler.codec.socks;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class SocksInitRequestDecoder extends ReplayingDecoder<State> {

    /* JADX INFO: renamed from: io.netty.handler.codec.socks.SocksInitRequestDecoder$1, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        public static final /* synthetic */ int[] $SwitchMap$io$netty$handler$codec$socks$SocksInitRequestDecoder$State;

        static {
            State.values();
            int[] iArr = new int[2];
            $SwitchMap$io$netty$handler$codec$socks$SocksInitRequestDecoder$State = iArr;
            try {
                iArr[State.CHECK_PROTOCOL_VERSION.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$socks$SocksInitRequestDecoder$State[State.READ_AUTH_SCHEMES.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
        }
    }

    public enum State {
        CHECK_PROTOCOL_VERSION,
        READ_AUTH_SCHEMES
    }

    public SocksInitRequestDecoder() {
        super(State.CHECK_PROTOCOL_VERSION);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r1v2, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r1v3, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r1v4, types: [java.util.ArrayList] */
    @Override // io.netty.handler.codec.ByteToMessageDecoder
    public void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
        Object socksInitRequest;
        ?? EmptyList;
        int iOrdinal = state().ordinal();
        if (iOrdinal == 0) {
            if (byteBuf.readByte() != SocksProtocolVersion.SOCKS5.byteValue()) {
                socksInitRequest = SocksCommonUtils.UNKNOWN_SOCKS_REQUEST;
                list.add(socksInitRequest);
                channelHandlerContext.pipeline().remove(this);
            }
            checkpoint(State.READ_AUTH_SCHEMES);
        } else if (iOrdinal != 1) {
            throw new Error();
        }
        byte b2 = byteBuf.readByte();
        if (b2 > 0) {
            EmptyList = new ArrayList(b2);
            for (int i2 = 0; i2 < b2; i2++) {
                EmptyList.add(SocksAuthScheme.valueOf(byteBuf.readByte()));
            }
        } else {
            EmptyList = Collections.emptyList();
        }
        socksInitRequest = new SocksInitRequest(EmptyList);
        list.add(socksInitRequest);
        channelHandlerContext.pipeline().remove(this);
    }
}
