package t9; import com.google.android.gms.common.api.Api; import java.io.Closeable; import java.io.EOFException; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import t9.d; import x9.v; import x9.w; /* loaded from: classes2.dex */ final class h implements Closeable { /* renamed from: e, reason: collision with root package name */ static final Logger f14582e = Logger.getLogger(e.class.getName()); /* renamed from: a, reason: collision with root package name */ private final x9.e f14583a; /* renamed from: b, reason: collision with root package name */ private final a f14584b; /* renamed from: c, reason: collision with root package name */ private final boolean f14585c; /* renamed from: d, reason: collision with root package name */ final d.a f14586d; static final class a implements v { /* renamed from: a, reason: collision with root package name */ private final x9.e f14587a; /* renamed from: b, reason: collision with root package name */ int f14588b; /* renamed from: c, reason: collision with root package name */ byte f14589c; /* renamed from: d, reason: collision with root package name */ int f14590d; /* renamed from: e, reason: collision with root package name */ int f14591e; /* renamed from: f, reason: collision with root package name */ short f14592f; a(x9.e eVar) { this.f14587a = eVar; } private void c() { int i10 = this.f14590d; int S = h.S(this.f14587a); this.f14591e = S; this.f14588b = S; byte readByte = (byte) (this.f14587a.readByte() & 255); this.f14589c = (byte) (this.f14587a.readByte() & 255); Logger logger = h.f14582e; if (logger.isLoggable(Level.FINE)) { logger.fine(e.b(true, this.f14590d, this.f14588b, readByte, this.f14589c)); } int readInt = this.f14587a.readInt() & Api.BaseClientBuilder.API_PRIORITY_OTHER; this.f14590d = readInt; if (readByte != 9) { throw e.d("%s != TYPE_CONTINUATION", Byte.valueOf(readByte)); } if (readInt != i10) { throw e.d("TYPE_CONTINUATION streamId changed", new Object[0]); } } @Override // x9.v public w b() { return this.f14587a.b(); } @Override // x9.v, java.io.Closeable, java.lang.AutoCloseable public void close() { } @Override // x9.v public long s0(x9.c cVar, long j10) { while (true) { int i10 = this.f14591e; if (i10 != 0) { long s02 = this.f14587a.s0(cVar, Math.min(j10, i10)); if (s02 == -1) { return -1L; } this.f14591e = (int) (this.f14591e - s02); return s02; } this.f14587a.skip(this.f14592f); this.f14592f = (short) 0; if ((this.f14589c & 4) != 0) { return -1L; } c(); } } } interface b { void a(); void b(boolean z10, int i10, int i11, List list); void c(int i10, long j10); void d(boolean z10, m mVar); void e(boolean z10, int i10, int i11); void f(int i10, int i11, int i12, boolean z10); void g(boolean z10, int i10, x9.e eVar, int i11); void h(int i10, t9.b bVar); void i(int i10, int i11, List list); void j(int i10, t9.b bVar, x9.f fVar); } h(x9.e eVar, boolean z10) { this.f14583a = eVar; this.f14585c = z10; a aVar = new a(eVar); this.f14584b = aVar; this.f14586d = new d.a(4096, aVar); } private void I(b bVar, int i10, byte b10, int i11) { if (i11 == 0) { throw e.d("PROTOCOL_ERROR: TYPE_DATA streamId == 0", new Object[0]); } boolean z10 = (b10 & 1) != 0; if ((b10 & 32) != 0) { throw e.d("PROTOCOL_ERROR: FLAG_COMPRESSED without SETTINGS_COMPRESS_DATA", new Object[0]); } short readByte = (b10 & 8) != 0 ? (short) (this.f14583a.readByte() & 255) : (short) 0; bVar.g(z10, i11, this.f14583a, c(i10, b10, readByte)); this.f14583a.skip(readByte); } private void O(b bVar, int i10, byte b10, int i11) { if (i10 < 8) { throw e.d("TYPE_GOAWAY length < 8: %s", Integer.valueOf(i10)); } if (i11 != 0) { throw e.d("TYPE_GOAWAY streamId != 0", new Object[0]); } int readInt = this.f14583a.readInt(); int readInt2 = this.f14583a.readInt(); int i12 = i10 - 8; t9.b a10 = t9.b.a(readInt2); if (a10 == null) { throw e.d("TYPE_GOAWAY unexpected error code: %d", Integer.valueOf(readInt2)); } x9.f fVar = x9.f.f15470e; if (i12 > 0) { fVar = this.f14583a.d(i12); } bVar.j(readInt, a10, fVar); } private List P(int i10, short s10, byte b10, int i11) { a aVar = this.f14584b; aVar.f14591e = i10; aVar.f14588b = i10; aVar.f14592f = s10; aVar.f14589c = b10; aVar.f14590d = i11; this.f14586d.k(); return this.f14586d.e(); } private void R(b bVar, int i10, byte b10, int i11) { if (i11 == 0) { throw e.d("PROTOCOL_ERROR: TYPE_HEADERS streamId == 0", new Object[0]); } boolean z10 = (b10 & 1) != 0; short readByte = (b10 & 8) != 0 ? (short) (this.f14583a.readByte() & 255) : (short) 0; if ((b10 & 32) != 0) { a0(bVar, i11); i10 -= 5; } bVar.b(z10, i11, -1, P(c(i10, b10, readByte), readByte, b10, i11)); } static int S(x9.e eVar) { return (eVar.readByte() & 255) | ((eVar.readByte() & 255) << 16) | ((eVar.readByte() & 255) << 8); } private void Y(b bVar, int i10, byte b10, int i11) { if (i10 != 8) { throw e.d("TYPE_PING length != 8: %s", Integer.valueOf(i10)); } if (i11 != 0) { throw e.d("TYPE_PING streamId != 0", new Object[0]); } bVar.e((b10 & 1) != 0, this.f14583a.readInt(), this.f14583a.readInt()); } private void a0(b bVar, int i10) { int readInt = this.f14583a.readInt(); bVar.f(i10, readInt & Api.BaseClientBuilder.API_PRIORITY_OTHER, (this.f14583a.readByte() & 255) + 1, (Integer.MIN_VALUE & readInt) != 0); } static int c(int i10, byte b10, short s10) { if ((b10 & 8) != 0) { i10--; } if (s10 <= i10) { return (short) (i10 - s10); } throw e.d("PROTOCOL_ERROR padding %s > remaining length %s", Short.valueOf(s10), Integer.valueOf(i10)); } private void d0(b bVar, int i10, byte b10, int i11) { if (i10 != 5) { throw e.d("TYPE_PRIORITY length: %d != 5", Integer.valueOf(i10)); } if (i11 == 0) { throw e.d("TYPE_PRIORITY streamId == 0", new Object[0]); } a0(bVar, i11); } private void f0(b bVar, int i10, byte b10, int i11) { if (i11 == 0) { throw e.d("PROTOCOL_ERROR: TYPE_PUSH_PROMISE streamId == 0", new Object[0]); } short readByte = (b10 & 8) != 0 ? (short) (this.f14583a.readByte() & 255) : (short) 0; bVar.i(i11, this.f14583a.readInt() & Api.BaseClientBuilder.API_PRIORITY_OTHER, P(c(i10 - 4, b10, readByte), readByte, b10, i11)); } private void j0(b bVar, int i10, byte b10, int i11) { if (i10 != 4) { throw e.d("TYPE_RST_STREAM length: %d != 4", Integer.valueOf(i10)); } if (i11 == 0) { throw e.d("TYPE_RST_STREAM streamId == 0", new Object[0]); } int readInt = this.f14583a.readInt(); t9.b a10 = t9.b.a(readInt); if (a10 == null) { throw e.d("TYPE_RST_STREAM unexpected error code: %d", Integer.valueOf(readInt)); } bVar.h(i11, a10); } private void m0(b bVar, int i10, byte b10, int i11) { if (i11 != 0) { throw e.d("TYPE_SETTINGS streamId != 0", new Object[0]); } if ((b10 & 1) != 0) { if (i10 != 0) { throw e.d("FRAME_SIZE_ERROR ack frame should be empty!", new Object[0]); } bVar.a(); return; } if (i10 % 6 != 0) { throw e.d("TYPE_SETTINGS length %% 6 != 0: %s", Integer.valueOf(i10)); } m mVar = new m(); for (int i12 = 0; i12 < i10; i12 += 6) { int readShort = this.f14583a.readShort() & 65535; int readInt = this.f14583a.readInt(); if (readShort != 2) { if (readShort == 3) { readShort = 4; } else if (readShort == 4) { if (readInt < 0) { throw e.d("PROTOCOL_ERROR SETTINGS_INITIAL_WINDOW_SIZE > 2^31 - 1", new Object[0]); } readShort = 7; } else if (readShort == 5 && (readInt < 16384 || readInt > 16777215)) { throw e.d("PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: %s", Integer.valueOf(readInt)); } } else if (readInt != 0 && readInt != 1) { throw e.d("PROTOCOL_ERROR SETTINGS_ENABLE_PUSH != 0 or 1", new Object[0]); } mVar.i(readShort, readInt); } bVar.d(false, mVar); } private void n0(b bVar, int i10, byte b10, int i11) { if (i10 != 4) { throw e.d("TYPE_WINDOW_UPDATE length !=4: %s", Integer.valueOf(i10)); } long readInt = this.f14583a.readInt() & 2147483647L; if (readInt == 0) { throw e.d("windowSizeIncrement was 0", Long.valueOf(readInt)); } bVar.c(i11, readInt); } public void G(b bVar) { if (this.f14585c) { if (!z(true, bVar)) { throw e.d("Required SETTINGS preface not received", new Object[0]); } return; } x9.e eVar = this.f14583a; x9.f fVar = e.f14500a; x9.f d10 = eVar.d(fVar.n()); Logger logger = f14582e; if (logger.isLoggable(Level.FINE)) { logger.fine(o9.e.q("<< CONNECTION %s", d10.i())); } if (!fVar.equals(d10)) { throw e.d("Expected a connection header but was %s", d10.s()); } } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() { this.f14583a.close(); } public boolean z(boolean z10, b bVar) { try { this.f14583a.s(9L); int S = S(this.f14583a); if (S < 0 || S > 16384) { throw e.d("FRAME_SIZE_ERROR: %s", Integer.valueOf(S)); } byte readByte = (byte) (this.f14583a.readByte() & 255); if (z10 && readByte != 4) { throw e.d("Expected a SETTINGS frame but was %s", Byte.valueOf(readByte)); } byte readByte2 = (byte) (this.f14583a.readByte() & 255); int readInt = this.f14583a.readInt() & Api.BaseClientBuilder.API_PRIORITY_OTHER; Logger logger = f14582e; if (logger.isLoggable(Level.FINE)) { logger.fine(e.b(true, readInt, S, readByte, readByte2)); } switch (readByte) { case 0: I(bVar, S, readByte2, readInt); return true; case 1: R(bVar, S, readByte2, readInt); return true; case 2: d0(bVar, S, readByte2, readInt); return true; case 3: j0(bVar, S, readByte2, readInt); return true; case 4: m0(bVar, S, readByte2, readInt); return true; case 5: f0(bVar, S, readByte2, readInt); return true; case 6: Y(bVar, S, readByte2, readInt); return true; case 7: O(bVar, S, readByte2, readInt); return true; case 8: n0(bVar, S, readByte2, readInt); return true; default: this.f14583a.skip(S); return true; } } catch (EOFException unused) { return false; } } }