package com.google.android.gms.internal.ads;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/* JADX INFO: loaded from: classes2.dex */
public abstract class cb2 extends ca2 {
    private static final int zza = Integer.MIN_VALUE;
    private static final int zzb = Integer.MAX_VALUE;
    private static Map<Class<?>, cb2> zzd = new ConcurrentHashMap();
    static final int zzr = Integer.MAX_VALUE;
    static final int zzs = 0;
    private int zzc;
    protected nc2 zzt;

    public cb2() {
        this.zzq = 0;
        this.zzc = -1;
        this.zzt = nc2.f14529f;
    }

    public static void A(cb2 cb2Var) {
        if (cb2Var != null && !y(cb2Var, true)) {
            throw new zzicg(new zziee().getMessage());
        }
    }

    public static Object j(Method method, Object obj, Object... objArr) {
        try {
            return method.invoke(obj, objArr);
        } catch (IllegalAccessException e10) {
            throw new RuntimeException("Couldn't use Java reflection to implement protocol message reflection.", e10);
        } catch (InvocationTargetException e11) {
            Throwable cause = e11.getCause();
            if (cause instanceof RuntimeException) {
                throw ((RuntimeException) cause);
            }
            if (cause instanceof Error) {
                throw ((Error) cause);
            }
            throw new RuntimeException("Unexpected exception thrown by generated accessor method.", cause);
        }
    }

    public static ob2 k(ib2 ib2Var) {
        int size = ib2Var.size();
        return ((ob2) ib2Var).zzh(size + size);
    }

    public static cb2 l(cb2 cb2Var, ma2 ma2Var, ua2 ua2Var) throws zzicg {
        cb2 cb2VarP = cb2Var.p();
        try {
            ic2 ic2VarB = dc2.f10372c.b(cb2VarP.getClass());
            na2 na2Var = ma2Var.f14051c;
            if (na2Var == null) {
                na2Var = new na2(ma2Var);
            }
            ic2VarB.g(cb2VarP, na2Var, ua2Var);
            ic2VarB.f(cb2VarP);
            return cb2VarP;
        } catch (zzicg e10) {
            if (e10.b()) {
                throw new zzicg(e10.getMessage(), e10);
            }
            throw e10;
        } catch (zziee e11) {
            throw new zzicg(e11.getMessage());
        } catch (IOException e12) {
            if (e12.getCause() instanceof zzicg) {
                throw ((zzicg) e12.getCause());
            }
            throw new zzicg(e12.getMessage(), e12);
        } catch (RuntimeException e13) {
            if (e13.getCause() instanceof zzicg) {
                throw ((zzicg) e13.getCause());
            }
            throw e13;
        }
    }

    public static cb2 m(cb2 cb2Var, zzian zzianVar, ua2 ua2Var) {
        ma2 ma2VarS = zzianVar.s();
        cb2 cb2VarL = l(cb2Var, ma2VarS, ua2Var);
        ma2VarS.j(0);
        A(cb2VarL);
        return cb2VarL;
    }

    public static cb2 u(Class cls) {
        cb2 cb2Var = zzd.get(cls);
        if (cb2Var == null) {
            try {
                Class.forName(cls.getName(), true, cls.getClassLoader());
                cb2Var = zzd.get(cls);
            } catch (ClassNotFoundException e10) {
                throw new IllegalStateException("Class initialization cannot fail.", e10);
            }
        }
        if (cb2Var == null) {
            cb2Var = (cb2) ((cb2) sc2.e(cls)).x(zzibq.f19866f, null);
            if (cb2Var == null) {
                throw new IllegalStateException();
            }
            zzd.put(cls, cb2Var);
        }
        return cb2Var;
    }

    public static void v(Class cls, cb2 cb2Var) {
        cb2Var.i();
        zzd.put(cls, cb2Var);
    }

    public static final boolean y(cb2 cb2Var, boolean z10) {
        byte bByteValue = ((Byte) cb2Var.x(zzibq.f19861a, null)).byteValue();
        if (bByteValue == 1) {
            return true;
        }
        if (bByteValue == 0) {
            return false;
        }
        boolean zZzl = dc2.f10372c.b(cb2Var.getClass()).zzl(cb2Var);
        if (z10) {
            cb2Var.x(zzibq.f19862b, true == zZzl ? cb2Var : null);
        }
        return zZzl;
    }

