package h1;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import l1.AbstractC0619b;

/* JADX INFO: renamed from: h1.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0506a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    int f4188a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    HashMap f4189b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public byte[] f4190c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f4191d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f4192e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f4193f = 0;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public C0506a f4194g = this;

    /* JADX INFO: renamed from: h1.a$a, reason: collision with other inner class name */
    static class C0076a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        int f4195a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        Object f4196b;

        C0076a() {
        }
    }

    public C0506a(byte[] bArr, int i2) {
        this.f4190c = bArr;
        this.f4192e = i2;
        this.f4191d = i2;
    }

    private int m(Object obj) {
        if (this.f4189b == null) {
            this.f4189b = new HashMap();
            this.f4188a = 1;
        }
        C0076a c0076a = (C0076a) this.f4189b.get(obj);
        if (c0076a == null) {
            c0076a = new C0076a();
            int i2 = this.f4188a;
            this.f4188a = i2 + 1;
            c0076a.f4195a = i2;
            c0076a.f4196b = obj;
            this.f4189b.put(obj, c0076a);
        }
        return c0076a.f4195a;
    }

    public void a(int i2) {
        int i3 = this.f4192e + i2;
        this.f4192e = i3;
        int i4 = this.f4191d;
        int i5 = i3 - i4;
        C0506a c0506a = this.f4194g;
        if (i5 > c0506a.f4193f) {
            c0506a.f4193f = i3 - i4;
        }
    }

    public int b(int i2) {
        int i3 = i2 - 1;
        int i4 = this.f4192e - this.f4191d;
        int i5 = ((~i3) & (i4 + i3)) - i4;
        a(i5);
        return i5;
    }

    public int c() {
        b(4);
        int iC = AbstractC0619b.c(this.f4190c, this.f4192e);
        a(4);
        return iC;
    }

    public int d() {
        b(2);
        short sB = AbstractC0619b.b(this.f4190c, this.f4192e);
        a(2);
        return sB;
    }

    public int e() {
        int i2 = this.f4190c[this.f4192e] & 255;
        a(1);
        return i2;
    }

    public String f() throws C0507b {
        String str;
        b(4);
        int i2 = this.f4192e;
        int iC = AbstractC0619b.c(this.f4190c, i2);
        int i3 = i2 + 12;
        if (iC != 0) {
            int i4 = (iC - 1) * 2;
            try {
                if (i4 < 0 || i4 > 65535) {
                    throw new C0507b("invalid array conformance");
                }
                str = new String(this.f4190c, i3, i4, "UTF-16LE");
                i3 += i4 + 2;
            } catch (UnsupportedEncodingException unused) {
                str = null;
            }
        } else {
            str = null;
        }
        a(i3 - this.f4192e);
        return str;
    }

    public C0506a g(int i2) {
        C0506a c0506a = new C0506a(this.f4190c, this.f4191d);
        c0506a.f4192e = i2;
        c0506a.f4194g = this.f4194g;
        return c0506a;
    }

    public void h(int i2) {
        b(4);
        AbstractC0619b.f(i2, this.f4190c, this.f4192e);
        a(4);
    }

    public void i(Object obj, int i2) {
        if (obj == null) {
            h(0);
            return;
        }
        if (i2 != 1) {
            if (i2 == 2) {
                h(m(obj));
                return;
            } else if (i2 != 3) {
                return;
            }
        }
        h(System.identityHashCode(obj));
    }

    public void j(int i2) {
        b(2);
        AbstractC0619b.d((short) i2, this.f4190c, this.f4192e);
        a(2);
    }

    public void k(int i2) {
        this.f4190c[this.f4192e] = (byte) (i2 & 255);
        a(1);
    }

    public void l(String str) {
        b(4);
        int i2 = this.f4192e;
        int length = str.length();
        int i3 = length + 1;
        AbstractC0619b.f(i3, this.f4190c, i2);
        AbstractC0619b.f(0, this.f4190c, i2 + 4);
        AbstractC0619b.f(i3, this.f4190c, i2 + 8);
        int i4 = i2 + 12;
        try {
            System.arraycopy(str.getBytes("UTF-16LE"), 0, this.f4190c, i4, length * 2);
        } catch (UnsupportedEncodingException unused) {
        }
        int i5 = i4 + (length * 2);
        byte[] bArr = this.f4190c;
        bArr[i5] = 0;
        bArr[i5 + 1] = 0;
        a((i5 + 2) - this.f4192e);
    }

    public int n() {
        return this.f4192e;
    }

    public int o() {
        return this.f4194g.f4193f;
    }

    public void p() {
        this.f4192e = this.f4191d;
        this.f4193f = 0;
        this.f4194g = this;
    }

    public void q(int i2) {
        this.f4192e = i2;
    }

    public void r(int i2) {
        this.f4194g.f4193f = i2;
    }

    public String toString() {
        return "start=" + this.f4191d + ",index=" + this.f4192e + ",length=" + o();
    }
}
