package a.i.b.a.c.e;

import a.i.b.a.c.e.a.aa;
import a.i.b.a.c.e.a.aj;
import a.i.b.a.c.g.d;
import a.i.b.a.c.g.e;
import a.i.b.a.c.g.f;
import a.i.b.a.c.g.g;
import a.i.b.a.c.g.i$c$a;
import a.i.b.a.c.g.i.b;
import a.i.b.a.c.g.i.c;
import a.i.b.a.c.g.k;
import a.i.b.a.c.g.q;
import a.i.b.a.c.g.q.a;
import a.i.b.a.c.g.s;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.ttpic.baseutils.ApiHelper$VERSION_CODES;
import java.io.IOException;

public final class a$ai extends c<a$ai> implements aj {
    public static s<a$ai> BsC = new 1();
    private static final a$ai BvO;
    private final d BsB;
    private int BsD;
    private byte BsG;
    private int BsH;
    public int BsW;
    public int Buf;
    public aa BvP;
    public int BvQ;
    public aa Bvo;
    public int Bvp;

    /* synthetic */ a$ai(e eVar, g gVar, byte b) {
        this(eVar, gVar);
    }

    private a$ai(b<a$ai, ?> bVar) {
        super(bVar);
        this.BsG = (byte) -1;
        this.BsH = -1;
        this.BsB = bVar.BsB;
    }

    private a$ai() {
        this.BsG = (byte) -1;
        this.BsH = -1;
        this.BsB = d.Bzq;
    }

    public static a$ai efS() {
        return BvO;
    }

    private a$ai(e eVar, g gVar) {
        AppMethodBeat.i(120997);
        this.BsG = (byte) -1;
        this.BsH = -1;
        ecA();
        d.b ehS = d.ehS();
        f e = f.e(ehS, 1);
        int i = 0;
        while (i == 0) {
            try {
                int vc = eVar.vc();
                aa.c efk;
                switch (vc) {
                    case 0:
                        i = 1;
                        break;
                    case 8:
                        this.BsD |= 1;
                        this.BsW = eVar.vd();
                        break;
                    case ApiHelper$VERSION_CODES.JELLY_BEAN /*16*/:
                        this.BsD |= 2;
                        this.Buf = eVar.vd();
                        break;
                    case ApiHelper$VERSION_CODES.O /*26*/:
                        if ((this.BsD & 4) == 4) {
                            efk = this.Bvo.efk();
                        } else {
                            efk = null;
                        }
                        this.Bvo = (aa) eVar.a(aa.BsC, gVar);
                        if (efk != null) {
                            efk.j(this.Bvo);
                            this.Bvo = efk.eft();
                        }
                        this.BsD |= 4;
                        break;
                    case 34:
                        if ((this.BsD & 16) == 16) {
                            efk = this.BvP.efk();
                        } else {
                            efk = null;
                        }
                        this.BvP = (aa) eVar.a(aa.BsC, gVar);
                        if (efk != null) {
                            efk.j(this.BvP);
                            this.BvP = efk.eft();
                        }
                        this.BsD |= 16;
                        break;
                    case 40:
                        this.BsD |= 8;
                        this.Bvp = eVar.vd();
                        break;
                    case 48:
                        this.BsD |= 32;
                        this.BvQ = eVar.vd();
                        break;
                    default:
                        if (!a(eVar, e, gVar, vc)) {
                            i = 1;
                            break;
                        }
                        break;
                }
            } catch (k e2) {
                e2.BzY = this;
                AppMethodBeat.o(120997);
                throw e2;
            } catch (IOException e3) {
                k kVar = new k(e3.getMessage());
                kVar.BzY = this;
                AppMethodBeat.o(120997);
                throw kVar;
            } catch (Throwable th) {
                try {
                    e.flush();
                    this.BsB = ehS.ehW();
                } catch (IOException e4) {
                    this.BsB = ehS.ehW();
                } catch (Throwable th2) {
                    this.BsB = ehS.ehW();
                    AppMethodBeat.o(120997);
                }
                this.BzI.eii();
                AppMethodBeat.o(120997);
            }
        }
        try {
            e.flush();
            this.BsB = ehS.ehW();
        } catch (IOException e5) {
            this.BsB = ehS.ehW();
        } catch (Throwable th3) {
            this.BsB = ehS.ehW();
            AppMethodBeat.o(120997);
        }
        this.BzI.eii();
        AppMethodBeat.o(120997);
    }

