package com.squareup.wire;

import X.9lU;
import X.Q1J;
import com.bytedance.covode.number.Covode;

public final class ProtoWriter {
    public final 9lU LIZ;

    static {
        Covode.recordClassIndex(47733);
    }

    public static int LIZ(int i) {
        if ((i & -128) == 0) {
            return 1;
        }
        if ((i & -16384) == 0) {
            return 2;
        }
        if ((-2097152 & i) == 0) {
            return 3;
        }
        return (i & -268435456) == 0 ? 4 : 5;
    }

    public static int LIZ(long j) {
        if ((-128 & j) == 0) {
            return 1;
        }
        if ((-16384 & j) == 0) {
            return 2;
        }
        if ((-2097152 & j) == 0) {
            return 3;
        }
        if ((-268435456 & j) == 0) {
            return 4;
        }
        if ((-34359738368L & j) == 0) {
            return 5;
        }
        if ((-4398046511104L & j) == 0) {
            return 6;
        }
        if ((-562949953421312L & j) == 0) {
            return 7;
        }
        if ((-72057594037927936L & j) == 0) {
            return 8;
        }
        return (j & Long.MIN_VALUE) == 0 ? 9 : 10;
    }

    public static int LIZIZ(int i) {
        return (i >> 31) ^ (i << 1);
    }

    public static long LIZIZ(long j) {
        return (j >> 63) ^ (j << 1);
    }

    public ProtoWriter(9lU r1) {
        this.LIZ = r1;
    }

    public final void writeBytes(Q1J q1j) {
        this.LIZ.LIZ(q1j);
    }

    public final void writeFixed32(int i) {
        this.LIZ.LIZLLL(i);
    }

    public final void writeFixed64(long j) {
        this.LIZ.LIZ(j);
    }

    public final void writeString(String str) {
        this.LIZ.LIZ(str);
    }

    public final void writeVarint32(int i) {
        while ((i & -128) != 0) {
            this.LIZ.LIZ((i & 127) | 128);
            i >>>= 7;
        }
        this.LIZ.LIZ(i);
    }

    public final void writeVarint64(long j) {
        while ((-128 & j) != 0) {
            this.LIZ.LIZ((((int) j) & 127) | 128);
            j >>>= 7;
        }
        this.LIZ.LIZ((int) j);
    }

    public static int LIZ(int i, FieldEncoding fieldEncoding) {
        return (i << 3) | fieldEncoding.value;
    }

    public final void writeTag(int i, FieldEncoding fieldEncoding) {
        writeVarint32(LIZ(i, fieldEncoding));
    }
}
