package com.google.protobuf;

import com.google.protobuf.k0;
import com.google.protobuf.u1;
import com.google.protobuf.v1;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public final class l implements v1 {

    /* renamed from: a, reason: collision with root package name */
    private final k f15135a;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public static /* synthetic */ class a {

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

        static {
            int[] iArr = new int[u1.b.values().length];
            f15136a = iArr;
            try {
                iArr[u1.b.BOOL.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f15136a[u1.b.FIXED32.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f15136a[u1.b.INT32.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                f15136a[u1.b.SFIXED32.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                f15136a[u1.b.SINT32.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                f15136a[u1.b.UINT32.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                f15136a[u1.b.FIXED64.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                f15136a[u1.b.INT64.ordinal()] = 8;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                f15136a[u1.b.SFIXED64.ordinal()] = 9;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                f15136a[u1.b.SINT64.ordinal()] = 10;
            } catch (NoSuchFieldError unused10) {
            }
            try {
                f15136a[u1.b.UINT64.ordinal()] = 11;
            } catch (NoSuchFieldError unused11) {
            }
            try {
                f15136a[u1.b.STRING.ordinal()] = 12;
            } catch (NoSuchFieldError unused12) {
            }
        }
    }

    private l(k kVar) {
        k kVar2 = (k) z.b(kVar, "output");
        this.f15135a = kVar2;
        kVar2.f15096a = this;
    }

    public static l P(k kVar) {
        l lVar = kVar.f15096a;
        return lVar != null ? lVar : new l(kVar);
    }

    private void Q(int i10, boolean z10, Object obj, k0.a aVar) {
        this.f15135a.T0(i10, 2);
        this.f15135a.V0(k0.b(aVar, Boolean.valueOf(z10), obj));
        k0.e(this.f15135a, aVar, Boolean.valueOf(z10), obj);
    }

    private void R(int i10, k0.a aVar, Map map) {
        int size = map.size();
        int[] iArr = new int[size];
        Iterator it = map.keySet().iterator();
        int i11 = 0;
        while (it.hasNext()) {
            iArr[i11] = ((Integer) it.next()).intValue();
            i11++;
        }
        Arrays.sort(iArr);
        for (int i12 = 0; i12 < size; i12++) {
            int i13 = iArr[i12];
            Object obj = map.get(Integer.valueOf(i13));
            this.f15135a.T0(i10, 2);
            this.f15135a.V0(k0.b(aVar, Integer.valueOf(i13), obj));
            k0.e(this.f15135a, aVar, Integer.valueOf(i13), obj);
        }
    }

    private void S(int i10, k0.a aVar, Map map) {
        int size = map.size();
        long[] jArr = new long[size];
        Iterator it = map.keySet().iterator();
        int i11 = 0;
        while (it.hasNext()) {
            jArr[i11] = ((Long) it.next()).longValue();
            i11++;
        }
        Arrays.sort(jArr);
        for (int i12 = 0; i12 < size; i12++) {
            long j10 = jArr[i12];
            Object obj = map.get(Long.valueOf(j10));
            this.f15135a.T0(i10, 2);
            this.f15135a.V0(k0.b(aVar, Long.valueOf(j10), obj));
            k0.e(this.f15135a, aVar, Long.valueOf(j10), obj);
        }
    }

    private void T(int i10, k0.a aVar, Map map) {
        switch (a.f15136a[aVar.f15110a.ordinal()]) {
            case 1:
                Object obj = map.get(Boolean.FALSE);
                if (obj != null) {
                    Q(i10, false, obj, aVar);
                }
                Object obj2 = map.get(Boolean.TRUE);
                if (obj2 != null) {
                    Q(i10, true, obj2, aVar);
                    return;
                }
                return;
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
                R(i10, aVar, map);
                return;
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
                S(i10, aVar, map);
                return;
            case 12:
                U(i10, aVar, map);
                return;
            default:
                throw new IllegalArgumentException("does not support key type: " + aVar.f15110a);
        }
    }

    private void U(int i10, k0.a aVar, Map map) {
        int size = map.size();
        String[] strArr = new String[size];
        Iterator it = map.keySet().iterator();
        int i11 = 0;
        while (it.hasNext()) {
            strArr[i11] = (String) it.next();
            i11++;
        }
        Arrays.sort(strArr);
        for (int i12 = 0; i12 < size; i12++) {
            String str = strArr[i12];
            Object obj = map.get(str);
            this.f15135a.T0(i10, 2);
            this.f15135a.V0(k0.b(aVar, str, obj));
            k0.e(this.f15135a, aVar, str, obj);
        }
    }

    private void V(int i10, Object obj) {
        if (obj instanceof String) {
            this.f15135a.R0(i10, (String) obj);
        } else {
            this.f15135a.l0(i10, (h) obj);
        }
    }

    @Override // com.google.protobuf.v1
    public void A(int i10, float f10) {
        this.f15135a.v0(i10, f10);
    }

    @Override // com.google.protobuf.v1
    public void B(int i10) {
        this.f15135a.T0(i10, 4);
    }

    @Override // com.google.protobuf.v1
    public void C(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.N0(i10, ((Integer) list.get(i11)).intValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.N(((Integer) list.get(i13)).intValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.O0(((Integer) list.get(i11)).intValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void D(int i10, int i11) {
        this.f15135a.p0(i10, i11);
    }

    @Override // com.google.protobuf.v1
    public void E(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.D0(i10, ((Long) list.get(i11)).longValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.z(((Long) list.get(i13)).longValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.E0(((Long) list.get(i11)).longValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void F(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.p0(i10, ((Integer) list.get(i11)).intValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.m(((Integer) list.get(i13)).intValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.q0(((Integer) list.get(i11)).intValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void G(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.n0(i10, ((Double) list.get(i11)).doubleValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.k(((Double) list.get(i13)).doubleValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.o0(((Double) list.get(i11)).doubleValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void H(int i10, int i11) {
        this.f15135a.N0(i10, i11);
    }

    @Override // com.google.protobuf.v1
    public void I(int i10, List list) {
        for (int i11 = 0; i11 < list.size(); i11++) {
            this.f15135a.l0(i10, (h) list.get(i11));
        }
    }

    @Override // com.google.protobuf.v1
    public void J(int i10, List list, h1 h1Var) {
        for (int i11 = 0; i11 < list.size(); i11++) {
            L(i10, list.get(i11), h1Var);
        }
    }

    @Override // com.google.protobuf.v1
    public void K(int i10, List list, h1 h1Var) {
        for (int i11 = 0; i11 < list.size(); i11++) {
            M(i10, list.get(i11), h1Var);
        }
    }

    @Override // com.google.protobuf.v1
    public void L(int i10, Object obj, h1 h1Var) {
        this.f15135a.F0(i10, (r0) obj, h1Var);
    }

    @Override // com.google.protobuf.v1
    public void M(int i10, Object obj, h1 h1Var) {
        this.f15135a.y0(i10, (r0) obj, h1Var);
    }

    @Override // com.google.protobuf.v1
    public void N(int i10, h hVar) {
        this.f15135a.l0(i10, hVar);
    }

    @Override // com.google.protobuf.v1
    public void O(int i10, k0.a aVar, Map map) {
        if (this.f15135a.b0()) {
            T(i10, aVar, map);
            return;
        }
        for (Map.Entry entry : map.entrySet()) {
            this.f15135a.T0(i10, 2);
            this.f15135a.V0(k0.b(aVar, entry.getKey(), entry.getValue()));
            k0.e(this.f15135a, aVar, entry.getKey(), entry.getValue());
        }
    }

    @Override // com.google.protobuf.v1
    public void a(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.v0(i10, ((Float) list.get(i11)).floatValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.s(((Float) list.get(i13)).floatValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.w0(((Float) list.get(i11)).floatValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void b(int i10, int i11) {
        this.f15135a.U0(i10, i11);
    }

    @Override // com.google.protobuf.v1
    public final void c(int i10, Object obj) {
        if (obj instanceof h) {
            this.f15135a.I0(i10, (h) obj);
        } else {
            this.f15135a.H0(i10, (r0) obj);
        }
    }

    @Override // com.google.protobuf.v1
    public void d(int i10, int i11) {
        this.f15135a.r0(i10, i11);
    }

    @Override // com.google.protobuf.v1
    public void e(int i10, double d10) {
        this.f15135a.n0(i10, d10);
    }

    @Override // com.google.protobuf.v1
    public void f(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.L0(i10, ((Long) list.get(i11)).longValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.L(((Long) list.get(i13)).longValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.M0(((Long) list.get(i11)).longValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void g(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.W0(i10, ((Long) list.get(i11)).longValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.W(((Long) list.get(i13)).longValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.X0(((Long) list.get(i11)).longValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void h(int i10, long j10) {
        this.f15135a.t0(i10, j10);
    }

    @Override // com.google.protobuf.v1
    public v1.a i() {
        return v1.a.ASCENDING;
    }

    @Override // com.google.protobuf.v1
    public void j(int i10, List list) {
        int i11 = 0;
        if (!(list instanceof g0)) {
            while (i11 < list.size()) {
                this.f15135a.R0(i10, (String) list.get(i11));
                i11++;
            }
        } else {
            g0 g0Var = (g0) list;
            while (i11 < list.size()) {
                V(i10, g0Var.f(i11));
                i11++;
            }
        }
    }

    @Override // com.google.protobuf.v1
    public void k(int i10, String str) {
        this.f15135a.R0(i10, str);
    }

    @Override // com.google.protobuf.v1
    public void l(int i10, long j10) {
        this.f15135a.W0(i10, j10);
    }

    @Override // com.google.protobuf.v1
    public void m(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.B0(i10, ((Integer) list.get(i11)).intValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.x(((Integer) list.get(i13)).intValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.C0(((Integer) list.get(i11)).intValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void n(int i10, long j10) {
        this.f15135a.D0(i10, j10);
    }

    @Override // com.google.protobuf.v1
    public void o(int i10, boolean z10) {
        this.f15135a.h0(i10, z10);
    }

    @Override // com.google.protobuf.v1
    public void p(int i10, int i11) {
        this.f15135a.J0(i10, i11);
    }

    @Override // com.google.protobuf.v1
    public void q(int i10) {
        this.f15135a.T0(i10, 3);
    }

    @Override // com.google.protobuf.v1
    public void r(int i10, int i11) {
        this.f15135a.B0(i10, i11);
    }

    @Override // com.google.protobuf.v1
    public void s(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.t0(i10, ((Long) list.get(i11)).longValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.q(((Long) list.get(i13)).longValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.u0(((Long) list.get(i11)).longValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void t(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.J0(i10, ((Integer) list.get(i11)).intValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.J(((Integer) list.get(i13)).intValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.K0(((Integer) list.get(i11)).intValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void u(int i10, long j10) {
        this.f15135a.L0(i10, j10);
    }

    @Override // com.google.protobuf.v1
    public void v(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.r0(i10, ((Integer) list.get(i11)).intValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.o(((Integer) list.get(i13)).intValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.s0(((Integer) list.get(i11)).intValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void w(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.h0(i10, ((Boolean) list.get(i11)).booleanValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.f(((Boolean) list.get(i13)).booleanValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.i0(((Boolean) list.get(i11)).booleanValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void x(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.U0(i10, ((Integer) list.get(i11)).intValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.U(((Integer) list.get(i13)).intValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.V0(((Integer) list.get(i11)).intValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void y(int i10, List list, boolean z10) {
        int i11 = 0;
        if (!z10) {
            while (i11 < list.size()) {
                this.f15135a.P0(i10, ((Long) list.get(i11)).longValue());
                i11++;
            }
            return;
        }
        this.f15135a.T0(i10, 2);
        int i12 = 0;
        for (int i13 = 0; i13 < list.size(); i13++) {
            i12 += k.P(((Long) list.get(i13)).longValue());
        }
        this.f15135a.V0(i12);
        while (i11 < list.size()) {
            this.f15135a.Q0(((Long) list.get(i11)).longValue());
            i11++;
        }
    }

    @Override // com.google.protobuf.v1
    public void z(int i10, long j10) {
        this.f15135a.P0(i10, j10);
    }
}
