package androidx.datastore.preferences.protobuf;

import androidx.datastore.preferences.protobuf.InvalidProtocolBufferException;
import java.nio.charset.Charset;

/* JADX INFO: loaded from: classes.dex */
public final class l implements y0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final k f2106a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f2107b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f2108c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f2109d = 0;

    public l(k kVar) {
        Charset charset = b0.f2047a;
        this.f2106a = kVar;
        kVar.f2104d = this;
    }

    public static void y(int i10) throws InvalidProtocolBufferException {
        if ((i10 & 3) != 0) {
            throw new InvalidProtocolBufferException("Failed to parse the message.");
        }
    }

    public static void z(int i10) throws InvalidProtocolBufferException {
        if ((i10 & 7) != 0) {
            throw new InvalidProtocolBufferException("Failed to parse the message.");
        }
    }

    public final int a() {
        int i10 = this.f2109d;
        if (i10 != 0) {
            this.f2107b = i10;
            this.f2109d = 0;
        } else {
            this.f2107b = this.f2106a.u();
        }
        int i11 = this.f2107b;
        if (i11 == 0 || i11 == this.f2108c) {
            return Integer.MAX_VALUE;
        }
        return i11 >>> 3;
    }

    public final void b(Object obj, z0 z0Var, q qVar) {
        int i10 = this.f2108c;
        this.f2108c = ((this.f2107b >>> 3) << 3) | 4;
        try {
            z0Var.h(obj, this, qVar);
            if (this.f2107b == this.f2108c) {
            } else {
                throw new InvalidProtocolBufferException("Failed to parse the message.");
            }
        } finally {
            this.f2108c = i10;
        }
    }

    public final void c(Object obj, z0 z0Var, q qVar) throws InvalidProtocolBufferException {
        k kVar = this.f2106a;
        int iV = kVar.v();
        if (kVar.f2101a >= kVar.f2102b) {
            throw new InvalidProtocolBufferException("Protocol message had too many levels of nesting.  May be malicious.  Use setRecursionLimit() to increase the recursion depth limit.");
        }
        int iE = kVar.e(iV);
        kVar.f2101a++;
        z0Var.h(obj, this, qVar);
        kVar.a(0);
        kVar.f2101a--;
        kVar.d(iE);
    }

    public final void d(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 0) {
            do {
                a0Var.add(Boolean.valueOf(kVar.f()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iB = kVar.b() + kVar.v();
        do {
            a0Var.add(Boolean.valueOf(kVar.f()));
        } while (kVar.b() < iB);
        v(iB);
    }

    public final ByteString e() throws InvalidProtocolBufferException.InvalidWireTypeException {
        w(2);
        return this.f2106a.g();
    }

    public final void f(a0 a0Var) throws InvalidProtocolBufferException.InvalidWireTypeException {
        int iU;
        if ((this.f2107b & 7) != 2) {
            throw InvalidProtocolBufferException.c();
        }
        do {
            a0Var.add(e());
            k kVar = this.f2106a;
            if (kVar.c()) {
                return;
            } else {
                iU = kVar.u();
            }
        } while (iU == this.f2107b);
        this.f2109d = iU;
    }

    public final void g(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 1) {
            do {
                a0Var.add(Double.valueOf(kVar.h()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iV = kVar.v();
        z(iV);
        int iB = kVar.b() + iV;
        do {
            a0Var.add(Double.valueOf(kVar.h()));
        } while (kVar.b() < iB);
    }

    public final void h(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 0) {
            do {
                a0Var.add(Integer.valueOf(kVar.i()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iB = kVar.b() + kVar.v();
        do {
            a0Var.add(Integer.valueOf(kVar.i()));
        } while (kVar.b() < iB);
        v(iB);
    }

    public final Object i(WireFormat$FieldType wireFormat$FieldType, Class cls, q qVar) throws InvalidProtocolBufferException {
        int iOrdinal = wireFormat$FieldType.ordinal();
        k kVar = this.f2106a;
        switch (iOrdinal) {
            case 0:
                w(1);
                return Double.valueOf(kVar.h());
            case 1:
                w(5);
                return Float.valueOf(kVar.l());
            case 2:
                w(0);
                return Long.valueOf(kVar.n());
            case 3:
                w(0);
                return Long.valueOf(kVar.w());
            case 4:
                w(0);
                return Integer.valueOf(kVar.m());
            case 5:
                w(1);
                return Long.valueOf(kVar.k());
            case 6:
                w(5);
                return Integer.valueOf(kVar.j());
            case 7:
                w(0);
                return Boolean.valueOf(kVar.f());
            case 8:
                w(2);
                return kVar.t();
            case 9:
            default:
                throw new IllegalArgumentException("unsupported field type.");
            case 10:
                w(2);
                z0 z0VarA = v0.f2160c.a(cls);
                y yVarF = z0VarA.f();
                c(yVarF, z0VarA, qVar);
                z0VarA.b(yVarF);
                return yVarF;
            case 11:
                return e();
            case 12:
                w(0);
                return Integer.valueOf(kVar.v());
            case 13:
                w(0);
                return Integer.valueOf(kVar.i());
            case 14:
                w(5);
                return Integer.valueOf(kVar.o());
            case 15:
                w(1);
                return Long.valueOf(kVar.p());
            case 16:
                w(0);
                return Integer.valueOf(kVar.q());
            case 17:
                w(0);
                return Long.valueOf(kVar.r());
        }
    }

    public final void j(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 2) {
            int iV = kVar.v();
            y(iV);
            int iB = kVar.b() + iV;
            do {
                a0Var.add(Integer.valueOf(kVar.j()));
            } while (kVar.b() < iB);
            return;
        }
        if (i10 != 5) {
            throw InvalidProtocolBufferException.c();
        }
        do {
            a0Var.add(Integer.valueOf(kVar.j()));
            if (kVar.c()) {
                return;
            } else {
                iU = kVar.u();
            }
        } while (iU == this.f2107b);
        this.f2109d = iU;
    }

    public final void k(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 1) {
            do {
                a0Var.add(Long.valueOf(kVar.k()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iV = kVar.v();
        z(iV);
        int iB = kVar.b() + iV;
        do {
            a0Var.add(Long.valueOf(kVar.k()));
        } while (kVar.b() < iB);
    }

    public final void l(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 2) {
            int iV = kVar.v();
            y(iV);
            int iB = kVar.b() + iV;
            do {
                a0Var.add(Float.valueOf(kVar.l()));
            } while (kVar.b() < iB);
            return;
        }
        if (i10 != 5) {
            throw InvalidProtocolBufferException.c();
        }
        do {
            a0Var.add(Float.valueOf(kVar.l()));
            if (kVar.c()) {
                return;
            } else {
                iU = kVar.u();
            }
        } while (iU == this.f2107b);
        this.f2109d = iU;
    }

    public final void m(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 0) {
            do {
                a0Var.add(Integer.valueOf(kVar.m()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iB = kVar.b() + kVar.v();
        do {
            a0Var.add(Integer.valueOf(kVar.m()));
        } while (kVar.b() < iB);
        v(iB);
    }

    public final void n(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 0) {
            do {
                a0Var.add(Long.valueOf(kVar.n()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iB = kVar.b() + kVar.v();
        do {
            a0Var.add(Long.valueOf(kVar.n()));
        } while (kVar.b() < iB);
        v(iB);
    }

    public final void o(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 2) {
            int iV = kVar.v();
            y(iV);
            int iB = kVar.b() + iV;
            do {
                a0Var.add(Integer.valueOf(kVar.o()));
            } while (kVar.b() < iB);
            return;
        }
        if (i10 != 5) {
            throw InvalidProtocolBufferException.c();
        }
        do {
            a0Var.add(Integer.valueOf(kVar.o()));
            if (kVar.c()) {
                return;
            } else {
                iU = kVar.u();
            }
        } while (iU == this.f2107b);
        this.f2109d = iU;
    }

    public final void p(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 1) {
            do {
                a0Var.add(Long.valueOf(kVar.p()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iV = kVar.v();
        z(iV);
        int iB = kVar.b() + iV;
        do {
            a0Var.add(Long.valueOf(kVar.p()));
        } while (kVar.b() < iB);
    }

    public final void q(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 0) {
            do {
                a0Var.add(Integer.valueOf(kVar.q()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iB = kVar.b() + kVar.v();
        do {
            a0Var.add(Integer.valueOf(kVar.q()));
        } while (kVar.b() < iB);
        v(iB);
    }

    public final void r(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 0) {
            do {
                a0Var.add(Long.valueOf(kVar.r()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iB = kVar.b() + kVar.v();
        do {
            a0Var.add(Long.valueOf(kVar.r()));
        } while (kVar.b() < iB);
        v(iB);
    }

    public final void s(a0 a0Var, boolean z10) throws InvalidProtocolBufferException.InvalidWireTypeException {
        String strS;
        int iU;
        if ((this.f2107b & 7) != 2) {
            throw InvalidProtocolBufferException.c();
        }
        do {
            k kVar = this.f2106a;
            if (z10) {
                w(2);
                strS = kVar.t();
            } else {
                w(2);
                strS = kVar.s();
            }
            a0Var.add(strS);
            if (kVar.c()) {
                return;
            } else {
                iU = kVar.u();
            }
        } while (iU == this.f2107b);
        this.f2109d = iU;
    }

    public final void t(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 0) {
            do {
                a0Var.add(Integer.valueOf(kVar.v()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iB = kVar.b() + kVar.v();
        do {
            a0Var.add(Integer.valueOf(kVar.v()));
        } while (kVar.b() < iB);
        v(iB);
    }

    public final void u(a0 a0Var) throws InvalidProtocolBufferException {
        int iU;
        int i10 = this.f2107b & 7;
        k kVar = this.f2106a;
        if (i10 == 0) {
            do {
                a0Var.add(Long.valueOf(kVar.w()));
                if (kVar.c()) {
                    return;
                } else {
                    iU = kVar.u();
                }
            } while (iU == this.f2107b);
            this.f2109d = iU;
            return;
        }
        if (i10 != 2) {
            throw InvalidProtocolBufferException.c();
        }
        int iB = kVar.b() + kVar.v();
        do {
            a0Var.add(Long.valueOf(kVar.w()));
        } while (kVar.b() < iB);
        v(iB);
    }

    public final void v(int i10) throws InvalidProtocolBufferException {
        if (this.f2106a.b() != i10) {
            throw InvalidProtocolBufferException.h();
        }
    }

    public final void w(int i10) throws InvalidProtocolBufferException.InvalidWireTypeException {
        if ((this.f2107b & 7) != i10) {
            throw InvalidProtocolBufferException.c();
        }
    }

    public final boolean x() {
        int i10;
        k kVar = this.f2106a;
        if (kVar.c() || (i10 = this.f2107b) == this.f2108c) {
            return false;
        }
        return kVar.x(i10);
    }
}
