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

import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

/* JADX INFO: loaded from: classes.dex */
public final class T1 extends n4.u0 {

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public C0674n2 f9679v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final byte[] f9680w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final int f9681x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public int f9682y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public static final Logger f9678z = Logger.getLogger(T1.class.getName());

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public static final boolean f9677A = H2.f9602e;

    public T1(int i, byte[] bArr) {
        int length = bArr.length;
        if (((length - i) | i) < 0) {
            Locale locale = Locale.US;
            throw new IllegalArgumentException(I1.a.o("Array range is invalid. Buffer.length=", length, i, ", offset=0, length="));
        }
        this.f9680w = bArr;
        this.f9682y = 0;
        this.f9681x = i;
    }

    public static int C(long j8) {
        return (640 - (Long.numberOfLeadingZeros(j8) * 9)) >>> 6;
    }

    public static int R(String str) {
        int length;
        try {
            length = J2.c(str);
        } catch (I2 unused) {
            length = str.getBytes(AbstractC0644h2.f9868a).length;
        }
        return S(length) + length;
    }

    public static int S(int i) {
        return (352 - (Integer.numberOfLeadingZeros(i) * 9)) >>> 6;
    }

    public final void D(int i, byte[] bArr) throws F0.t {
        try {
            System.arraycopy(bArr, 0, this.f9680w, this.f9682y, i);
            this.f9682y += i;
        } catch (IndexOutOfBoundsException e8) {
            throw new F0.t(this.f9682y, this.f9681x, i, e8);
        }
    }

    public final void E(int i, S1 s12) {
        O((i << 3) | 2);
        O(s12.c());
        D(s12.c(), s12.f9673r);
    }

    public final void F(int i, int i5) {
        O((i << 3) | 5);
        G(i5);
    }

    public final void G(int i) {
        int i5 = this.f9682y;
        try {
            byte[] bArr = this.f9680w;
            bArr[i5] = (byte) i;
            bArr[i5 + 1] = (byte) (i >> 8);
            bArr[i5 + 2] = (byte) (i >> 16);
            bArr[i5 + 3] = (byte) (i >> 24);
            this.f9682y = i5 + 4;
        } catch (IndexOutOfBoundsException e8) {
            throw new F0.t(i5, this.f9681x, 4, e8);
        }
    }

    public final void H(long j8, int i) {
        O((i << 3) | 1);
        I(j8);
    }

    public final void I(long j8) {
        int i = this.f9682y;
        try {
            byte[] bArr = this.f9680w;
            bArr[i] = (byte) j8;
            bArr[i + 1] = (byte) (j8 >> 8);
            bArr[i + 2] = (byte) (j8 >> 16);
            bArr[i + 3] = (byte) (j8 >> 24);
            bArr[i + 4] = (byte) (j8 >> 32);
            bArr[i + 5] = (byte) (j8 >> 40);
            bArr[i + 6] = (byte) (j8 >> 48);
            bArr[i + 7] = (byte) (j8 >> 56);
            this.f9682y = i + 8;
        } catch (IndexOutOfBoundsException e8) {
            throw new F0.t(i, this.f9681x, 8, e8);
        }
    }

    public final void J(int i, int i5) {
        O(i << 3);
        K(i5);
    }

    public final void K(int i) {
        if (i >= 0) {
            O(i);
        } else {
            Q(i);
        }
    }

    public final void L(int i, String str) throws F0.t {
        O((i << 3) | 2);
        int i5 = this.f9682y;
        try {
            int iS = S(str.length() * 3);
            int iS2 = S(str.length());
            byte[] bArr = this.f9680w;
            int i8 = this.f9681x;
            if (iS2 != iS) {
                O(J2.c(str));
                int i9 = this.f9682y;
                this.f9682y = J2.b(str, bArr, i9, i8 - i9);
            } else {
                int i10 = i5 + iS2;
                this.f9682y = i10;
                int iB = J2.b(str, bArr, i10, i8 - i10);
                this.f9682y = i5;
                O((iB - i5) - iS2);
                this.f9682y = iB;
            }
        } catch (I2 e8) {
            this.f9682y = i5;
            f9678z.logp(Level.WARNING, "com.google.protobuf.CodedOutputStream", "inefficientWriteStringNoTag", "Converting ill-formed UTF-16. Your Protocol Buffer will not round trip correctly!", (Throwable) e8);
            byte[] bytes = str.getBytes(AbstractC0644h2.f9868a);
            try {
                int length = bytes.length;
                O(length);
                D(length, bytes);
            } catch (IndexOutOfBoundsException e9) {
                throw new F0.t(e9);
            }
        } catch (IndexOutOfBoundsException e10) {
            throw new F0.t(e10);
        }
    }

    public final void M(int i, int i5) {
        O((i << 3) | i5);
    }

    public final void N(int i, int i5) {
        O(i << 3);
        O(i5);
    }

    public final void O(int i) {
        int i5;
        int i8 = this.f9682y;
        while (true) {
            int i9 = i & (-128);
            byte[] bArr = this.f9680w;
            if (i9 == 0) {
                i5 = i8 + 1;
                bArr[i8] = (byte) i;
                this.f9682y = i5;
                return;
            } else {
                i5 = i8 + 1;
                try {
                    bArr[i8] = (byte) (i | 128);
                    i >>>= 7;
                    i8 = i5;
                } catch (IndexOutOfBoundsException e8) {
                    throw new F0.t(i5, this.f9681x, 1, e8);
                }
            }
            throw new F0.t(i5, this.f9681x, 1, e8);
        }
    }

    public final void P(long j8, int i) {
        O(i << 3);
        Q(j8);
    }

    public final void Q(long j8) {
        int i;
        int i5 = this.f9682y;
        byte[] bArr = this.f9680w;
        boolean z8 = f9677A;
        int i8 = this.f9681x;
        if (!z8 || i8 - i5 < 10) {
            long j9 = j8;
            while ((j9 & (-128)) != 0) {
                i = i5 + 1;
                try {
                    bArr[i5] = (byte) (((int) j9) | 128);
                    j9 >>>= 7;
                    i5 = i;
                } catch (IndexOutOfBoundsException e8) {
                    throw new F0.t(i, i8, 1, e8);
                }
            }
            i = i5 + 1;
            bArr[i5] = (byte) j9;
        } else {
            long j10 = j8;
            while ((j10 & (-128)) != 0) {
                H2.f9600c.d(bArr, H2.f9603f + ((long) i5), (byte) (((int) j10) | 128));
                j10 >>>= 7;
                i5++;
            }
            i = i5 + 1;
            H2.f9600c.d(bArr, H2.f9603f + ((long) i5), (byte) j10);
        }
        this.f9682y = i;
    }
}
