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

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

/* JADX INFO: loaded from: classes2.dex */
public final class u5 extends b5 {

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public static final boolean f20443i = j7.f20263e;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public xyz.stream.api.a0 f20444d;

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

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

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

    public u5(byte[] bArr, int i10) {
        if (((bArr.length - i10) | i10) < 0) {
            throw new IllegalArgumentException(String.format("Array range is invalid. Buffer.length=%d, offset=%d, length=%d", Integer.valueOf(bArr.length), 0, Integer.valueOf(i10)));
        }
        this.f20445e = bArr;
        this.f20447g = 0;
        this.f20446f = i10;
    }

    public static int A(int i10, int i11) {
        return F(i11) + J(i10 << 3);
    }

    public static int B(int i10) {
        return J(i10 << 3) + 4;
    }

    public static int C(int i10, long j10) {
        return F((j10 >> 63) ^ (j10 << 1)) + J(i10 << 3);
    }

    public static int D(int i10, int i11) {
        return F(i11) + J(i10 << 3);
    }

    public static int E(int i10, long j10) {
        return F(j10) + J(i10 << 3);
    }

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

    public static int G(int i10) {
        return J(i10 << 3) + 4;
    }

    public static int H(int i10) {
        return J(i10 << 3);
    }

    public static int I(int i10, int i11) {
        return J((i11 >> 31) ^ (i11 << 1)) + J(i10 << 3);
    }

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

    public static int K(int i10, int i11) {
        return J(i11) + J(i10 << 3);
    }

    public static int a(int i10) {
        return J(i10 << 3) + 4;
    }

    public static int i(int i10) {
        return J(i10 << 3) + 8;
    }

    public static int k(int i10) {
        return J(i10 << 3) + 1;
    }

    public static int l(int i10, u6 u6Var, d7 d7Var) {
        return ((m5) u6Var).a(d7Var) + (J(i10 << 3) << 1);
    }

    public static int m(int i10, String str) {
        return n(str) + J(i10 << 3);
    }

    public static int n(String str) {
        int length;
        try {
            length = l7.a(str);
        } catch (zzmt unused) {
            length = str.getBytes(d6.f20163a).length;
        }
        return J(length) + length;
    }

    public static int s(int i10) {
        return J(i10 << 3) + 8;
    }

    public static int t(int i10, zzik zzikVar) {
        int iJ = J(i10 << 3);
        int iJ2 = zzikVar.j();
        return J(iJ2) + iJ2 + iJ;
    }

    public static int x(int i10, long j10) {
        return F(j10) + J(i10 << 3);
    }

    public static int z(int i10) {
        return J(i10 << 3) + 8;
    }

