package e.a.r.y;

import com.seewo.libmcuservice.constant.IRemoteConstants;
import e.a.o.j;

/* JADX INFO: compiled from: StreamingJsonDecoder.kt */
/* JADX INFO: loaded from: classes.dex */
@d.n
public class l0 extends e.a.p.a implements e.a.r.g {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final e.a.r.a f3029a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final r0 f3030b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final e.a.r.y.a f3031c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final e.a.s.c f3032d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private int f3033e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private a f3034f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final e.a.r.f f3035g;
    private final v h;

    /* JADX INFO: compiled from: StreamingJsonDecoder.kt */
    @d.n
    public static final class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public String f3036a;

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

    /* JADX INFO: compiled from: StreamingJsonDecoder.kt */
    @d.n
    public /* synthetic */ class b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f3037a;

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

    public l0(e.a.r.a aVar, r0 r0Var, e.a.r.y.a aVar2, e.a.o.f fVar, a aVar3) {
        d.n0.c.s.e(aVar, "json");
        d.n0.c.s.e(r0Var, IRemoteConstants.KEY_INF_PUBLISH_MODE);
        d.n0.c.s.e(aVar2, "lexer");
        d.n0.c.s.e(fVar, "descriptor");
        this.f3029a = aVar;
        this.f3030b = r0Var;
        this.f3031c = aVar2;
        this.f3032d = aVar.e();
        this.f3033e = -1;
        this.f3034f = aVar3;
        e.a.r.f fVarD = aVar.d();
        this.f3035g = fVarD;
        this.h = fVarD.f() ? null : new v(fVar);
    }

    private final void J() {
        if (this.f3031c.E() != 4) {
            return;
        }
        e.a.r.y.a.y(this.f3031c, "Unexpected leading comma", 0, null, 6, null);
        throw new d.h();
    }

    private final boolean K(e.a.o.f fVar, int i) {
        String strF;
        e.a.r.a aVar = this.f3029a;
        e.a.o.f fVarK = fVar.k(i);
        if (fVarK.c() || !(!this.f3031c.M())) {
            if (!d.n0.c.s.a(fVarK.e(), j.b.f2791a) || (strF = this.f3031c.F(this.f3035g.l())) == null || z.d(fVarK, aVar, strF) != -3) {
                return false;
            }
            this.f3031c.q();
        }
        return true;
    }

    private final int L() {
        boolean zL = this.f3031c.L();
        if (!this.f3031c.f()) {
            if (!zL) {
                return -1;
            }
            e.a.r.y.a.y(this.f3031c, "Unexpected trailing comma", 0, null, 6, null);
            throw new d.h();
        }
        int i = this.f3033e;
        if (i != -1 && !zL) {
            e.a.r.y.a.y(this.f3031c, "Expected end of the array or comma", 0, null, 6, null);
            throw new d.h();
        }
        int i2 = i + 1;
        this.f3033e = i2;
        return i2;
    }

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

    private final int N(e.a.o.f fVar) {
        boolean zL;
        boolean zL2 = this.f3031c.L();
        while (this.f3031c.f()) {
            String strO = O();
            this.f3031c.o(':');
            int iD = z.d(fVar, this.f3029a, strO);
            boolean z = false;
            if (iD == -3) {
                z = true;
                zL = false;
            } else {
                if (!this.f3035g.d() || !K(fVar, iD)) {
                    v vVar = this.h;
                    if (vVar != null) {
                        vVar.c(iD);
                    }
                    return iD;
                }
                zL = this.f3031c.L();
            }
            zL2 = z ? P(strO) : zL;
        }
        if (zL2) {
            e.a.r.y.a.y(this.f3031c, "Unexpected trailing comma", 0, null, 6, null);
            throw new d.h();
        }
        v vVar2 = this.h;
        if (vVar2 != null) {
            return vVar2.d();
        }
        return -1;
    }

    private final String O() {
        return this.f3035g.l() ? this.f3031c.t() : this.f3031c.k();
    }

    private final boolean P(String str) {
        if (this.f3035g.g() || R(this.f3034f, str)) {
            this.f3031c.H(this.f3035g.l());
        } else {
            this.f3031c.A(str);
        }
        return this.f3031c.L();
    }

    private final void Q(e.a.o.f fVar) {
        while (w(fVar) != -1) {
        }
    }

    private final boolean R(a aVar, String str) {
        if (aVar == null || !d.n0.c.s.a(aVar.f3036a, str)) {
            return false;
        }
        aVar.f3036a = null;
        return true;
    }

    @Override // e.a.p.a, e.a.p.e
    public byte B() {
        long jP = this.f3031c.p();
        byte b2 = (byte) jP;
        if (jP == b2) {
            return b2;
        }
        e.a.r.y.a.y(this.f3031c, "Failed to parse byte for input '" + jP + '\'', 0, null, 6, null);
        throw new d.h();
    }

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

    @Override // e.a.p.a, e.a.p.e
    public float D() {
        e.a.r.y.a aVar = this.f3031c;
        String strS = aVar.s();
        try {
            float f2 = Float.parseFloat(strS);
            if (!this.f3029a.d().a()) {
                if (!((Float.isInfinite(f2) || Float.isNaN(f2)) ? false : true)) {
                    y.i(this.f3031c, Float.valueOf(f2));
                    throw new d.h();
                }
            }
            return f2;
        } catch (IllegalArgumentException unused) {
            e.a.r.y.a.y(aVar, "Failed to parse type 'float' for input '" + strS + '\'', 0, null, 6, null);
            throw new d.h();
        }
    }

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