    static {
        AppMethodBeat.i(121005);
        a$ai a_ai = new a$ai();
        BvO = a_ai;
        a_ai.ecA();
        AppMethodBeat.o(121005);
    }

    public final s<a$ai> ecy() {
        return BsC;
    }

    public final boolean ecY() {
        return (this.BsD & 1) == 1;
    }

    public final boolean edW() {
        return (this.BsD & 2) == 2;
    }

    public final boolean ecP() {
        return (this.BsD & 4) == 4;
    }

    public final boolean efn() {
        return (this.BsD & 8) == 8;
    }

    public final boolean efT() {
        return (this.BsD & 16) == 16;
    }

    public final boolean efU() {
        return (this.BsD & 32) == 32;
    }

    private void ecA() {
        AppMethodBeat.i(120998);
        this.BsW = 0;
        this.Buf = 0;
        this.Bvo = aa.eeX();
        this.Bvp = 0;
        this.BvP = aa.eeX();
        this.BvQ = 0;
        AppMethodBeat.o(120998);
    }

    public final boolean isInitialized() {
        AppMethodBeat.i(120999);
        byte b = this.BsG;
        if (b == (byte) 1) {
            AppMethodBeat.o(120999);
            return true;
        } else if (b == (byte) 0) {
            AppMethodBeat.o(120999);
            return false;
        } else if (!edW()) {
            this.BsG = (byte) 0;
            AppMethodBeat.o(120999);
            return false;
        } else if (ecP() && !this.Bvo.isInitialized()) {
            this.BsG = (byte) 0;
            AppMethodBeat.o(120999);
            return false;
        } else if (efT() && !this.BvP.isInitialized()) {
            this.BsG = (byte) 0;
            AppMethodBeat.o(120999);
            return false;
        } else if (this.BzI.isInitialized()) {
            this.BsG = (byte) 1;
            AppMethodBeat.o(120999);
            return true;
        } else {
            this.BsG = (byte) 0;
            AppMethodBeat.o(120999);
            return false;
        }
    }

    public final void a(f fVar) {
        AppMethodBeat.i(121000);
        vq();
        i$c$a eip = eip();
        if ((this.BsD & 1) == 1) {
            fVar.bq(1, this.BsW);
        }
        if ((this.BsD & 2) == 2) {
            fVar.bq(2, this.Buf);
        }
        if ((this.BsD & 4) == 4) {
            fVar.a(3, this.Bvo);
        }
        if ((this.BsD & 16) == 16) {
            fVar.a(4, this.BvP);
        }
        if ((this.BsD & 8) == 8) {
            fVar.bq(5, this.Bvp);
        }
        if ((this.BsD & 32) == 32) {
            fVar.bq(6, this.BvQ);
        }
        eip.b(200, fVar);
        fVar.d(this.BsB);
        AppMethodBeat.o(121000);
    }

    public final int vq() {
        AppMethodBeat.i(121001);
        int i = this.BsH;
        if (i != -1) {
            AppMethodBeat.o(121001);
            return i;
        }
        i = 0;
        if ((this.BsD & 1) == 1) {
            i = f.bs(1, this.BsW) + 0;
        }
        if ((this.BsD & 2) == 2) {
            i += f.bs(2, this.Buf);
        }
        if ((this.BsD & 4) == 4) {
            i += f.c(3, this.Bvo);
        }
        if ((this.BsD & 16) == 16) {
            i += f.c(4, this.BvP);
        }
        if ((this.BsD & 8) == 8) {
            i += f.bs(5, this.Bvp);
        }
        if ((this.BsD & 32) == 32) {
            i += f.bs(6, this.BvQ);
        }
        i = (i + this.BzI.vq()) + this.BsB.size();
        this.BsH = i;
        AppMethodBeat.o(121001);
        return i;
    }

    public static a b(a$ai a_ai) {
        AppMethodBeat.i(121002);
        a d = a.efX().d(a_ai);
        AppMethodBeat.o(121002);
        return d;
    }

    public final /* bridge */ /* synthetic */ q ecE() {
        return BvO;
    }

    public final /* synthetic */ a ecC() {
        AppMethodBeat.i(121003);
        a d = a.efX().d(this);
        AppMethodBeat.o(121003);
        return d;
    }

    public final /* synthetic */ a ecD() {
        AppMethodBeat.i(121004);
        a efX = a.efX();
        AppMethodBeat.o(121004);
        return efX;
    }
}
