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

import java.util.Locale;

/* JADX INFO: loaded from: classes2.dex */
public final class oa2 extends qa2 {

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

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

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

    public oa2(byte[] bArr, int i10) {
        int length = bArr.length;
        if (((length - i10) | i10) < 0) {
            throw new IllegalArgumentException(String.format(Locale.US, "Array range is invalid. Buffer.length=%d, offset=%d, length=%d", Integer.valueOf(length), 0, Integer.valueOf(i10)));
        }
        this.f14989d = bArr;
        this.f14991f = 0;
        this.f14990e = i10;
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void C(int i10, int i11) throws zziau {
        R((i10 << 3) | i11);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void D(int i10, int i11) throws zziau {
        R(i10 << 3);
        Q(i11);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void E(int i10, int i11) throws zziau {
        R(i10 << 3);
        R(i11);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void F(int i10, int i11) throws zziau {
        R((i10 << 3) | 5);
        S(i11);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void G(int i10, long j10) throws zziau {
        R(i10 << 3);
        T(j10);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final int H() {
        return this.f14990e - this.f14991f;
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void I(int i10, long j10) throws zziau {
        R((i10 << 3) | 1);
        U(j10);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void J(int i10, boolean z10) throws zziau {
        R(i10 << 3);
        P(z10 ? (byte) 1 : (byte) 0);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void K(int i10, String str) throws zziau {
        R((i10 << 3) | 2);
        V(str);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void L(int i10, zzian zzianVar) throws zziau {
        R((i10 << 3) | 2);
        M(zzianVar);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void M(zzian zzianVar) throws zziau {
        R(zzianVar.j());
        zzianVar.o(this);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void N(int i10, byte[] bArr) throws zziau {
        R(i10);
        W(0, i10, bArr);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void O(wb2 wb2Var) throws zziau {
        R(((cb2) wb2Var).d(null));
        ((cb2) wb2Var).w(this);
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void P(byte b10) throws zziau {
        IndexOutOfBoundsException indexOutOfBoundsException;
        int i10 = this.f14991f;
        try {
            int i11 = i10 + 1;
            try {
                this.f14989d[i10] = b10;
                this.f14991f = i11;
            } catch (IndexOutOfBoundsException e10) {
                indexOutOfBoundsException = e10;
                i10 = i11;
                throw new zziau(i10, this.f14990e, 1, indexOutOfBoundsException);
            }
        } catch (IndexOutOfBoundsException e11) {
            indexOutOfBoundsException = e11;
        }
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void Q(int i10) throws zziau {
        if (i10 >= 0) {
            R(i10);
        } else {
            T(i10);
        }
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void R(int i10) throws zziau {
        int i11;
        int i12 = this.f14991f;
        while (true) {
            int i13 = i10 & (-128);
            byte[] bArr = this.f14989d;
            if (i13 == 0) {
                i11 = i12 + 1;
                bArr[i12] = (byte) i10;
                this.f14991f = i11;
                return;
            } else {
                i11 = i12 + 1;
                try {
                    bArr[i12] = (byte) (i10 | 128);
                    i10 >>>= 7;
                    i12 = i11;
                } catch (IndexOutOfBoundsException e10) {
                    throw new zziau(i11, this.f14990e, 1, e10);
                }
            }
            throw new zziau(i11, this.f14990e, 1, e10);
        }
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void S(int i10) throws zziau {
        int i11 = this.f14991f;
        try {
            byte[] bArr = this.f14989d;
            bArr[i11] = (byte) i10;
            bArr[i11 + 1] = (byte) (i10 >> 8);
            bArr[i11 + 2] = (byte) (i10 >> 16);
            bArr[i11 + 3] = (byte) (i10 >> 24);
            this.f14991f = i11 + 4;
        } catch (IndexOutOfBoundsException e10) {
            throw new zziau(i11, this.f14990e, 4, e10);
        }
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void T(long j10) throws zziau {
        int i10;
        int i11 = this.f14991f;
        boolean z10 = qa2.f15673c;
        int i12 = this.f14990e;
        byte[] bArr = this.f14989d;
        if (!z10 || i12 - i11 < 10) {
            long j11 = j10;
            while ((j11 & (-128)) != 0) {
                i10 = i11 + 1;
                try {
                    bArr[i11] = (byte) (((int) j11) | 128);
                    j11 >>>= 7;
                    i11 = i10;
                } catch (IndexOutOfBoundsException e10) {
                    throw new zziau(i10, i12, 1, e10);
                }
            }
            i10 = i11 + 1;
            bArr[i11] = (byte) j11;
        } else {
            long j12 = j10;
            while ((j12 & (-128)) != 0) {
                sc2.r(bArr, i11, (byte) (((int) j12) | 128));
                j12 >>>= 7;
                i11++;
            }
            i10 = i11 + 1;
            sc2.r(bArr, i11, (byte) j12);
        }
        this.f14991f = i10;
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void U(long j10) throws zziau {
        int i10 = this.f14991f;
        try {
            byte[] bArr = this.f14989d;
            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);
            bArr[i10 + 7] = (byte) (j10 >> 56);
            this.f14991f = i10 + 8;
        } catch (IndexOutOfBoundsException e10) {
            throw new zziau(i10, this.f14990e, 8, e10);
        }
    }

    @Override // com.google.android.gms.internal.ads.qa2
    public final void V(String str) throws zziau {
        int i10 = this.f14991f;
        try {
            int iZ = qa2.z(str.length() * 3);
            int iZ2 = qa2.z(str.length());
            int i11 = this.f14990e;
            byte[] bArr = this.f14989d;
            if (iZ2 != iZ) {
                R(tc2.b(str));
                int i12 = this.f14991f;
                this.f14991f = tc2.c(str, bArr, i12, i11 - i12);
            } else {
                int i13 = i10 + iZ2;
                this.f14991f = i13;
                int iC = tc2.c(str, bArr, i13, i11 - i13);
                this.f14991f = i10;
                R((iC - i10) - iZ2);
                this.f14991f = iC;
            }
        } catch (IndexOutOfBoundsException e10) {
            throw new zziau(e10);
        }
    }

    public final void W(int i10, int i11, byte[] bArr) throws zziau {
        try {
            System.arraycopy(bArr, i10, this.f14989d, this.f14991f, i11);
            this.f14991f += i11;
        } catch (IndexOutOfBoundsException e10) {
            throw new zziau(this.f14991f, this.f14990e, i11, e10);
        }
    }

    @Override // com.google.android.gms.internal.ads.rb
    public final void k(int i10, int i11, byte[] bArr) throws zziau {
        W(i10, i11, bArr);
    }
}
