package com.google.android.gms.internal.vision; import com.google.common.base.Ascii; import com.google.common.primitives.UnsignedBytes; import java.io.IOException; import java.util.Arrays; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public final class zzfb extends zzez { private final byte[] buffer; private int limit; private int pos; private final boolean zzsk; private int zzsl; private int zzsm; private int zzsn; private int zzso; private zzfb(byte[] bArr, int i, int i2, boolean z) { super(); this.zzso = Integer.MAX_VALUE; this.buffer = bArr; this.limit = i2 + i; this.pos = i; this.zzsm = i; this.zzsk = z; } @Override // com.google.android.gms.internal.vision.zzez public final int zzdq() throws IOException { if (zzcm()) { this.zzsn = 0; return 0; } int zzdt = zzdt(); this.zzsn = zzdt; if ((zzdt >>> 3) != 0) { return zzdt; } throw zzgf.zzfk(); } @Override // com.google.android.gms.internal.vision.zzez public final void zzak(int i) throws zzgf { if (this.zzsn != i) { throw zzgf.zzfl(); } } @Override // com.google.android.gms.internal.vision.zzez public final boolean zzal(int i) throws IOException { int zzdq; int i2 = i & 7; int i3 = 0; if (i2 == 0) { if (this.limit - this.pos >= 10) { while (i3 < 10) { byte[] bArr = this.buffer; int i4 = this.pos; this.pos = i4 + 1; if (bArr[i4] < 0) { i3++; } } throw zzgf.zzfj(); } while (i3 < 10) { if (zzdy() < 0) { i3++; } } throw zzgf.zzfj(); return true; } if (i2 == 1) { zzap(8); return true; } if (i2 == 2) { zzap(zzdt()); return true; } if (i2 != 3) { if (i2 == 4) { return false; } if (i2 == 5) { zzap(4); return true; } throw zzgf.zzfm(); } do { zzdq = zzdq(); if (zzdq == 0) { break; } } while (zzal(zzdq)); zzak(((i >>> 3) << 3) | 4); return true; } @Override // com.google.android.gms.internal.vision.zzez public final double readDouble() throws IOException { return Double.longBitsToDouble(zzdw()); } @Override // com.google.android.gms.internal.vision.zzez public final float readFloat() throws IOException { return Float.intBitsToFloat(zzdv()); } @Override // com.google.android.gms.internal.vision.zzez public final long zzcp() throws IOException { return zzdu(); } @Override // com.google.android.gms.internal.vision.zzez public final long zzcq() throws IOException { return zzdu(); } @Override // com.google.android.gms.internal.vision.zzez public final int zzcr() throws IOException { return zzdt(); } @Override // com.google.android.gms.internal.vision.zzez public final long zzcs() throws IOException { return zzdw(); } @Override // com.google.android.gms.internal.vision.zzez public final int zzct() throws IOException { return zzdv(); } @Override // com.google.android.gms.internal.vision.zzez public final boolean zzcu() throws IOException { return zzdu() != 0; } @Override // com.google.android.gms.internal.vision.zzez public final String readString() throws IOException { int zzdt = zzdt(); if (zzdt > 0) { int i = this.limit; int i2 = this.pos; if (zzdt <= i - i2) { String str = new String(this.buffer, i2, zzdt, zzga.UTF_8); this.pos += zzdt; return str; } } if (zzdt == 0) { return ""; } if (zzdt < 0) { throw zzgf.zzfi(); } throw zzgf.zzfh(); } @Override // com.google.android.gms.internal.vision.zzez public final String zzcv() throws IOException { int zzdt = zzdt(); if (zzdt > 0) { int i = this.limit; int i2 = this.pos; if (zzdt <= i - i2) { String zzi = zziw.zzi(this.buffer, i2, zzdt); this.pos += zzdt; return zzi; } } if (zzdt == 0) { return ""; } if (zzdt <= 0) { throw zzgf.zzfi(); } throw zzgf.zzfh(); } @Override // com.google.android.gms.internal.vision.zzez public final T zza(zzhq zzhqVar, zzfk zzfkVar) throws IOException { int zzdt = zzdt(); if (this.zzsf >= this.zzsg) { throw zzgf.zzfn(); } int zzan = zzan(zzdt); this.zzsf++; T zza = zzhqVar.zza(this, zzfkVar); zzak(0); this.zzsf--; zzao(zzan); return zza; } @Override // com.google.android.gms.internal.vision.zzez public final zzeo zzcw() throws IOException { byte[] bArr; int zzdt = zzdt(); if (zzdt > 0) { int i = this.limit; int i2 = this.pos; if (zzdt <= i - i2) { zzeo zzb = zzeo.zzb(this.buffer, i2, zzdt); this.pos += zzdt; return zzb; } } if (zzdt == 0) { return zzeo.zzrx; } if (zzdt > 0) { int i3 = this.limit; int i4 = this.pos; if (zzdt <= i3 - i4) { int i5 = zzdt + i4; this.pos = i5; bArr = Arrays.copyOfRange(this.buffer, i4, i5); return zzeo.zze(bArr); } } if (zzdt > 0) { throw zzgf.zzfh(); } if (zzdt == 0) { bArr = zzga.zzxn; return zzeo.zze(bArr); } throw zzgf.zzfi(); } @Override // com.google.android.gms.internal.vision.zzez public final int zzcx() throws IOException { return zzdt(); } @Override // com.google.android.gms.internal.vision.zzez public final int zzcy() throws IOException { return zzdt(); } @Override // com.google.android.gms.internal.vision.zzez public final int zzcz() throws IOException { return zzdv(); } @Override // com.google.android.gms.internal.vision.zzez public final long zzda() throws IOException { return zzdw(); } @Override // com.google.android.gms.internal.vision.zzez public final int zzdb() throws IOException { return zzaq(zzdt()); } @Override // com.google.android.gms.internal.vision.zzez public final long zzdc() throws IOException { return zzd(zzdu()); } private final int zzdt() throws IOException { int i; int i2 = this.pos; int i3 = this.limit; if (i3 != i2) { byte[] bArr = this.buffer; int i4 = i2 + 1; byte b = bArr[i2]; if (b >= 0) { this.pos = i4; return b; } if (i3 - i4 >= 9) { int i5 = i2 + 2; int i6 = (bArr[i4] << 7) ^ b; if (i6 < 0) { i = i6 ^ (-128); } else { int i7 = i2 + 3; int i8 = (bArr[i5] << 14) ^ i6; if (i8 >= 0) { i = i8 ^ 16256; } else { int i9 = i2 + 4; int i10 = i8 ^ (bArr[i7] << Ascii.NAK); if (i10 < 0) { i = (-2080896) ^ i10; } else { i7 = i2 + 5; byte b2 = bArr[i9]; int i11 = (i10 ^ (b2 << 28)) ^ 266354560; if (b2 < 0) { i9 = i2 + 6; if (bArr[i7] < 0) { i7 = i2 + 7; if (bArr[i9] < 0) { i9 = i2 + 8; if (bArr[i7] < 0) { i7 = i2 + 9; if (bArr[i9] < 0) { if (bArr[i7] >= 0) { i5 = i2 + 10; i = i11; } } } } } i = i11; } i = i11; } i5 = i9; } i5 = i7; } this.pos = i5; return i; } } return (int) zzdr(); } private final long zzdu() throws IOException { long j; long j2; long j3; int i = this.pos; int i2 = this.limit; if (i2 != i) { byte[] bArr = this.buffer; int i3 = i + 1; byte b = bArr[i]; if (b >= 0) { this.pos = i3; return b; } if (i2 - i3 >= 9) { int i4 = i + 2; int i5 = (bArr[i3] << 7) ^ b; if (i5 < 0) { j = i5 ^ (-128); } else { int i6 = i + 3; int i7 = (bArr[i4] << 14) ^ i5; if (i7 >= 0) { j = i7 ^ 16256; i4 = i6; } else { int i8 = i + 4; int i9 = i7 ^ (bArr[i6] << Ascii.NAK); if (i9 < 0) { long j4 = (-2080896) ^ i9; i4 = i8; j = j4; } else { long j5 = i9; i4 = i + 5; long j6 = j5 ^ (bArr[i8] << 28); if (j6 >= 0) { j3 = 266354560; } else { int i10 = i + 6; long j7 = j6 ^ (bArr[i4] << 35); if (j7 < 0) { j2 = -34093383808L; } else { i4 = i + 7; j6 = j7 ^ (bArr[i10] << 42); if (j6 >= 0) { j3 = 4363953127296L; } else { i10 = i + 8; j7 = j6 ^ (bArr[i4] << 49); if (j7 < 0) { j2 = -558586000294016L; } else { i4 = i + 9; long j8 = (j7 ^ (bArr[i10] << 56)) ^ 71499008037633920L; if (j8 < 0) { if (bArr[i4] >= 0) { i4 = i + 10; } } j = j8; } } } j = j7 ^ j2; i4 = i10; } j = j6 ^ j3; } } } this.pos = i4; return j; } } return zzdr(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.android.gms.internal.vision.zzez public final long zzdr() throws IOException { long j = 0; for (int i = 0; i < 64; i += 7) { j |= (r3 & Ascii.DEL) << i; if ((zzdy() & 128) == 0) { return j; } } throw zzgf.zzfj(); } private final int zzdv() throws IOException { int i = this.pos; if (this.limit - i < 4) { throw zzgf.zzfh(); } byte[] bArr = this.buffer; this.pos = i + 4; return ((bArr[i + 3] & UnsignedBytes.MAX_VALUE) << 24) | (bArr[i] & UnsignedBytes.MAX_VALUE) | ((bArr[i + 1] & UnsignedBytes.MAX_VALUE) << 8) | ((bArr[i + 2] & UnsignedBytes.MAX_VALUE) << 16); } private final long zzdw() throws IOException { int i = this.pos; if (this.limit - i < 8) { throw zzgf.zzfh(); } byte[] bArr = this.buffer; this.pos = i + 8; return ((bArr[i + 7] & 255) << 56) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16) | ((bArr[i + 3] & 255) << 24) | ((bArr[i + 4] & 255) << 32) | ((bArr[i + 5] & 255) << 40) | ((bArr[i + 6] & 255) << 48); } @Override // com.google.android.gms.internal.vision.zzez public final int zzan(int i) throws zzgf { if (i < 0) { throw zzgf.zzfi(); } int zzds = i + zzds(); int i2 = this.zzso; if (zzds > i2) { throw zzgf.zzfh(); } this.zzso = zzds; zzdx(); return i2; } @Override // com.google.android.gms.internal.vision.zzez public final void zzao(int i) { this.zzso = i; zzdx(); } private final byte zzdy() throws IOException { int i = this.pos; if (i == this.limit) { throw zzgf.zzfh(); } byte[] bArr = this.buffer; this.pos = i + 1; return bArr[i]; } @Override // com.google.android.gms.internal.vision.zzez public final void zzap(int i) throws IOException { if (i >= 0) { int i2 = this.limit; int i3 = this.pos; if (i <= i2 - i3) { this.pos = i3 + i; return; } } if (i < 0) { throw zzgf.zzfi(); } throw zzgf.zzfh(); } @Override // com.google.android.gms.internal.vision.zzez public final int zzds() { return this.pos - this.zzsm; } @Override // com.google.android.gms.internal.vision.zzez public final boolean zzcm() throws IOException { return this.pos == this.limit; } private final void zzdx() { int i = this.limit + this.zzsl; this.limit = i; int i2 = i - this.zzsm; int i3 = this.zzso; if (i2 <= i3) { this.zzsl = 0; return; } int i4 = i2 - i3; this.zzsl = i4; this.limit = i - i4; } }