    @Override // e.a.p.a
    public <T> T G(e.a.a<T> aVar) {
        d.n0.c.s.e(aVar, "deserializer");
        try {
            if ((aVar instanceof e.a.q.b) && !this.f3029a.d().k()) {
                String strC = j0.c(aVar.getDescriptor(), this.f3029a);
                String strL = this.f3031c.l(strC, this.f3035g.l());
                e.a.a<? extends T> aVarC = strL != null ? ((e.a.q.b) aVar).c(this, strL) : null;
                if (aVarC == null) {
                    return (T) j0.d(this, aVar);
                }
                this.f3034f = new a(strC);
                return aVarC.deserialize(this);
            }
            return aVar.deserialize(this);
        } catch (e.a.c e2) {
            throw new e.a.c(e2.a(), e2.getMessage() + " at path: " + this.f3031c.f2993b.a(), e2);
        }
    }

    @Override // e.a.p.a, e.a.p.c
    public void a(e.a.o.f fVar) {
        d.n0.c.s.e(fVar, "descriptor");
        if (this.f3029a.d().g() && fVar.g() == 0) {
            Q(fVar);
        }
        this.f3031c.o(this.f3030b.end);
        this.f3031c.f2993b.b();
    }

    @Override // e.a.p.c
    public e.a.s.c b() {
        return this.f3032d;
    }

    @Override // e.a.p.a, e.a.p.e
    public e.a.p.c c(e.a.o.f fVar) {
        d.n0.c.s.e(fVar, "descriptor");
        r0 r0VarB = s0.b(this.f3029a, fVar);
        this.f3031c.f2993b.c(fVar);
        this.f3031c.o(r0VarB.begin);
        J();
        int i = b.f3037a[r0VarB.ordinal()];
        return (i == 1 || i == 2 || i == 3) ? new l0(this.f3029a, r0VarB, this.f3031c, fVar, this.f3034f) : (this.f3030b == r0VarB && this.f3029a.d().f()) ? this : new l0(this.f3029a, r0VarB, this.f3031c, fVar, this.f3034f);
    }

    @Override // e.a.r.g
    public final e.a.r.a d() {
        return this.f3029a;
    }

    @Override // e.a.p.a, e.a.p.e
    public boolean e() {
        return this.f3035g.l() ? this.f3031c.i() : this.f3031c.g();
    }

    @Override // e.a.p.a, e.a.p.e
    public char f() {
        String strS = this.f3031c.s();
        if (strS.length() == 1) {
            return strS.charAt(0);
        }
        e.a.r.y.a.y(this.f3031c, "Expected single char, but got '" + strS + '\'', 0, null, 6, null);
        throw new d.h();
    }

    @Override // e.a.p.a, e.a.p.e
    public int g(e.a.o.f fVar) {
        d.n0.c.s.e(fVar, "enumDescriptor");
        return z.e(fVar, this.f3029a, n(), " at path " + this.f3031c.f2993b.a());
    }

    @Override // e.a.r.g
    public e.a.r.h i() {
        return new h0(this.f3029a.d(), this.f3031c).e();
    }

    @Override // e.a.p.a, e.a.p.e
    public int j() {
        long jP = this.f3031c.p();
        int i = (int) jP;
        if (jP == i) {
            return i;
        }
        e.a.r.y.a.y(this.f3031c, "Failed to parse int for input '" + jP + '\'', 0, null, 6, null);
        throw new d.h();
    }

    @Override // e.a.p.a, e.a.p.e
    public Void l() {
        return 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 // e.a.p.a, e.a.p.c
    public <T> T m(e.a.o.f fVar, int i, e.a.a<T> aVar, T t) {
        d.n0.c.s.e(fVar, "descriptor");
        d.n0.c.s.e(aVar, "deserializer");
        boolean z = this.f3030b == r0.MAP && (i & 1) == 0;
        if (z) {
            this.f3031c.f2993b.d();
        }
        T t2 = (T) super.m(fVar, i, aVar, t);
        if (z) {
            this.f3031c.f2993b.f(t2);
        }
        return t2;
    }

    @Override // e.a.p.a, e.a.p.e
    public String n() {
        return this.f3035g.l() ? this.f3031c.t() : this.f3031c.q();
    }

    @Override // e.a.p.a, e.a.p.e
    public long r() {
        return this.f3031c.p();
    }

    @Override // e.a.p.a, e.a.p.e
    public boolean u() {
        v vVar = this.h;
        return !(vVar != null ? vVar.b() : false) && this.f3031c.M();
    }

    @Override // e.a.p.c
    public int w(e.a.o.f fVar) {
        d.n0.c.s.e(fVar, "descriptor");
        int i = b.f3037a[this.f3030b.ordinal()];
        int iL = i != 2 ? i != 4 ? L() : N(fVar) : M();
        if (this.f3030b != r0.MAP) {
            this.f3031c.f2993b.g(iL);
        }
        return iL;
    }

    @Override // e.a.p.a, e.a.p.e
    public e.a.p.e y(e.a.o.f fVar) {
        d.n0.c.s.e(fVar, "descriptor");
        return n0.a(fVar) ? new t(this.f3031c, this.f3029a) : super.y(fVar);
    }
}
