package C;

/* JADX INFO: loaded from: classes.dex */
final class f {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final long[] f202d = {128, 64, 32, 16, 8, 4, 2, 1};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final byte[] f203a = new byte[8];

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private int f204b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private int f205c;

    public static long a(byte[] bArr, int i2, boolean z2) {
        long j2 = ((long) bArr[0]) & 255;
        if (z2) {
            j2 &= ~f202d[i2 - 1];
        }
        for (int i3 = 1; i3 < i2; i3++) {
            j2 = (j2 << 8) | (((long) bArr[i3]) & 255);
        }
        return j2;
    }

    public static int c(int i2) {
        int i3 = 0;
        while (true) {
            long[] jArr = f202d;
            if (i3 >= jArr.length) {
                return -1;
            }
            if ((jArr[i3] & ((long) i2)) != 0) {
                return i3 + 1;
            }
            i3++;
        }
    }

    public int b() {
        return this.f205c;
    }

    public long d(v.f fVar, boolean z2, boolean z3, int i2) {
        if (this.f204b == 0) {
            if (!fVar.a(this.f203a, 0, 1, z2)) {
                return -1L;
            }
            int iC = c(this.f203a[0] & 255);
            this.f205c = iC;
            if (iC == -1) {
                throw new IllegalStateException("No valid varint length mask found");
            }
            this.f204b = 1;
        }
        int i3 = this.f205c;
        if (i3 > i2) {
            this.f204b = 0;
            return -2L;
        }
        if (i3 != 1) {
            fVar.readFully(this.f203a, 1, i3 - 1);
        }
        this.f204b = 0;
        return a(this.f203a, this.f205c, z3);
    }

    public void e() {
        this.f204b = 0;
        this.f205c = 0;
    }
}
