package com.google.android.gms.internal.gtm; 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 zzqg extends zzqe { private final byte[] buffer; private int limit; private int pos; private final boolean zzawk; private int zzawl; private int zzawm; private int zzawn; private int zzawo; private zzqg(byte[] bArr, int i, int i2, boolean z) { super(); this.zzawo = Integer.MAX_VALUE; this.buffer = bArr; this.limit = i2 + i; this.pos = i; this.zzawm = i; this.zzawk = z; } @Override // com.google.android.gms.internal.gtm.zzqe public final int zzni() throws IOException { if (zzny()) { this.zzawn = 0; return 0; } int zzoa = zzoa(); this.zzawn = zzoa; if ((zzoa >>> 3) != 0) { return zzoa; } throw new zzrk("Protocol message contained an invalid tag (zero)."); } @Override // com.google.android.gms.internal.gtm.zzqe public final void zzan(int i) throws zzrk { if (this.zzawn != i) { throw zzrk.zzps(); } } @Override // com.google.android.gms.internal.gtm.zzqe public final boolean zzao(int i) throws IOException { int zzni; 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 zzrk.zzpr(); } while (i3 < 10) { if (zzof() < 0) { i3++; } } throw zzrk.zzpr(); return true; } if (i2 == 1) { zzas(8); return true; } if (i2 == 2) { zzas(zzoa()); return true; } if (i2 != 3) { if (i2 == 4) { return false; } if (i2 == 5) { zzas(4); return true; } throw zzrk.zzpt(); } do { zzni = zzni(); if (zzni == 0) { break; } } while (zzao(zzni)); zzan(((i >>> 3) << 3) | 4); return true; } @Override // com.google.android.gms.internal.gtm.zzqe public final double readDouble() throws IOException { return Double.longBitsToDouble(zzod()); } @Override // com.google.android.gms.internal.gtm.zzqe public final float readFloat() throws IOException { return Float.intBitsToFloat(zzoc()); } @Override // com.google.android.gms.internal.gtm.zzqe public final long zznj() throws IOException { return zzob(); } @Override // com.google.android.gms.internal.gtm.zzqe public final long zznk() throws IOException { return zzob(); } @Override // com.google.android.gms.internal.gtm.zzqe public final int zznl() throws IOException { return zzoa(); } @Override // com.google.android.gms.internal.gtm.zzqe public final long zznm() throws IOException { return zzod(); } @Override // com.google.android.gms.internal.gtm.zzqe public final int zznn() throws IOException { return zzoc(); } @Override // com.google.android.gms.internal.gtm.zzqe public final boolean zzno() throws IOException { return zzob() != 0; } @Override // com.google.android.gms.internal.gtm.zzqe public final String readString() throws IOException { int zzoa = zzoa(); if (zzoa > 0) { int i = this.limit; int i2 = this.pos; if (zzoa <= i - i2) { String str = new String(this.buffer, i2, zzoa, zzre.UTF_8); this.pos += zzoa; return str; } } if (zzoa == 0) { return ""; } if (zzoa < 0) { throw zzrk.zzpq(); } throw zzrk.zzpp(); } @Override // com.google.android.gms.internal.gtm.zzqe public final String zznp() throws IOException { int zzoa = zzoa(); if (zzoa > 0) { int i = this.limit; int i2 = this.pos; if (zzoa <= i - i2) { String zzh = zztz.zzh(this.buffer, i2, zzoa); this.pos += zzoa; return zzh; } } if (zzoa == 0) { return ""; } if (zzoa <= 0) { throw zzrk.zzpq(); } throw zzrk.zzpp(); } @Override // com.google.android.gms.internal.gtm.zzqe public final T zza(zzsu zzsuVar, zzqp zzqpVar) throws IOException { int zzoa = zzoa(); if (this.zzawf >= this.zzawg) { throw zzrk.zzpu(); } int zzaq = zzaq(zzoa); this.zzawf++; T zza = zzsuVar.zza(this, zzqpVar); zzan(0); this.zzawf--; zzar(zzaq); return zza; } @Override // com.google.android.gms.internal.gtm.zzqe public final zzps zznq() throws IOException { byte[] bArr; int zzoa = zzoa(); if (zzoa > 0) { int i = this.limit; int i2 = this.pos; if (zzoa <= i - i2) { zzps zzb = zzps.zzb(this.buffer, i2, zzoa); this.pos += zzoa; return zzb; } } if (zzoa == 0) { return zzps.zzavx; } if (zzoa > 0) { int i3 = this.limit; int i4 = this.pos; if (zzoa <= i3 - i4) { int i5 = zzoa + i4; this.pos = i5; bArr = Arrays.copyOfRange(this.buffer, i4, i5); return zzps.zzf(bArr); } } if (zzoa > 0) { throw zzrk.zzpp(); } if (zzoa == 0) { bArr = zzre.zzbbh; return zzps.zzf(bArr); } throw zzrk.zzpq(); } @Override // com.google.android.gms.internal.gtm.zzqe public final int zznr() throws IOException { return zzoa(); } @Override // com.google.android.gms.internal.gtm.zzqe public final int zzns() throws IOException { return zzoa(); } @Override // com.google.android.gms.internal.gtm.zzqe public final int zznt() throws IOException { return zzoc(); } @Override // com.google.android.gms.internal.gtm.zzqe public final long zznu() throws IOException { return zzod(); } @Override // com.google.android.gms.internal.gtm.zzqe public final int zznv() throws IOException { int zzoa = zzoa(); return (zzoa >>> 1) ^ (-(zzoa & 1)); } @Override // com.google.android.gms.internal.gtm.zzqe public final long zznw() throws IOException { long zzob = zzob(); return (zzob >>> 1) ^ (-(1 & zzob)); } private final int zzoa() 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) zznx(); } private final long zzob() 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 zznx(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.android.gms.internal.gtm.zzqe public final long zznx() throws IOException { long j = 0; for (int i = 0; i < 64; i += 7) { j |= (r3 & Ascii.DEL) << i; if ((zzof() & 128) == 0) { return j; } } throw zzrk.zzpr(); } private final int zzoc() throws IOException { int i = this.pos; if (this.limit - i < 4) { throw zzrk.zzpp(); } 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 zzod() throws IOException { int i = this.pos; if (this.limit - i < 8) { throw zzrk.zzpp(); } 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.gtm.zzqe public final int zzaq(int i) throws zzrk { if (i < 0) { throw zzrk.zzpq(); } int zznz = i + zznz(); int i2 = this.zzawo; if (zznz > i2) { throw zzrk.zzpp(); } this.zzawo = zznz; zzoe(); return i2; } @Override // com.google.android.gms.internal.gtm.zzqe public final void zzar(int i) { this.zzawo = i; zzoe(); } private final byte zzof() throws IOException { int i = this.pos; if (i == this.limit) { throw zzrk.zzpp(); } byte[] bArr = this.buffer; this.pos = i + 1; return bArr[i]; } @Override // com.google.android.gms.internal.gtm.zzqe public final void zzas(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 zzrk.zzpq(); } throw zzrk.zzpp(); } @Override // com.google.android.gms.internal.gtm.zzqe public final int zznz() { return this.pos - this.zzawm; } @Override // com.google.android.gms.internal.gtm.zzqe public final boolean zzny() throws IOException { return this.pos == this.limit; } private final void zzoe() { int i = this.limit + this.zzawl; this.limit = i; int i2 = i - this.zzawm; int i3 = this.zzawo; if (i2 <= i3) { this.zzawl = 0; return; } int i4 = i2 - i3; this.zzawl = i4; this.limit = i - i4; } }