package com.tapjoy.internal; import com.applovin.exoplayer2.common.base.Ascii; import java.io.EOFException; import java.io.IOException; import java.net.ProtocolException; import java.nio.charset.Charset; import kotlin.jvm.internal.ByteCompanionObject; /* loaded from: classes4.dex */ public final class v0 { public final l a; public int d; public int h; public long b = 0; public long c = Long.MAX_VALUE; public int e = 2; public int f = -1; public long g = -1; public v0(l lVar) { this.a = lVar; } public final void b(int i) { while (this.b < this.c && this.a.b != 0) { int b = b(); if (b == 0) { throw new ProtocolException("Unexpected tag 0"); } int i2 = b >> 3; int i3 = b & 7; if (i3 == 0) { this.e = 0; e(); } else if (i3 == 1) { this.e = 1; d(); } else if (i3 == 2) { long b2 = b(); this.b += b2; l lVar = this.a; while (b2 > 0) { if (lVar.a == null) { throw new EOFException(); } int min = (int) Math.min(b2, r5.c - r5.b); long j = min; lVar.b -= j; b2 -= j; b1 b1Var = lVar.a; int i4 = b1Var.b + min; b1Var.b = i4; if (i4 == b1Var.c) { lVar.a = b1Var.a(); c1.a(b1Var); } } } else if (i3 == 3) { b(i2); } else if (i3 == 4) { if (i2 != i) { throw new ProtocolException("Unexpected end group"); } return; } else { if (i3 != 5) { throw new ProtocolException("Unexpected field encoding: " + i3); } this.e = 5; c(); } } throw new EOFException(); } public final int c() { int i = this.e; if (i != 5 && i != 2) { throw new ProtocolException("Expected FIXED32 or LENGTH_DELIMITED but was " + this.e); } l lVar = this.a; if (lVar.b < 4) { throw new EOFException(); } this.b += 4; int b = lVar.b(); Charset charset = f3.a; int i2 = ((b & 255) << 24) | (((-16777216) & b) >>> 24) | ((16711680 & b) >>> 8) | ((65280 & b) << 8); a(5); return i2; } public final long d() { long j; int i = this.e; if (i != 1 && i != 2) { throw new ProtocolException("Expected FIXED64 or LENGTH_DELIMITED but was " + this.e); } l lVar = this.a; long j2 = lVar.b; if (j2 < 8) { throw new EOFException(); } this.b += 8; if (j2 < 8) { throw new IllegalStateException("size < 8: " + lVar.b); } b1 b1Var = lVar.a; int i2 = b1Var.b; int i3 = b1Var.c; if (i3 - i2 < 8) { j = ((lVar.b() & 4294967295L) << 32) | (4294967295L & lVar.b()); } else { byte[] bArr = b1Var.a; int i4 = i2 + 7; long j3 = ((bArr[i2 + 1] & 255) << 48) | ((bArr[i2] & 255) << 56) | ((bArr[i2 + 2] & 255) << 40) | ((bArr[i2 + 3] & 255) << 32) | ((bArr[i2 + 4] & 255) << 24) | ((bArr[i2 + 5] & 255) << 16) | ((bArr[i2 + 6] & 255) << 8); int i5 = i2 + 8; j = j3 | (bArr[i4] & 255); lVar.b = j2 - 8; if (i5 == i3) { lVar.a = b1Var.a(); c1.a(b1Var); } else { b1Var.b = i5; } } long a = f3.a(j); a(1); return a; } public final long e() { int i = this.e; if (i != 0 && i != 2) { throw new ProtocolException("Expected VARINT or LENGTH_DELIMITED but was " + this.e); } long j = 0; for (int i2 = 0; i2 < 64; i2 += 7) { this.b++; j |= (r4 & Byte.MAX_VALUE) << i2; if ((this.a.a() & ByteCompanionObject.MIN_VALUE) == 0) { a(0); return j; } } throw new ProtocolException("WireInput encountered a malformed varint"); } public final void a(int i) { if (this.e == i) { this.e = 6; return; } long j = this.b; long j2 = this.c; if (j > j2) { throw new IOException("Expected to end at " + this.c + " but was " + this.b); } if (j != j2) { this.e = 7; return; } this.c = this.g; this.g = -1L; this.e = 6; } public final long a() { if (this.e != 2) { throw new ProtocolException("Expected LENGTH_DELIMITED but was " + this.e); } long j = this.c; long j2 = j - this.b; if (this.a.b < j2) { throw new EOFException(); } this.e = 6; this.b = j; this.c = this.g; this.g = -1L; return j2; } public final int b() { int i; this.b++; byte a = this.a.a(); if (a >= 0) { return a; } int i2 = a & Byte.MAX_VALUE; this.b++; byte a2 = this.a.a(); if (a2 >= 0) { i = a2 << 7; } else { i2 |= (a2 & Byte.MAX_VALUE) << 7; this.b++; byte a3 = this.a.a(); if (a3 >= 0) { i = a3 << Ascii.SO; } else { i2 |= (a3 & Byte.MAX_VALUE) << 14; this.b++; byte a4 = this.a.a(); if (a4 < 0) { int i3 = i2 | ((a4 & Byte.MAX_VALUE) << 21); this.b++; byte a5 = this.a.a(); int i4 = i3 | (a5 << Ascii.FS); if (a5 >= 0) { return i4; } for (int i5 = 0; i5 < 5; i5++) { this.b++; if (this.a.a() >= 0) { return i4; } } throw new ProtocolException("Malformed VARINT"); } i = a4 << Ascii.NAK; } } return i2 | i; } }