package e.a.q;

import com.seewo.libmcuservice.constant.ITVStateConstants;
import e.a.p.c;

/* JADX INFO: compiled from: AbstractPolymorphicSerializer.kt */
/* JADX INFO: loaded from: classes.dex */
@d.n
public abstract class b<T> implements e.a.b<T> {
    /* JADX INFO: Access modifiers changed from: private */
    public final T b(e.a.p.c cVar) {
        return (T) c.a.c(cVar, getDescriptor(), 1, e.a.f.a(this, cVar, cVar.t(getDescriptor(), 0)), null, 8, null);
    }

    public e.a.a<? extends T> c(e.a.p.c cVar, String str) {
        d.n0.c.s.e(cVar, "decoder");
        return cVar.b().d(e(), str);
    }

    public e.a.j<T> d(e.a.p.f fVar, T t) {
        d.n0.c.s.e(fVar, "encoder");
        d.n0.c.s.e(t, ITVStateConstants.KEY_VOICE_VALUE);
        return fVar.b().e(e(), t);
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // e.a.a
    public final T deserialize(e.a.p.e eVar) {
        T t;
        d.n0.c.s.e(eVar, "decoder");
        e.a.o.f descriptor = getDescriptor();
        e.a.p.c cVarC = eVar.c(descriptor);
        d.n0.c.w wVar = new d.n0.c.w();
        if (cVarC.x()) {
            t = (T) b(cVarC);
        } else {
            t = null;
            while (true) {
                int iW = cVarC.w(getDescriptor());
                if (iW != -1) {
                    if (iW == 0) {
                        wVar.f2650c = (T) cVarC.t(getDescriptor(), iW);
                    } else {
                        if (iW != 1) {
                            StringBuilder sb = new StringBuilder();
                            sb.append("Invalid index in polymorphic deserialization of ");
                            String str = (String) wVar.f2650c;
                            if (str == null) {
                                str = "unknown class";
                            }
                            sb.append(str);
                            sb.append("\n Expected 0, 1 or DECODE_DONE(-1), but found ");
                            sb.append(iW);
                            throw new e.a.i(sb.toString());
                        }
                        T t2 = wVar.f2650c;
                        if (t2 == 0) {
                            throw new IllegalArgumentException("Cannot read polymorphic value before its type token".toString());
                        }
                        wVar.f2650c = t2;
                        t = (T) c.a.c(cVarC, getDescriptor(), iW, e.a.f.a(this, cVarC, (String) t2), null, 8, null);
                    }
                } else {
                    if (t == null) {
                        throw new IllegalArgumentException(("Polymorphic value has not been read for class " + ((String) wVar.f2650c)).toString());
                    }
                    d.n0.c.s.c(t, "null cannot be cast to non-null type T of kotlinx.serialization.internal.AbstractPolymorphicSerializer.deserialize$lambda$3");
                }
            }
        }
        cVarC.a(descriptor);
        return t;
    }

    public abstract d.q0.b<T> e();

    @Override // e.a.j
    public final void serialize(e.a.p.f fVar, T t) {
        d.n0.c.s.e(fVar, "encoder");
        d.n0.c.s.e(t, ITVStateConstants.KEY_VOICE_VALUE);
        e.a.j<? super T> jVarB = e.a.f.b(this, fVar, t);
        e.a.o.f descriptor = getDescriptor();
        e.a.p.d dVarC = fVar.c(descriptor);
        dVarC.r(getDescriptor(), 0, jVarB.getDescriptor().a());
        e.a.o.f descriptor2 = getDescriptor();
        d.n0.c.s.c(jVarB, "null cannot be cast to non-null type kotlinx.serialization.SerializationStrategy<T of kotlinx.serialization.internal.Platform_commonKt.cast>");
        dVarC.w(descriptor2, 1, jVarB, t);
        dVarC.a(descriptor);
    }
}
