package k.a.q.y;

import k.a.n.j;

/* JADX INFO: compiled from: StreamingJsonDecoder.kt */
/* JADX INFO: loaded from: classes.dex */
public class d0 extends k.a.o.a implements k.a.q.g {
    private final k.a.q.a a;
    private final j0 b;
    public final k.a.q.y.a c;
    private final k.a.r.c d;
    private int e;
    private a f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final k.a.q.f f919g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final n f920h;

    /* JADX INFO: compiled from: StreamingJsonDecoder.kt */
    public static final class a {
        public String a;

        public a(String str) {
            this.a = str;
        }
    }

    /* JADX INFO: compiled from: StreamingJsonDecoder.kt */
    public /* synthetic */ class b {
        public static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[j0.values().length];
            try {
                iArr[j0.LIST.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[j0.MAP.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[j0.POLY_OBJ.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[j0.OBJ.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            a = iArr;
        }
    }

    public d0(k.a.q.a aVar, j0 j0Var, k.a.q.y.a aVar2, k.a.n.f fVar, a aVar3) {
        j.p0.d.r.f(aVar, "json");
        j.p0.d.r.f(j0Var, "mode");
        j.p0.d.r.f(aVar2, "lexer");
        j.p0.d.r.f(fVar, "descriptor");
        this.a = aVar;
        this.b = j0Var;
        this.c = aVar2;
        this.d = aVar.e();
        this.e = -1;
        this.f = aVar3;
        k.a.q.f fVarD = this.a.d();
        this.f919g = fVarD;
        this.f920h = fVarD.f() ? null : new n(fVar);
    }

    private final void K() {
        if (this.c.E() != 4) {
            return;
        }
        k.a.q.y.a.y(this.c, "Unexpected leading comma", 0, null, 6, null);
        throw null;
    }

    private final boolean L(k.a.n.f fVar, int i2) {
        String strF;
        k.a.q.a aVar = this.a;
        k.a.n.f fVarJ = fVar.j(i2);
        if (fVarJ.h() || !(!this.c.M())) {
            if (!j.p0.d.r.a(fVarJ.c(), j.b.a) || (strF = this.c.F(this.f919g.l())) == null || r.d(fVarJ, aVar, strF) != -3) {
                return false;
            }
            this.c.q();
        }
        return true;
    }

    private final int M() {
        boolean zL = this.c.L();
        if (!this.c.f()) {
            if (!zL) {
                return -1;
            }
            k.a.q.y.a.y(this.c, "Unexpected trailing comma", 0, null, 6, null);
            throw null;
        }
        if (this.e != -1 && !zL) {
            k.a.q.y.a.y(this.c, "Expected end of the array or comma", 0, null, 6, null);
            throw null;
        }
        int i2 = this.e + 1;
        this.e = i2;
        return i2;
    }

    private final int N() {
        boolean zL = false;
        boolean z = this.e % 2 != 0;
        if (!z) {
            this.c.o(':');
        } else if (this.e != -1) {
            zL = this.c.L();
        }
        if (!this.c.f()) {
            if (!zL) {
                return -1;
            }
            k.a.q.y.a.y(this.c, "Expected '}', but had ',' instead", 0, null, 6, null);
            throw null;
        }
        if (z) {
            if (this.e == -1) {
                k.a.q.y.a aVar = this.c;
                boolean z2 = !zL;
                int i2 = aVar.a;
                if (!z2) {
                    k.a.q.y.a.y(aVar, "Unexpected trailing comma", i2, null, 4, null);
                    throw null;
                }
            } else {
                k.a.q.y.a aVar2 = this.c;
                int i3 = aVar2.a;
                if (!zL) {
                    k.a.q.y.a.y(aVar2, "Expected comma after the key-value pair", i3, null, 4, null);
                    throw null;
                }
            }
        }
        int i4 = this.e + 1;
        this.e = i4;
        return i4;
    }

    private final int O(k.a.n.f fVar) {
        boolean zL;
        boolean zL2 = this.c.L();
        while (this.c.f()) {
            String strP = P();
            this.c.o(':');
            int iD = r.d(fVar, this.a, strP);
            boolean z = false;
            if (iD == -3) {
                z = true;
                zL = false;
            } else {
                if (!this.f919g.d() || !L(fVar, iD)) {
                    n nVar = this.f920h;
                    if (nVar != null) {
                        nVar.c(iD);
                    }
                    return iD;
                }
                zL = this.c.L();
            }
            zL2 = z ? Q(strP) : zL;
        }
        if (zL2) {
            k.a.q.y.a.y(this.c, "Unexpected trailing comma", 0, null, 6, null);
            throw null;
        }
        n nVar2 = this.f920h;
        if (nVar2 != null) {
            return nVar2.d();
        }
        return -1;
    }

    private final String P() {
        return this.f919g.l() ? this.c.t() : this.c.k();
    }

    private final boolean Q(String str) {
        if (this.f919g.g() || S(this.f, str)) {
            this.c.H(this.f919g.l());
            return this.c.L();
        }
        this.c.A(str);
        throw null;
    }

    private final void R(k.a.n.f fVar) {
        while (q(fVar) != -1) {
        }
    }

    private final boolean S(a aVar, String str) {
        if (aVar == null || !j.p0.d.r.a(aVar.a, str)) {
            return false;
        }
        aVar.a = null;
        return true;
    }

    @Override // k.a.o.a, k.a.o.e
    public byte A() {
        long jP = this.c.p();
        byte b2 = (byte) jP;
        if (jP == b2) {
            return b2;
        }
        k.a.q.y.a.y(this.c, "Failed to parse byte for input '" + jP + '\'', 0, null, 6, null);
        throw null;
    }

    @Override // k.a.o.a, k.a.o.e
    public Void B() {
        return null;
    }

    @Override // k.a.o.a, k.a.o.e
    public short C() {
        long jP = this.c.p();
        short s = (short) jP;
        if (jP == s) {
            return s;
        }
        k.a.q.y.a.y(this.c, "Failed to parse short for input '" + jP + '\'', 0, null, 6, null);
        throw null;
    }

    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // k.a.o.a, k.a.o.c
    public <T> T D(k.a.n.f fVar, int i2, k.a.a<T> aVar, T t) {
        j.p0.d.r.f(fVar, "descriptor");
        j.p0.d.r.f(aVar, "deserializer");
        boolean z = this.b == j0.MAP && (i2 & 1) == 0;
        if (z) {
            this.c.b.d();
        }
        T t2 = (T) super.D(fVar, i2, aVar, t);
        if (z) {
            this.c.b.f(t2);
        }
        return t2;
    }

    @Override // k.a.o.a, k.a.o.e
    public String E() {
        return this.f919g.l() ? this.c.t() : this.c.q();
    }

    @Override // k.a.o.a, k.a.o.e
    public float F() {
        k.a.q.y.a aVar = this.c;
        String strS = aVar.s();
        try {
            float f = Float.parseFloat(strS);
            if (!this.a.d().a()) {
                if (!((Float.isInfinite(f) || Float.isNaN(f)) ? false : true)) {
                    q.i(this.c, Float.valueOf(f));
                    throw null;
                }
            }
            return f;
        } catch (IllegalArgumentException unused) {
            k.a.q.y.a.y(aVar, "Failed to parse type 'float' for input '" + strS + '\'', 0, null, 6, null);
            throw null;
        }
    }

    @Override // k.a.o.a, k.a.o.e
    public double H() {
        k.a.q.y.a aVar = this.c;
        String strS = aVar.s();
        try {
            double d = Double.parseDouble(strS);
            if (!this.a.d().a()) {
                if (!((Double.isInfinite(d) || Double.isNaN(d)) ? false : true)) {
                    q.i(this.c, Double.valueOf(d));
                    throw null;
                }
            }
            return d;
        } catch (IllegalArgumentException unused) {
            k.a.q.y.a.y(aVar, "Failed to parse type 'double' for input '" + strS + '\'', 0, null, 6, null);
            throw null;
        }
    }

    @Override // k.a.o.a, k.a.o.e
    public k.a.o.c a(k.a.n.f fVar) {
        j.p0.d.r.f(fVar, "descriptor");
        j0 j0VarB = k0.b(this.a, fVar);
        this.c.b.c(fVar);
        this.c.o(j0VarB.begin);
        K();
        int i2 = b.a[j0VarB.ordinal()];
        return (i2 == 1 || i2 == 2 || i2 == 3) ? new d0(this.a, j0VarB, this.c, fVar, this.f) : (this.b == j0VarB && this.a.d().f()) ? this : new d0(this.a, j0VarB, this.c, fVar, this.f);
    }

    @Override // k.a.o.a, k.a.o.c
    public void b(k.a.n.f fVar) {
        j.p0.d.r.f(fVar, "descriptor");
        if (this.a.d().g() && fVar.d() == 0) {
            R(fVar);
        }
        this.c.o(this.b.end);
        this.c.b.b();
    }

    @Override // k.a.q.g
    public final k.a.q.a c() {
        return this.a;
    }

    @Override // k.a.o.c
    public k.a.r.c d() {
        return this.d;
    }

    @Override // k.a.o.a, k.a.o.e
    public long h() {
        return this.c.p();
    }

    @Override // k.a.o.a, k.a.o.e
    public boolean j() {
        return this.f919g.l() ? this.c.i() : this.c.g();
    }

    @Override // k.a.o.a, k.a.o.e
    public boolean l() {
        n nVar = this.f920h;
        return !(nVar != null ? nVar.b() : false) && this.c.M();
    }

    @Override // k.a.o.a, k.a.o.e
    public char n() {
        String strS = this.c.s();
        if (strS.length() == 1) {
            return strS.charAt(0);
        }
        k.a.q.y.a.y(this.c, "Expected single char, but got '" + strS + '\'', 0, null, 6, null);
        throw null;
    }

    @Override // k.a.o.a, k.a.o.e
    public int p(k.a.n.f fVar) {
        j.p0.d.r.f(fVar, "enumDescriptor");
        return r.e(fVar, this.a, E(), " at path " + this.c.b.a());
    }

    @Override // k.a.o.c
    public int q(k.a.n.f fVar) {
        j.p0.d.r.f(fVar, "descriptor");
        int i2 = b.a[this.b.ordinal()];
        int iM = i2 != 2 ? i2 != 4 ? M() : O(fVar) : N();
        if (this.b != j0.MAP) {
            this.c.b.g(iM);
        }
        return iM;
    }

    @Override // k.a.o.a, k.a.o.e
    public k.a.o.e t(k.a.n.f fVar) {
        j.p0.d.r.f(fVar, "descriptor");
        if (f0.a(fVar)) {
            return new l(this.c, this.a);
        }
        super.t(fVar);
        return this;
    }

    @Override // k.a.q.g
    public k.a.q.h v() {
        return new z(this.a.d(), this.c).e();
    }

    @Override // k.a.o.a, k.a.o.e
    public int w() {
        long jP = this.c.p();
        int i2 = (int) jP;
        if (jP == i2) {
            return i2;
        }
        k.a.q.y.a.y(this.c, "Failed to parse int for input '" + jP + '\'', 0, null, 6, null);
        throw null;
    }

    @Override // k.a.o.a, k.a.o.e
    public <T> T z(k.a.a<T> aVar) {
        j.p0.d.r.f(aVar, "deserializer");
        try {
            if ((aVar instanceof k.a.p.b) && !this.a.d().k()) {
                String strC = b0.c(aVar.a(), this.a);
                String strL = this.c.l(strC, this.f919g.l());
                k.a.a<? extends T> aVarH = strL != null ? ((k.a.p.b) aVar).h(this, strL) : null;
                if (aVarH == null) {
                    return (T) b0.d(this, aVar);
                }
                this.f = new a(strC);
                return aVarH.d(this);
            }
            return aVar.d(this);
        } catch (k.a.c e) {
            throw new k.a.c(e.a(), e.getMessage() + " at path: " + this.c.b.a(), e);
        }
    }
}
