package com.applovin.impl; import java.util.ArrayDeque; /* loaded from: classes.dex */ final class a6 implements p7 { private final byte[] a = new byte[8]; private final ArrayDeque b = new ArrayDeque(); private final zp c = new zp(); private o7 d; private int e; private int f; private long g; @Override // com.applovin.impl.p7 public void a(o7 o7Var) { this.d = o7Var; } @Override // com.applovin.impl.p7 public void reset() { this.e = 0; this.b.clear(); this.c.b(); } @Override // com.applovin.impl.p7 public boolean a(l8 l8Var) { b1.b(this.d); while (true) { b bVar = (b) this.b.peek(); if (bVar == null || l8Var.f() < bVar.b) { if (this.e == 0) { long a2 = this.c.a(l8Var, true, false, 4); if (a2 == -2) { a2 = b(l8Var); } if (a2 == -1) { return false; } this.f = (int) a2; this.e = 1; } if (this.e == 1) { this.g = this.c.a(l8Var, false, true, 8); this.e = 2; } int b2 = this.d.b(this.f); if (b2 != 0) { if (b2 == 1) { long f = l8Var.f(); this.b.push(new b(this.f, this.g + f)); this.d.a(this.f, f, this.g); this.e = 0; return true; } if (b2 == 2) { long j = this.g; if (j <= 8) { this.d.a(this.f, b(l8Var, (int) j)); this.e = 0; return true; } throw dh.a("Invalid integer size: " + this.g, null); } if (b2 == 3) { long j2 = this.g; if (j2 <= 2147483647L) { this.d.a(this.f, c(l8Var, (int) j2)); this.e = 0; return true; } throw dh.a("String element size: " + this.g, null); } if (b2 == 4) { this.d.a(this.f, (int) this.g, l8Var); this.e = 0; return true; } if (b2 != 5) { throw dh.a("Invalid element type " + b2, null); } long j3 = this.g; if (j3 != 4 && j3 != 8) { throw dh.a("Invalid float size: " + this.g, null); } this.d.a(this.f, a(l8Var, (int) j3)); this.e = 0; return true; } l8Var.a((int) this.g); this.e = 0; } else { this.d.a(((b) this.b.pop()).a); return true; } } } private long b(l8 l8Var) { l8Var.b(); while (true) { l8Var.c(this.a, 0, 4); int a2 = zp.a(this.a[0]); if (a2 != -1 && a2 <= 4) { int a3 = (int) zp.a(this.a, a2, false); if (this.d.c(a3)) { l8Var.a(a2); return a3; } } l8Var.a(1); } } private static String c(l8 l8Var, int i) { if (i == 0) { return ""; } byte[] bArr = new byte[i]; l8Var.d(bArr, 0, i); while (i > 0 && bArr[i - 1] == 0) { i--; } return new String(bArr, 0, i); } public static final class b { private final int a; private final long b; private b(int i, long j) { this.a = i; this.b = j; } } private long b(l8 l8Var, int i) { l8Var.d(this.a, 0, i); long j = 0; for (int i2 = 0; i2 < i; i2++) { j = (j << 8) | (this.a[i2] & 255); } return j; } private double a(l8 l8Var, int i) { long b2 = b(l8Var, i); if (i == 4) { return Float.intBitsToFloat((int) b2); } return Double.longBitsToDouble(b2); } }