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

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 d0 extends i {
    private static final Map zzb = new ConcurrentHashMap();
    protected m1 zzc;
    protected int zzd;

    public d0() {
        this.zza = 0;
        this.zzc = m1.f21068f;
        this.zzd = -1;
    }

    public static j0 d(j0 j0Var) {
        int size = j0Var.size();
        return j0Var.zzd(size == 0 ? 10 : size + size);
    }

    public static Object e(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 void f(Class cls, d0 d0Var) {
        zzb.put(cls, d0Var);
    }

    public static d0 j(Class cls) {
        Map map = zzb;
        d0 d0Var = (d0) map.get(cls);
        if (d0Var == null) {
            try {
                Class.forName(cls.getName(), true, cls.getClassLoader());
                d0Var = (d0) map.get(cls);
            } catch (ClassNotFoundException e10) {
                throw new IllegalStateException("Class initialization cannot fail.", e10);
            }
        }
        if (d0Var == null) {
            d0Var = (d0) ((d0) u1.h(cls)).m(6);
            if (d0Var == null) {
                throw new IllegalStateException();
            }
            map.put(cls, d0Var);
        }
        return d0Var;
    }

    public static d0 k(d0 d0Var, zzaby zzabyVar, w wVar) throws zzadi {
        zzabv zzabvVar = (zzabv) zzabyVar;
        byte[] bArr = zzabvVar.zza;
        int iG = zzabvVar.g();
        q qVar = new q(bArr, iG);
        try {
            qVar.a(iG);
            d0 d0Var2 = (d0) d0Var.m(4);
            try {
                j1 j1VarA = g1.f20921c.a(d0Var2.getClass());
                r rVar = qVar.f21144b;
                if (rVar == null) {
                    rVar = new r(qVar);
                }
                j1VarA.b(d0Var2, rVar, wVar);
                j1VarA.zzf(d0Var2);
                try {
                    if (qVar.f21149g != 0) {
                        throw new zzadi("Protocol message end-group tag did not match expected tag.");
                    }
                    if (d0Var2.g()) {
                        return d0Var2;
                    }
                    zzadi zzadiVar = new zzadi(new zzafh().getMessage());
                    zzadiVar.e(d0Var2);
                    throw zzadiVar;
                } catch (zzadi e10) {
                    e10.e(d0Var2);
                    throw e10;
                }
            } catch (zzadi e11) {
                e11.e(d0Var2);
                throw e11;
            } catch (zzafh e12) {
                zzadi zzadiVar2 = new zzadi(e12.getMessage());
                zzadiVar2.e(d0Var2);
                throw zzadiVar2;
            } catch (IOException e13) {
                if (e13.getCause() instanceof zzadi) {
                    throw ((zzadi) e13.getCause());
                }
                zzadi zzadiVar3 = new zzadi(e13);
                zzadiVar3.e(d0Var2);
                throw zzadiVar3;
            } catch (RuntimeException e14) {
                if (e14.getCause() instanceof zzadi) {
                    throw ((zzadi) e14.getCause());
                }
                throw e14;
            }
        } catch (zzadi e15) {
            throw new IllegalArgumentException(e15);
        }
    }

    public static d0 l(d0 d0Var, byte[] bArr, w wVar) throws zzadi {
        int length = bArr.length;
        d0 d0Var2 = (d0) d0Var.m(4);
        try {
            j1 j1VarA = g1.f20921c.a(d0Var2.getClass());
            j1VarA.c(d0Var2, bArr, 0, length, new com.google.android.gms.internal.ads.vc(wVar));
            j1VarA.zzf(d0Var2);
            if (d0Var2.zza != 0) {
                throw new RuntimeException();
            }
            if (d0Var2.g()) {
                return d0Var2;
            }
            zzadi zzadiVar = new zzadi(new zzafh().getMessage());
            zzadiVar.e(d0Var2);
            throw zzadiVar;
        } catch (zzadi e10) {
            e10.e(d0Var2);
            throw e10;
        } catch (zzafh e11) {
            zzadi zzadiVar2 = new zzadi(e11.getMessage());
            zzadiVar2.e(d0Var2);
            throw zzadiVar2;
        } catch (IOException e12) {
            if (e12.getCause() instanceof zzadi) {
                throw ((zzadi) e12.getCause());
            }
            zzadi zzadiVar3 = new zzadi(e12);
            zzadiVar3.e(d0Var2);
            throw zzadiVar3;
        } catch (IndexOutOfBoundsException unused) {
            zzadi zzadiVarF = zzadi.f();
            zzadiVarF.e(d0Var2);
            throw zzadiVarF;
        }
    }

    @Override // com.google.android.gms.internal.pal.z0
    public final /* synthetic */ b0 A() {
        return (b0) m(5);
    }

    @Override // com.google.android.gms.internal.pal.a1
    public final /* synthetic */ d0 a() {
        return (d0) m(6);
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj != null && getClass() == obj.getClass()) {
            return g1.f20921c.a(getClass()).zzk(this, (d0) obj);
        }
        return false;
    }

    public final boolean g() {
        byte bByteValue = ((Byte) m(1)).byteValue();
        if (bByteValue == 1) {
            return true;
        }
        if (bByteValue == 0) {
            return false;
        }
        boolean zZzl = g1.f20921c.a(getClass()).zzl(this);
        m(2);
        return zZzl;
    }

    public final int h() {
        int i10 = this.zzd;
        if (i10 != -1) {
            return i10;
        }
        int iZza = g1.f20921c.a(getClass()).zza(this);
        this.zzd = iZza;
        return iZza;
    }

    public final int hashCode() {
        int i10 = this.zza;
        if (i10 != 0) {
            return i10;
        }
        int iZzb = g1.f20921c.a(getClass()).zzb(this);
        this.zza = iZzb;
        return iZzb;
    }

    public final b0 i() {
        return (b0) m(5);
    }

    public abstract Object m(int i10);

    public final String toString() {
        String string = super.toString();
        StringBuilder sb = new StringBuilder();
        sb.append("# ");
        sb.append(string);
        q9.d0(this, sb, 0);
        return sb.toString();
    }

    @Override // com.google.android.gms.internal.pal.z0
    public final /* synthetic */ b0 zzaC() {
        b0 b0Var = (b0) m(5);
        b0Var.e(this);
        return b0Var;
    }
}