    public static cb2 z(cb2 cb2Var, byte[] bArr, int i10, ua2 ua2Var) throws zzicg {
        if (i10 == 0) {
            return cb2Var;
        }
        cb2 cb2VarP = cb2Var.p();
        try {
            ic2 ic2VarB = dc2.f10372c.b(cb2VarP.getClass());
            ic2VarB.i(cb2VarP, bArr, 0, i10, new ga2(ua2Var));
            ic2VarB.f(cb2VarP);
            return cb2VarP;
        } catch (zzicg e10) {
            if (e10.b()) {
                throw new zzicg(e10.getMessage(), e10);
            }
            throw e10;
        } catch (zziee e11) {
            throw new zzicg(e11.getMessage());
        } catch (IOException e12) {
            if (e12.getCause() instanceof zzicg) {
                throw ((zzicg) e12.getCause());
            }
            throw new zzicg(e12.getMessage(), e12);
        } catch (IndexOutOfBoundsException unused) {
            throw new zzicg("While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.");
        }
    }

    @Override // com.google.android.gms.internal.ads.ca2
    public final int d(ic2 ic2Var) {
        int iA;
        int iA2;
        if (h()) {
            if (ic2Var == null) {
                iA2 = dc2.f10372c.b(getClass()).a(this);
            } else {
                iA2 = ic2Var.a(this);
            }
            if (iA2 >= 0) {
                return iA2;
            }
            throw new IllegalStateException(defpackage.e.n(new StringBuilder(String.valueOf(iA2).length() + 42), "serialized size must be non-negative, was ", iA2));
        }
        int i10 = this.zzc;
        if ((i10 & Integer.MAX_VALUE) != Integer.MAX_VALUE) {
            return i10 & Integer.MAX_VALUE;
        }
        if (ic2Var == null) {
            iA = dc2.f10372c.b(getClass()).a(this);
        } else {
            iA = ic2Var.a(this);
        }
        g(iA);
        return iA;
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        return dc2.f10372c.b(getClass()).c(this, (cb2) obj);
    }

    public final void g(int i10) {
        if (i10 < 0) {
            throw new IllegalStateException(defpackage.e.n(new StringBuilder(String.valueOf(i10).length() + 42), "serialized size must be non-negative, was ", i10));
        }
        this.zzc = i10 | (this.zzc & Integer.MIN_VALUE);
    }

    public final boolean h() {
        return (this.zzc & Integer.MIN_VALUE) != 0;
    }

    public final int hashCode() {
        if (h()) {
            return dc2.f10372c.b(getClass()).e(this);
        }
        if (this.zzq == 0) {
            this.zzq = dc2.f10372c.b(getClass()).e(this);
        }
        return this.zzq;
    }

    public final void i() {
        this.zzc &= Integer.MAX_VALUE;
    }

    public final void n() {
        this.zzq = 0;
    }

    public final bc2 o() {
        return (bc2) x(zzibq.f19867g, null);
    }

    public final cb2 p() {
        return (cb2) x(zzibq.f19864d, null);
    }

    public final void q() {
        dc2.f10372c.b(getClass()).f(this);
        i();
    }

    public final ab2 r() {
        return (ab2) x(zzibq.f19865e, null);
    }

    public final ab2 s() {
        ab2 ab2Var = (ab2) x(zzibq.f19865e, null);
        ab2Var.f(this);
        return ab2Var;
    }

    public final void t() {
        g(Integer.MAX_VALUE);
    }

    public final String toString() {
        String string = super.toString();
        char[] cArr = xb2.f18402a;
        StringBuilder sb = new StringBuilder();
        sb.append("# ");
        sb.append(string);
        xb2.b(this, sb, 0);
        return sb.toString();
    }

    public final void w(qa2 qa2Var) {
        ic2 ic2VarB = dc2.f10372c.b(getClass());
        ra2 ra2Var = qa2Var.f15674b;
        if (ra2Var == null) {
            ra2Var = new ra2(qa2Var);
        }
        ic2VarB.h(this, ra2Var);
    }

    public abstract Object x(zzibq zzibqVar, cb2 cb2Var);
}
