package com.google.protobuf;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

/* JADX INFO: loaded from: classes3.dex */
public final class C {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final L0 f14162a = new L0(16);

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

    static {
        new C(0);
    }

    public C() {
    }

    public static int a(k1 k1Var, int i6, Object obj) {
        int serializedSize;
        int iE;
        int iF = 1;
        int iD = AbstractC1335v.D(i6);
        if (k1Var == k1.f14288d) {
            iD *= 2;
        }
        switch (k1Var.ordinal()) {
            case 0:
                ((Double) obj).getClass();
                Logger logger = AbstractC1335v.f14361d;
                iF = 8;
                return iF + iD;
            case 1:
                ((Float) obj).getClass();
                Logger logger2 = AbstractC1335v.f14361d;
                iF = 4;
                return iF + iD;
            case 2:
                iF = AbstractC1335v.F(((Long) obj).longValue());
                return iF + iD;
            case 3:
                iF = AbstractC1335v.F(((Long) obj).longValue());
                return iF + iD;
            case 4:
                iF = AbstractC1335v.B(((Integer) obj).intValue());
                return iF + iD;
            case 5:
                ((Long) obj).getClass();
                Logger logger3 = AbstractC1335v.f14361d;
                iF = 8;
                return iF + iD;
            case 6:
                ((Integer) obj).getClass();
                Logger logger4 = AbstractC1335v.f14361d;
                iF = 4;
                return iF + iD;
            case 7:
                ((Boolean) obj).getClass();
                Logger logger5 = AbstractC1335v.f14361d;
                return iF + iD;
            case 8:
                iF = obj instanceof AbstractC1320n ? AbstractC1335v.A((AbstractC1320n) obj) : AbstractC1335v.C((String) obj);
                return iF + iD;
            case 9:
                Logger logger6 = AbstractC1335v.f14361d;
                iF = ((InterfaceC1332t0) obj).getSerializedSize();
                return iF + iD;
            case 10:
                Logger logger7 = AbstractC1335v.f14361d;
                serializedSize = ((InterfaceC1332t0) obj).getSerializedSize();
                iE = AbstractC1335v.E(serializedSize);
                iF = iE + serializedSize;
                return iF + iD;
            case 11:
                if (obj instanceof AbstractC1320n) {
                    iF = AbstractC1335v.A((AbstractC1320n) obj);
                    return iF + iD;
                }
                Logger logger8 = AbstractC1335v.f14361d;
                serializedSize = ((byte[]) obj).length;
                iE = AbstractC1335v.E(serializedSize);
                iF = iE + serializedSize;
                return iF + iD;
            case 12:
                iF = AbstractC1335v.E(((Integer) obj).intValue());
                return iF + iD;
            case 13:
                iF = obj instanceof T ? AbstractC1335v.B(((T) obj).getNumber()) : AbstractC1335v.B(((Integer) obj).intValue());
                return iF + iD;
            case 14:
                ((Integer) obj).getClass();
                Logger logger9 = AbstractC1335v.f14361d;
                iF = 4;
                return iF + iD;
            case 15:
                ((Long) obj).getClass();
                Logger logger10 = AbstractC1335v.f14361d;
                iF = 8;
                return iF + iD;
            case 16:
                int iIntValue = ((Integer) obj).intValue();
                iF = AbstractC1335v.E((iIntValue >> 31) ^ (iIntValue << 1));
                return iF + iD;
            case 17:
                long jLongValue = ((Long) obj).longValue();
                iF = AbstractC1335v.F((jLongValue >> 63) ^ (jLongValue << 1));
                return iF + iD;
            default:
                throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
        }
    }

    public static void d(I i6, Object obj) {
        k1 k1Var = i6.f14191b;
        Charset charset = Z.f14234a;
        obj.getClass();
        boolean z6 = true;
        switch (k1Var.f14291a) {
            case INT:
                z6 = obj instanceof Integer;
                break;
            case LONG:
                z6 = obj instanceof Long;
                break;
            case FLOAT:
                z6 = obj instanceof Float;
                break;
            case DOUBLE:
                z6 = obj instanceof Double;
                break;
            case BOOLEAN:
                z6 = obj instanceof Boolean;
                break;
            case STRING:
                z6 = obj instanceof String;
                break;
            case BYTE_STRING:
                if (!(obj instanceof AbstractC1320n) && !(obj instanceof byte[])) {
                    z6 = false;
                }
                break;
            case ENUM:
                if (!(obj instanceof Integer) && !(obj instanceof T)) {
                    z6 = false;
                }
                break;
            case MESSAGE:
                if (!(obj instanceof InterfaceC1332t0)) {
                    z6 = false;
                }
                break;
            default:
                z6 = false;
                break;
        }
        if (!z6) {
            throw new IllegalArgumentException(String.format("Wrong object type used with protocol message reflection.\nField number: %d, field java type: %s, value type: %s\n", Integer.valueOf(i6.f14190a), i6.f14191b.f14291a, obj.getClass().getName()));
        }
    }

