package com.google.protobuf;

import java.lang.reflect.Field;
import java.nio.Buffer;
import java.nio.ByteOrder;
import java.security.AccessController;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.Unsafe;

/* JADX INFO: loaded from: classes3.dex */
public abstract class c1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final Unsafe f14249a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Class f14250b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final b1 f14251c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final boolean f14252d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final boolean f14253e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final long f14254f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final long f14255g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final boolean f14256h;

    static {
        Unsafe unsafeJ = j();
        f14249a = unsafeJ;
        f14250b = AbstractC1302e.f14269a;
        boolean zF = f(Long.TYPE);
        boolean zF2 = f(Integer.TYPE);
        b1 a1Var = null;
        if (unsafeJ != null) {
            if (!AbstractC1302e.a()) {
                a1Var = new a1(unsafeJ);
            } else if (zF) {
                a1Var = new Z0(unsafeJ, 1);
            } else if (zF2) {
                a1Var = new Z0(unsafeJ, 0);
            }
        }
        f14251c = a1Var;
        f14252d = a1Var == null ? false : a1Var.u();
        f14253e = a1Var == null ? false : a1Var.t();
        f14254f = c(byte[].class);
        c(boolean[].class);
        d(boolean[].class);
        c(int[].class);
        d(int[].class);
        c(long[].class);
        d(long[].class);
        c(float[].class);
        d(float[].class);
        c(double[].class);
        d(double[].class);
        c(Object[].class);
        d(Object[].class);
        Field fieldE = e();
        f14255g = (fieldE == null || a1Var == null) ? -1L : a1Var.l(fieldE);
        f14256h = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
    }

    public static void a(Throwable th) {
        Logger.getLogger(c1.class.getName()).log(Level.WARNING, "platform method missing - proto runtime falling back to safer methods: " + th);
    }

    public static Object b(Class cls) {
        try {
            return f14249a.allocateInstance(cls);
        } catch (InstantiationException e6) {
            throw new IllegalStateException(e6);
        }
    }

    public static int c(Class cls) {
        if (f14253e) {
            return f14251c.a(cls);
        }
        return -1;
    }

    public static void d(Class cls) {
        if (f14253e) {
            f14251c.b(cls);
        }
    }

    public static Field e() {
        Field declaredField;
        Field declaredField2;
        if (AbstractC1302e.a()) {
            try {
                declaredField2 = Buffer.class.getDeclaredField("effectiveDirectAddress");
            } catch (Throwable unused) {
                declaredField2 = null;
            }
            if (declaredField2 != null) {
                return declaredField2;
            }
        }
        try {
            declaredField = Buffer.class.getDeclaredField("address");
        } catch (Throwable unused2) {
            declaredField = null;
        }
        if (declaredField == null || declaredField.getType() != Long.TYPE) {
            return null;
        }
        return declaredField;
    }

    public static boolean f(Class cls) {
        if (!AbstractC1302e.a()) {
            return false;
        }
        try {
            Class cls2 = f14250b;
            Class cls3 = Boolean.TYPE;
            cls2.getMethod("peekLong", cls, cls3);
            cls2.getMethod("pokeLong", cls, Long.TYPE, cls3);
            Class cls4 = Integer.TYPE;
            cls2.getMethod("pokeInt", cls, cls4, cls3);
            cls2.getMethod("peekInt", cls, cls3);
            cls2.getMethod("pokeByte", cls, Byte.TYPE);
            cls2.getMethod("peekByte", cls);
            cls2.getMethod("pokeByteArray", cls, byte[].class, cls4, cls4);
            cls2.getMethod("peekByteArray", cls, byte[].class, cls4, cls4);
            return true;
        } catch (Throwable unused) {
            return false;
        }
    }

    public static byte g(long j4, byte[] bArr) {
        return f14251c.f(f14254f + j4, bArr);
    }

    public static byte h(long j4, Object obj) {
        return (byte) ((f14251c.i((-4) & j4, obj) >>> ((int) (((~j4) & 3) << 3))) & 255);
    }

    public static byte i(long j4, Object obj) {
        return (byte) ((f14251c.i((-4) & j4, obj) >>> ((int) ((j4 & 3) << 3))) & 255);
    }

    public static Unsafe j() {
        try {
            return (Unsafe) AccessController.doPrivileged(new Y0());
        } catch (Throwable unused) {
            return null;
        }
    }

    public static void k(byte[] bArr, long j4, byte b5) {
        f14251c.n(bArr, f14254f + j4, b5);
    }

    public static void l(Object obj, long j4, byte b5) {
        long j6 = (-4) & j4;
        int i6 = f14251c.i(j6, obj);
        int i7 = ((~((int) j4)) & 3) << 3;
        n(((255 & b5) << i7) | (i6 & (~(255 << i7))), j6, obj);
    }

    public static void m(Object obj, long j4, byte b5) {
        long j6 = (-4) & j4;
        int i6 = (((int) j4) & 3) << 3;
        n(((255 & b5) << i6) | (f14251c.i(j6, obj) & (~(255 << i6))), j6, obj);
    }

    public static void n(int i6, long j4, Object obj) {
        f14251c.q(i6, j4, obj);
    }

    public static void o(Object obj, long j4, long j6) {
        f14251c.r(obj, j4, j6);
    }

    public static void p(Object obj, long j4, Object obj2) {
        f14251c.s(obj, j4, obj2);
    }
}
