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

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

/* JADX INFO: loaded from: classes2.dex */
public final class t extends com.bumptech.glide.h {

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final boolean f19978f = n1.f19961e;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public u f19979a;

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

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

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

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

    public static int Q(int i10, p pVar, c1 c1Var) {
        int iA = pVar.a(c1Var);
        int iT = T(i10 << 3);
        return iT + iT + iA;
    }

    public static int R(int i10) {
        if (i10 >= 0) {
            return T(i10);
        }
        return 10;
    }

    public static int S(String str) {
        int length;
        try {
            length = o1.c(str);
        } catch (zzgc unused) {
            length = str.getBytes(f0.f19920a).length;
        }
        return T(length) + length;
    }

    public static int T(int i10) {
        if ((i10 & (-128)) == 0) {
            return 1;
        }
        if ((i10 & (-16384)) == 0) {
            return 2;
        }
        if (((-2097152) & i10) == 0) {
            return 3;
        }
        return (i10 & (-268435456)) == 0 ? 4 : 5;
    }

    public static int U(long j10) {
        int i10;
        if (((-128) & j10) == 0) {
            return 1;
        }
        if (j10 < 0) {
            return 10;
        }
        if (((-34359738368L) & j10) != 0) {
            j10 >>>= 28;
            i10 = 6;
        } else {
            i10 = 2;
        }
        if (((-2097152) & j10) != 0) {
            j10 >>>= 14;
            i10 += 2;
        }
        return (j10 & (-16384)) != 0 ? i10 + 1 : i10;
    }

    public final void E(byte b10) {
        try {
            byte[] bArr = this.f19980b;
            int i10 = this.f19982d;
            this.f19982d = i10 + 1;
            bArr[i10] = b10;
        } catch (IndexOutOfBoundsException e10) {
            throw new zzct(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f19982d), Integer.valueOf(this.f19981c), 1), e10);
        }
    }

    public final void F(byte[] bArr, int i10) throws zzct {
        try {
            System.arraycopy(bArr, 0, this.f19980b, this.f19982d, i10);
            this.f19982d += i10;
        } catch (IndexOutOfBoundsException e10) {
            throw new zzct(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f19982d), Integer.valueOf(this.f19981c), Integer.valueOf(i10)), e10);
        }
    }

    public final void G(int i10, zzcn zzcnVar) {
        N((i10 << 3) | 2);
        N(zzcnVar.g());
        zzck zzckVar = (zzck) zzcnVar;
        F(zzckVar.zza, zzckVar.g());
    }

    public final void H(int i10, int i11) {
        N((i10 << 3) | 5);
        I(i11);
    }

    public final void I(int i10) throws zzct {
        try {
            byte[] bArr = this.f19980b;
            int i11 = this.f19982d;
            bArr[i11] = (byte) (i10 & 255);
            bArr[i11 + 1] = (byte) ((i10 >> 8) & 255);
            bArr[i11 + 2] = (byte) ((i10 >> 16) & 255);
            this.f19982d = i11 + 4;
            bArr[i11 + 3] = (byte) ((i10 >> 24) & 255);
        } catch (IndexOutOfBoundsException e10) {
            throw new zzct(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f19982d), Integer.valueOf(this.f19981c), 1), e10);
        }
    }

    public final void J(int i10, long j10) {
        N((i10 << 3) | 1);
        K(j10);
    }

    public final void K(long j10) throws zzct {
        try {
            byte[] bArr = this.f19980b;
            int i10 = this.f19982d;
            bArr[i10] = (byte) (((int) j10) & 255);
            bArr[i10 + 1] = (byte) (((int) (j10 >> 8)) & 255);
            bArr[i10 + 2] = (byte) (((int) (j10 >> 16)) & 255);
            bArr[i10 + 3] = (byte) (((int) (j10 >> 24)) & 255);
            bArr[i10 + 4] = (byte) (((int) (j10 >> 32)) & 255);
            bArr[i10 + 5] = (byte) (((int) (j10 >> 40)) & 255);
            bArr[i10 + 6] = (byte) (((int) (j10 >> 48)) & 255);
            this.f19982d = i10 + 8;
            bArr[i10 + 7] = (byte) (((int) (j10 >> 56)) & 255);
        } catch (IndexOutOfBoundsException e10) {
            throw new zzct(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f19982d), Integer.valueOf(this.f19981c), 1), e10);
        }
    }

    public final void L(int i10, String str) throws zzct {
        N((i10 << 3) | 2);
        int i11 = this.f19982d;
        try {
            int iT = T(str.length() * 3);
            int iT2 = T(str.length());
            int i12 = this.f19981c;
            byte[] bArr = this.f19980b;
            if (iT2 == iT) {
                int i13 = i11 + iT2;
                this.f19982d = i13;
                int iB = o1.b(str, bArr, i13, i12 - i13);
                this.f19982d = i11;
                N((iB - i11) - iT2);
                this.f19982d = iB;
            } else {
                N(o1.c(str));
                int i14 = this.f19982d;
                this.f19982d = o1.b(str, bArr, i14, i12 - i14);
            }
        } catch (zzgc e10) {
            this.f19982d = i11;
            f19977e.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(f0.f19920a);
            try {
                int length = bytes.length;
                N(length);
                F(bytes, length);
            } catch (IndexOutOfBoundsException e11) {
                throw new zzct(e11);
            }
        } catch (IndexOutOfBoundsException e12) {
            throw new zzct(e12);
        }
    }

    public final void M(int i10, int i11) {
        N((i10 << 3) | i11);
    }

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

    public final void O(int i10, long j10) {
        N(i10 << 3);
        P(j10);
    }

    public final void P(long j10) {
        boolean z10 = f19978f;
        int i10 = this.f19981c;
        byte[] bArr = this.f19980b;
        if (!z10 || i10 - this.f19982d < 10) {
            while ((j10 & (-128)) != 0) {
                try {
                    int i11 = this.f19982d;
                    this.f19982d = i11 + 1;
                    bArr[i11] = (byte) ((((int) j10) & 127) | 128);
                    j10 >>>= 7;
                } catch (IndexOutOfBoundsException e10) {
                    throw new zzct(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f19982d), Integer.valueOf(i10), 1), e10);
                }
            }
            int i12 = this.f19982d;
            this.f19982d = i12 + 1;
            bArr[i12] = (byte) j10;
            return;
        }
        while ((j10 & (-128)) != 0) {
            int i13 = this.f19982d;
            this.f19982d = i13 + 1;
            n1.f19959c.d(bArr, n1.f19962f + ((long) i13), (byte) ((((int) j10) & 127) | 128));
            j10 >>>= 7;
        }
        int i14 = this.f19982d;
        this.f19982d = i14 + 1;
        n1.f19959c.d(bArr, n1.f19962f + ((long) i14), (byte) j10);
    }
}