    public static void e(AbstractC1335v abstractC1335v, k1 k1Var, int i6, Object obj) {
        if (k1Var == k1.f14288d) {
            abstractC1335v.W(i6, 3);
            ((InterfaceC1332t0) obj).writeTo(abstractC1335v);
            abstractC1335v.W(i6, 4);
        }
        abstractC1335v.W(i6, k1Var.f14292b);
        switch (k1Var.ordinal()) {
            case 0:
                abstractC1335v.P(Double.doubleToRawLongBits(((Double) obj).doubleValue()));
                break;
            case 1:
                abstractC1335v.N(Float.floatToRawIntBits(((Float) obj).floatValue()));
                break;
            case 2:
                abstractC1335v.a0(((Long) obj).longValue());
                break;
            case 3:
                abstractC1335v.a0(((Long) obj).longValue());
                break;
            case 4:
                abstractC1335v.R(((Integer) obj).intValue());
                break;
            case 5:
                abstractC1335v.P(((Long) obj).longValue());
                break;
            case 6:
                abstractC1335v.N(((Integer) obj).intValue());
                break;
            case 7:
                abstractC1335v.H(((Boolean) obj).booleanValue() ? (byte) 1 : (byte) 0);
                break;
            case 8:
                if (!(obj instanceof AbstractC1320n)) {
                    abstractC1335v.V((String) obj);
                } else {
                    abstractC1335v.L((AbstractC1320n) obj);
                }
                break;
            case 9:
                ((InterfaceC1332t0) obj).writeTo(abstractC1335v);
                break;
            case 10:
                abstractC1335v.T((InterfaceC1332t0) obj);
                break;
            case 11:
                if (!(obj instanceof AbstractC1320n)) {
                    byte[] bArr = (byte[]) obj;
                    abstractC1335v.J(bArr, bArr.length);
                } else {
                    abstractC1335v.L((AbstractC1320n) obj);
                }
                break;
            case 12:
                abstractC1335v.Y(((Integer) obj).intValue());
                break;
            case 13:
                if (!(obj instanceof T)) {
                    abstractC1335v.R(((Integer) obj).intValue());
                } else {
                    abstractC1335v.R(((T) obj).getNumber());
                }
                break;
            case 14:
                abstractC1335v.N(((Integer) obj).intValue());
                break;
            case 15:
                abstractC1335v.P(((Long) obj).longValue());
                break;
            case 16:
                int iIntValue = ((Integer) obj).intValue();
                abstractC1335v.Y((iIntValue >> 31) ^ (iIntValue << 1));
                break;
            case 17:
                long jLongValue = ((Long) obj).longValue();
                abstractC1335v.a0((jLongValue >> 63) ^ (jLongValue << 1));
                break;
        }
    }

    public final void b() {
        L0 l02;
        if (this.f14163b) {
            return;
        }
        int i6 = 0;
        while (true) {
            l02 = this.f14162a;
            if (i6 >= l02.f14212b.size()) {
                break;
            }
            Map.Entry entryC = l02.c(i6);
            if (entryC.getValue() instanceof L) {
                ((L) entryC.getValue()).makeImmutable();
            }
            i6++;
        }
        if (!l02.f14214d) {
            for (int i7 = 0; i7 < l02.f14212b.size(); i7++) {
                Map.Entry entryC2 = l02.c(i7);
                if (((I) entryC2.getKey()).f14192c) {
                    entryC2.setValue(Collections.unmodifiableList((List) entryC2.getValue()));
                }
            }
            for (Map.Entry entry : l02.d()) {
                if (((I) entry.getKey()).f14192c) {
                    entry.setValue(Collections.unmodifiableList((List) entry.getValue()));
                }
            }
        }
        if (!l02.f14214d) {
            l02.f14213c = l02.f14213c.isEmpty() ? Collections.EMPTY_MAP : Collections.unmodifiableMap(l02.f14213c);
            l02.f14216f = l02.f14216f.isEmpty() ? Collections.EMPTY_MAP : Collections.unmodifiableMap(l02.f14216f);
            l02.f14214d = true;
        }
        this.f14163b = true;
    }

    public final void c(I i6, Object obj) {
        if (!i6.f14192c) {
            d(i6, obj);
        } else {
            if (!(obj instanceof List)) {
                throw new IllegalArgumentException("Wrong object type used with protocol message reflection.");
            }
            ArrayList arrayList = new ArrayList();
            arrayList.addAll((List) obj);
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                d(i6, it.next());
            }
            obj = arrayList;
        }
        this.f14162a.put(i6, obj);
    }

    public final Object clone() {
        L0 l02;
        C c6 = new C();
        int i6 = 0;
        while (true) {
            l02 = this.f14162a;
            if (i6 >= l02.f14212b.size()) {
                break;
            }
            Map.Entry entryC = l02.c(i6);
            c6.c((I) entryC.getKey(), entryC.getValue());
            i6++;
        }
        for (Map.Entry entry : l02.d()) {
            c6.c((I) entry.getKey(), entry.getValue());
        }
        return c6;
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof C) {
            return this.f14162a.equals(((C) obj).f14162a);
        }
        return false;
    }

    public final int hashCode() {
        return this.f14162a.hashCode();
    }

    public C(int i6) {
        b();
        b();
    }
}
