package h.b.p.a0;

import h.b.m.j;

/* JADX INFO: compiled from: StreamingJsonEncoder.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class b0 extends h.b.n.b implements h.b.p.p {
    public final e a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final h.b.p.a f4501b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final f0 f4502c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final h.b.p.p[] f4503d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final h.b.q.c f4504e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final h.b.p.f f4505f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f4506g;

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

    public b0(e eVar, h.b.p.a aVar, f0 f0Var, h.b.p.p[] pVarArr) {
        g.h0.c.l.f(eVar, "composer");
        g.h0.c.l.f(aVar, "json");
        g.h0.c.l.f(f0Var, "mode");
        this.a = eVar;
        this.f4501b = aVar;
        this.f4502c = f0Var;
        this.f4503d = pVarArr;
        this.f4504e = aVar.f4486c;
        this.f4505f = aVar.f4485b;
        int iOrdinal = f0Var.ordinal();
        if (pVarArr != null) {
            if (pVarArr[iOrdinal] == null && pVarArr[iOrdinal] == this) {
                return;
            }
            pVarArr[iOrdinal] = this;
        }
    }

    @Override // h.b.n.b, h.b.n.f
    public void C(long j2) {
        if (this.f4506g) {
            F(String.valueOf(j2));
        } else {
            this.a.e(j2);
        }
    }

    @Override // h.b.n.b, h.b.n.f
    public void F(String str) {
        g.h0.c.l.f(str, "value");
        this.a.h(str);
    }

    @Override // h.b.n.b
    public boolean G(h.b.m.e eVar, int i2) {
        g.h0.c.l.f(eVar, "descriptor");
        int iOrdinal = this.f4502c.ordinal();
        if (iOrdinal != 1) {
            boolean z = false;
            if (iOrdinal == 2) {
                e eVar2 = this.a;
                if (eVar2.f4514b) {
                    this.f4506g = true;
                    eVar2.b();
                } else {
                    if (i2 % 2 == 0) {
                        eVar2.a.a(',');
                        this.a.b();
                        z = true;
                    } else {
                        eVar2.a.a(':');
                        this.a.i();
                    }
                    this.f4506g = z;
                }
            } else if (iOrdinal != 3) {
                e eVar3 = this.a;
                if (!eVar3.f4514b) {
                    eVar3.a.a(',');
                }
                this.a.b();
                F(eVar.g(i2));
                this.a.a.a(':');
                this.a.i();
            } else {
                if (i2 == 0) {
                    this.f4506g = true;
                }
                if (i2 == 1) {
                    this.a.a.a(',');
                    this.a.i();
                    this.f4506g = false;
                }
            }
        } else {
            e eVar4 = this.a;
            if (!eVar4.f4514b) {
                eVar4.a.a(',');
            }
            this.a.b();
        }
        return true;
    }

    @Override // h.b.n.b, h.b.n.d
    public void a(h.b.m.e eVar) {
        g.h0.c.l.f(eVar, "descriptor");
        if (this.f4502c.end != 0) {
            this.a.j();
            this.a.b();
            e eVar2 = this.a;
            eVar2.a.a(this.f4502c.end);
        }
    }

    @Override // h.b.n.f
    public h.b.q.c b() {
        return this.f4504e;
    }

    @Override // h.b.n.b, h.b.n.f
    public h.b.n.d c(h.b.m.e eVar) {
        h.b.p.p pVar;
        g.h0.c.l.f(eVar, "descriptor");
        f0 f0VarD = y.d(this.f4501b, eVar);
        char c2 = f0VarD.begin;
        if (c2 != 0) {
            this.a.a.a(c2);
            this.a.a();
        }
        if (this.f4507h != null) {
            this.a.b();
            String str = this.f4507h;
            g.h0.c.l.c(str);
            F(str);
            this.a.a.a(':');
            this.a.i();
            F(eVar.a());
            this.f4507h = null;
        }
        if (this.f4502c == f0VarD) {
            return this;
        }
        h.b.p.p[] pVarArr = this.f4503d;
        return (pVarArr == null || (pVar = pVarArr[f0VarD.ordinal()]) == null) ? new b0(this.a, this.f4501b, f0VarD, this.f4503d) : pVar;
    }

    @Override // h.b.p.p
    public h.b.p.a d() {
        return this.f4501b;
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // h.b.n.b, h.b.n.f
    public <T> void e(h.b.j<? super T> jVar, T t) {
        g.h0.c.l.f(jVar, "serializer");
        if (!(jVar instanceof h.b.o.b) || d().f4485b.f4569i) {
            jVar.d(this, t);
            return;
        }
        h.b.o.b bVar = (h.b.o.b) jVar;
        String strB = y.b(jVar.a(), d());
        g.h0.c.l.d(t, "null cannot be cast to non-null type kotlin.Any");
        h.b.j jVarX = f.a.y.a.X(bVar, this, t);
        h.b.m.j jVarE = jVarX.a().e();
        g.h0.c.l.f(jVarE, "kind");
        if (jVarE instanceof j.b) {
            throw new IllegalStateException("Enums cannot be serialized polymorphically with 'type' parameter. You can use 'JsonBuilder.useArrayPolymorphism' instead".toString());
        }
        if (jVarE instanceof h.b.m.d) {
            throw new IllegalStateException("Primitives cannot be serialized polymorphically with 'type' parameter. You can use 'JsonBuilder.useArrayPolymorphism' instead".toString());
        }
        if (jVarE instanceof h.b.m.c) {
            throw new IllegalStateException("Actual serializer for polymorphic cannot be polymorphic itself".toString());
        }
        this.f4507h = strB;
        jVarX.d(this, t);
    }

    @Override // h.b.n.f
    public void f() {
        this.a.f("null");
    }

    @Override // h.b.n.b, h.b.n.f
    public void i(double d2) {
        if (this.f4506g) {
            F(String.valueOf(d2));
        } else {
            this.a.a.d(String.valueOf(d2));
        }
        if (this.f4505f.f4571k) {
            return;
        }
        if (!((Double.isInfinite(d2) || Double.isNaN(d2)) ? false : true)) {
            throw f.a.y.a.c(Double.valueOf(d2), this.a.a.toString());
        }
    }

    @Override // h.b.n.b, h.b.n.f
    public void j(short s) {
        if (this.f4506g) {
            F(String.valueOf((int) s));
        } else {
            this.a.g(s);
        }
    }

    @Override // h.b.n.b, h.b.n.f
    public void k(byte b2) {
        if (this.f4506g) {
            F(String.valueOf((int) b2));
        } else {
            this.a.c(b2);
        }
    }

    @Override // h.b.n.b, h.b.n.f
    public void l(boolean z) {
        if (this.f4506g) {
            F(String.valueOf(z));
        } else {
            this.a.a.d(String.valueOf(z));
        }
    }

    @Override // h.b.n.b, h.b.n.d
    public <T> void m(h.b.m.e eVar, int i2, h.b.j<? super T> jVar, T t) {
        g.h0.c.l.f(eVar, "descriptor");
        g.h0.c.l.f(jVar, "serializer");
        if (t != null || this.f4505f.f4566f) {
            super.m(eVar, i2, jVar, t);
        }
    }

    @Override // h.b.n.b, h.b.n.f
    public void o(float f2) {
        if (this.f4506g) {
            F(String.valueOf(f2));
        } else {
            this.a.a.d(String.valueOf(f2));
        }
        if (this.f4505f.f4571k) {
            return;
        }
        if (!((Float.isInfinite(f2) || Float.isNaN(f2)) ? false : true)) {
            throw f.a.y.a.c(Float.valueOf(f2), this.a.a.toString());
        }
    }

    @Override // h.b.n.b, h.b.n.f
    public void p(char c2) {
        F(String.valueOf(c2));
    }

    @Override // h.b.n.f
    public void v(h.b.m.e eVar, int i2) {
        g.h0.c.l.f(eVar, "enumDescriptor");
        F(eVar.g(i2));
    }

    @Override // h.b.n.b, h.b.n.d
    public boolean w(h.b.m.e eVar, int i2) {
        g.h0.c.l.f(eVar, "descriptor");
        return this.f4505f.a;
    }

    @Override // h.b.n.b, h.b.n.f
    public void x(int i2) {
        if (this.f4506g) {
            F(String.valueOf(i2));
        } else {
            this.a.d(i2);
        }
    }

    @Override // h.b.n.b, h.b.n.f
    public h.b.n.f y(h.b.m.e eVar) {
        g.h0.c.l.f(eVar, "descriptor");
        if (!c0.a(eVar)) {
            g.h0.c.l.f(eVar, "descriptor");
            return this;
        }
        e fVar = this.a;
        if (!(fVar instanceof f)) {
            fVar = new f(fVar.a, this.f4506g);
        }
        return new b0(fVar, this.f4501b, this.f4502c, null);
    }
}
