package n5; import com.google.android.gms.common.api.Api; import h5.o0; import h5.p0; import java.io.Closeable; import java.io.IOException; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import n5.k; /* loaded from: classes2.dex */ final class l implements Closeable { /* renamed from: e, reason: collision with root package name */ static final Logger f12129e = Logger.getLogger(d.class.getName()); /* renamed from: a, reason: collision with root package name */ private final h5.f f12130a; /* renamed from: b, reason: collision with root package name */ private final a f12131b; /* renamed from: c, reason: collision with root package name */ private final boolean f12132c; /* renamed from: d, reason: collision with root package name */ final k.a f12133d; static final class a implements o0 { /* renamed from: a, reason: collision with root package name */ private final h5.f f12134a; /* renamed from: b, reason: collision with root package name */ int f12135b; /* renamed from: c, reason: collision with root package name */ byte f12136c; /* renamed from: d, reason: collision with root package name */ int f12137d; /* renamed from: e, reason: collision with root package name */ int f12138e; /* renamed from: f, reason: collision with root package name */ short f12139f; a(h5.f fVar) { this.f12134a = fVar; } private void c() { int i10 = this.f12137d; int z10 = l.z(this.f12134a); this.f12138e = z10; this.f12135b = z10; byte readByte = (byte) (this.f12134a.readByte() & 255); this.f12136c = (byte) (this.f12134a.readByte() & 255); Logger logger = l.f12129e; if (logger.isLoggable(Level.FINE)) { logger.fine(d.c(true, this.f12137d, this.f12135b, readByte, this.f12136c)); } int readInt = this.f12134a.readInt() & Api.BaseClientBuilder.API_PRIORITY_OTHER; this.f12137d = readInt; if (readByte != 9) { d.d("%s != TYPE_CONTINUATION", Byte.valueOf(readByte)); throw null; } if (readInt == i10) { return; } d.d("TYPE_CONTINUATION streamId changed", new Object[0]); throw null; } @Override // h5.o0 public long H(h5.d dVar, long j10) { while (true) { int i10 = this.f12138e; if (i10 != 0) { long H = this.f12134a.H(dVar, Math.min(j10, i10)); if (H == -1) { return -1L; } this.f12138e = (int) (this.f12138e - H); return H; } this.f12134a.skip(this.f12139f); this.f12139f = (short) 0; if ((this.f12136c & 4) != 0) { return -1L; } c(); } } @Override // h5.o0 public p0 b() { return this.f12134a.b(); } @Override // h5.o0, java.io.Closeable, java.lang.AutoCloseable public void close() { } } interface b { void a(); void a(int i10, n5.b bVar, h5.g gVar); void b(boolean z10, int i10, int i11); void c(int i10, int i11, List list); void d(boolean z10, i iVar); void e(boolean z10, int i10, h5.f fVar, int i11); void f(boolean z10, int i10, int i11, List list); void g(int i10, int i11, int i12, boolean z10); void h(int i10, n5.b bVar); void i(int i10, long j10); } l(h5.f fVar, boolean z10) { this.f12130a = fVar; this.f12132c = z10; a aVar = new a(fVar); this.f12131b = aVar; this.f12133d = new k.a(4096, aVar); } private List G(int i10, short s10, byte b10, int i11) { a aVar = this.f12131b; aVar.f12138e = i10; aVar.f12135b = i10; aVar.f12139f = s10; aVar.f12136c = b10; aVar.f12137d = i11; this.f12133d.m(); return this.f12133d.h(); } private void O(b bVar, int i10) { int readInt = this.f12130a.readInt(); bVar.g(i10, readInt & Api.BaseClientBuilder.API_PRIORITY_OTHER, (this.f12130a.readByte() & 255) + 1, (Integer.MIN_VALUE & readInt) != 0); } private void P(b bVar, int i10, byte b10, int i11) { if (i11 == 0) { d.d("PROTOCOL_ERROR: TYPE_DATA streamId == 0", new Object[0]); throw null; } boolean z10 = (b10 & 1) != 0; if ((b10 & 32) != 0) { d.d("PROTOCOL_ERROR: FLAG_COMPRESSED without SETTINGS_COMPRESS_DATA", new Object[0]); throw null; } short readByte = (b10 & 8) != 0 ? (short) (this.f12130a.readByte() & 255) : (short) 0; bVar.e(z10, i11, this.f12130a, c(i10, b10, readByte)); this.f12130a.skip(readByte); } private void S(b bVar, int i10, byte b10, int i11) { if (i10 < 8) { d.d("TYPE_GOAWAY length < 8: %s", Integer.valueOf(i10)); throw null; } if (i11 != 0) { d.d("TYPE_GOAWAY streamId != 0", new Object[0]); throw null; } int readInt = this.f12130a.readInt(); int readInt2 = this.f12130a.readInt(); int i12 = i10 - 8; n5.b a10 = n5.b.a(readInt2); if (a10 == null) { d.d("TYPE_GOAWAY unexpected error code: %d", Integer.valueOf(readInt2)); throw null; } h5.g gVar = h5.g.f10073e; if (i12 > 0) { gVar = this.f12130a.d(i12); } bVar.a(readInt, a10, gVar); } private void Y(b bVar, int i10, byte b10, int i11) { if (i11 == 0) { d.d("PROTOCOL_ERROR: TYPE_HEADERS streamId == 0", new Object[0]); throw null; } boolean z10 = (b10 & 1) != 0; short readByte = (b10 & 8) != 0 ? (short) (this.f12130a.readByte() & 255) : (short) 0; if ((b10 & 32) != 0) { O(bVar, i11); i10 -= 5; } bVar.f(z10, i11, -1, G(c(i10, b10, readByte), readByte, b10, i11)); } private void a0(b bVar, int i10, byte b10, int i11) { if (i10 != 8) { d.d("TYPE_PING length != 8: %s", Integer.valueOf(i10)); throw null; } if (i11 != 0) { d.d("TYPE_PING streamId != 0", new Object[0]); throw null; } bVar.b((b10 & 1) != 0, this.f12130a.readInt(), this.f12130a.readInt()); } static int c(int i10, byte b10, short s10) { if ((b10 & 8) != 0) { i10--; } if (s10 <= i10) { return (short) (i10 - s10); } d.d("PROTOCOL_ERROR padding %s > remaining length %s", Short.valueOf(s10), Integer.valueOf(i10)); throw null; } private void d0(b bVar, int i10, byte b10, int i11) { if (i10 != 5) { d.d("TYPE_PRIORITY length: %d != 5", Integer.valueOf(i10)); throw null; } if (i11 != 0) { O(bVar, i11); } else { d.d("TYPE_PRIORITY streamId == 0", new Object[0]); throw null; } } private void f0(b bVar, int i10, byte b10, int i11) { if (i11 == 0) { d.d("PROTOCOL_ERROR: TYPE_PUSH_PROMISE streamId == 0", new Object[0]); throw null; } short readByte = (b10 & 8) != 0 ? (short) (this.f12130a.readByte() & 255) : (short) 0; bVar.c(i11, this.f12130a.readInt() & Api.BaseClientBuilder.API_PRIORITY_OTHER, G(c(i10 - 4, b10, readByte), readByte, b10, i11)); } private void j0(b bVar, int i10, byte b10, int i11) { if (i10 != 4) { d.d("TYPE_RST_STREAM length: %d != 4", Integer.valueOf(i10)); throw null; } if (i11 == 0) { d.d("TYPE_RST_STREAM streamId == 0", new Object[0]); throw null; } int readInt = this.f12130a.readInt(); n5.b a10 = n5.b.a(readInt); if (a10 != null) { bVar.h(i11, a10); } else { d.d("TYPE_RST_STREAM unexpected error code: %d", Integer.valueOf(readInt)); throw null; } } private void m0(b bVar, int i10, byte b10, int i11) { if (i11 != 0) { d.d("TYPE_SETTINGS streamId != 0", new Object[0]); throw null; } if ((b10 & 1) != 0) { if (i10 == 0) { bVar.a(); return; } else { d.d("FRAME_SIZE_ERROR ack frame should be empty!", new Object[0]); throw null; } } if (i10 % 6 != 0) { d.d("TYPE_SETTINGS length %% 6 != 0: %s", Integer.valueOf(i10)); throw null; } i iVar = new i(); for (int i12 = 0; i12 < i10; i12 += 6) { int readShort = this.f12130a.readShort() & 65535; int readInt = this.f12130a.readInt(); if (readShort != 2) { if (readShort == 3) { readShort = 4; } else if (readShort == 4) { if (readInt < 0) { d.d("PROTOCOL_ERROR SETTINGS_INITIAL_WINDOW_SIZE > 2^31 - 1", new Object[0]); throw null; } readShort = 7; } else if (readShort == 5 && (readInt < 16384 || readInt > 16777215)) { d.d("PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: %s", Integer.valueOf(readInt)); throw null; } } else if (readInt != 0 && readInt != 1) { d.d("PROTOCOL_ERROR SETTINGS_ENABLE_PUSH != 0 or 1", new Object[0]); throw null; } iVar.b(readShort, readInt); } bVar.d(false, iVar); } private void n0(b bVar, int i10, byte b10, int i11) { if (i10 != 4) { d.d("TYPE_WINDOW_UPDATE length !=4: %s", Integer.valueOf(i10)); throw null; } long readInt = this.f12130a.readInt() & 2147483647L; if (readInt != 0) { bVar.i(i11, readInt); } else { d.d("windowSizeIncrement was 0", Long.valueOf(readInt)); throw null; } } static int z(h5.f fVar) { return (fVar.readByte() & 255) | ((fVar.readByte() & 255) << 16) | ((fVar.readByte() & 255) << 8); } public void I(b bVar) { if (this.f12132c) { if (R(true, bVar)) { return; } d.d("Required SETTINGS preface not received", new Object[0]); throw null; } h5.f fVar = this.f12130a; h5.g gVar = d.f11995a; h5.g d10 = fVar.d(gVar.o()); Logger logger = f12129e; if (logger.isLoggable(Level.FINE)) { logger.fine(i5.c.r("<< CONNECTION %s", d10.j())); } if (gVar.equals(d10)) { return; } d.d("Expected a connection header but was %s", d10.t()); throw null; } public boolean R(boolean z10, b bVar) { try { this.f12130a.s(9L); int z11 = z(this.f12130a); if (z11 < 0 || z11 > 16384) { d.d("FRAME_SIZE_ERROR: %s", Integer.valueOf(z11)); throw null; } byte readByte = (byte) (this.f12130a.readByte() & 255); if (z10 && readByte != 4) { d.d("Expected a SETTINGS frame but was %s", Byte.valueOf(readByte)); throw null; } byte readByte2 = (byte) (this.f12130a.readByte() & 255); int readInt = this.f12130a.readInt() & Api.BaseClientBuilder.API_PRIORITY_OTHER; Logger logger = f12129e; if (logger.isLoggable(Level.FINE)) { logger.fine(d.c(true, readInt, z11, readByte, readByte2)); } switch (readByte) { case 0: P(bVar, z11, readByte2, readInt); return true; case 1: Y(bVar, z11, readByte2, readInt); return true; case 2: d0(bVar, z11, readByte2, readInt); return true; case 3: j0(bVar, z11, readByte2, readInt); return true; case 4: m0(bVar, z11, readByte2, readInt); return true; case 5: f0(bVar, z11, readByte2, readInt); return true; case 6: a0(bVar, z11, readByte2, readInt); return true; case 7: S(bVar, z11, readByte2, readInt); return true; case 8: n0(bVar, z11, readByte2, readInt); return true; default: this.f12130a.skip(z11); return true; } } catch (IOException unused) { return false; } } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() { this.f12130a.close(); } }