    public final void b(byte b10) {
        int i10 = this.f20447g;
        try {
            int i11 = i10 + 1;
            try {
                this.f20445e[i10] = b10;
                this.f20447g = i11;
            } catch (IndexOutOfBoundsException e10) {
                e = e10;
                i10 = i11;
                throw new zzjc$zzb(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(i10), Integer.valueOf(this.f20446f), 1), e);
            }
        } catch (IndexOutOfBoundsException e11) {
            e = e11;
        }
    }

    public final void c(int i10) {
        try {
            byte[] bArr = this.f20445e;
            int i11 = this.f20447g;
            bArr[i11] = (byte) i10;
            bArr[i11 + 1] = (byte) (i10 >> 8);
            bArr[i11 + 2] = (byte) (i10 >> 16);
            this.f20447g = i11 + 4;
            bArr[i11 + 3] = (byte) (i10 >>> 24);
        } catch (IndexOutOfBoundsException e10) {
            throw new zzjc$zzb(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f20447g), Integer.valueOf(this.f20446f), 1), e10);
        }
    }

    public final void d(int i10, int i11) {
        v(i10, 5);
        c(i11);
    }

    public final void e(int i10, long j10) {
        v(i10, 1);
        f(j10);
    }

    public final void f(long j10) {
        try {
            byte[] bArr = this.f20445e;
            int i10 = this.f20447g;
            bArr[i10] = (byte) j10;
            bArr[i10 + 1] = (byte) (j10 >> 8);
            bArr[i10 + 2] = (byte) (j10 >> 16);
            bArr[i10 + 3] = (byte) (j10 >> 24);
            bArr[i10 + 4] = (byte) (j10 >> 32);
            bArr[i10 + 5] = (byte) (j10 >> 40);
            bArr[i10 + 6] = (byte) (j10 >> 48);
            this.f20447g = i10 + 8;
            bArr[i10 + 7] = (byte) (j10 >> 56);
        } catch (IndexOutOfBoundsException e10) {
            throw new zzjc$zzb(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f20447g), Integer.valueOf(this.f20446f), 1), e10);
        }
    }

    public final void g(zzik zzikVar) {
        u(zzikVar.j());
        zziv zzivVar = (zziv) zzikVar;
        w(zzivVar.zzb, zzivVar.k(), zzivVar.j());
    }

    public final void h(String str) {
        int i10 = this.f20447g;
        try {
            int iJ = J(str.length() * 3);
            int iJ2 = J(str.length());
            byte[] bArr = this.f20445e;
            if (iJ2 != iJ) {
                u(l7.a(str));
                this.f20447g = l7.b(str, bArr, this.f20447g, j());
                return;
            }
            int i11 = i10 + iJ2;
            this.f20447g = i11;
            int iB = l7.b(str, bArr, i11, j());
            this.f20447g = i10;
            u((iB - i10) - iJ2);
            this.f20447g = iB;
        } catch (zzmt e10) {
            this.f20447g = i10;
            f20442h.logp(Level.WARNING, "com.google.protobuf.CodedOutputStream", "inefficientWriteStringNoTag", "Converting ill-formed UTF-16. Your Protocol Buffer will not round trip correctly!", (Throwable) e10);
            byte[] bytes = str.getBytes(d6.f20163a);
            try {
                u(bytes.length);
                w(bytes, 0, bytes.length);
            } catch (IndexOutOfBoundsException e11) {
                throw new zzjc$zzb(e11);
            }
        } catch (IndexOutOfBoundsException e12) {
            throw new zzjc$zzb(e12);
        }
    }

    public final int j() {
        return this.f20446f - this.f20447g;
    }

    public final void o(int i10) {
        if (i10 >= 0) {
            u(i10);
        } else {
            r(i10);
        }
    }

    public final void p(int i10, int i11) {
        v(i10, 0);
        o(i11);
    }

    public final void q(int i10, long j10) {
        v(i10, 0);
        r(j10);
    }

    public final void r(long j10) {
        boolean z10 = f20443i;
        byte[] bArr = this.f20445e;
        if (z10 && j() >= 10) {
            while ((j10 & (-128)) != 0) {
                int i10 = this.f20447g;
                this.f20447g = i10 + 1;
                j7.g(bArr, i10, (byte) (((int) j10) | 128));
                j10 >>>= 7;
            }
            int i11 = this.f20447g;
            this.f20447g = i11 + 1;
            j7.g(bArr, i11, (byte) j10);
            return;
        }
        while ((j10 & (-128)) != 0) {
            try {
                int i12 = this.f20447g;
                this.f20447g = i12 + 1;
                bArr[i12] = (byte) (((int) j10) | 128);
                j10 >>>= 7;
            } catch (IndexOutOfBoundsException e10) {
                throw new zzjc$zzb(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f20447g), Integer.valueOf(this.f20446f), 1), e10);
            }
        }
        int i13 = this.f20447g;
        this.f20447g = i13 + 1;
        bArr[i13] = (byte) j10;
    }

    public final void u(int i10) {
        while (true) {
            int i11 = i10 & (-128);
            byte[] bArr = this.f20445e;
            if (i11 == 0) {
                int i12 = this.f20447g;
                this.f20447g = i12 + 1;
                bArr[i12] = (byte) i10;
                return;
            } else {
                try {
                    int i13 = this.f20447g;
                    this.f20447g = i13 + 1;
                    bArr[i13] = (byte) (i10 | 128);
                    i10 >>>= 7;
                } catch (IndexOutOfBoundsException e10) {
                    throw new zzjc$zzb(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f20447g), Integer.valueOf(this.f20446f), 1), e10);
                }
            }
            throw new zzjc$zzb(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f20447g), Integer.valueOf(this.f20446f), 1), e10);
        }
    }

    public final void v(int i10, int i11) {
        u((i10 << 3) | i11);
    }

    public final void w(byte[] bArr, int i10, int i11) throws zzjc$zzb {
        try {
            System.arraycopy(bArr, i10, this.f20445e, this.f20447g, i11);
            this.f20447g += i11;
        } catch (IndexOutOfBoundsException e10) {
            throw new zzjc$zzb(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f20447g), Integer.valueOf(this.f20446f), Integer.valueOf(i11)), e10);
        }
    }

    public final void y(int i10, int i11) {
        v(i10, 0);
        u(i11);
    }
}
