package j$.time.zone;

import com.google.firebase.firestore.local.SQLitePersistence;
import j$.time.ZoneOffset;
import java.io.Externalizable;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.util.TimeZone;

/* JADX INFO: loaded from: classes2.dex */
final class a implements Externalizable {
    private static final long serialVersionUID = -8885321777449118786L;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private byte f19389a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private Serializable f19390b;

    public a() {
    }

    a(byte b5, Serializable serializable) {
        this.f19389a = b5;
        this.f19390b = serializable;
    }

    @Override // java.io.Externalizable
    public final void writeExternal(ObjectOutput objectOutput) throws IOException {
        byte b5 = this.f19389a;
        Serializable serializable = this.f19390b;
        objectOutput.writeByte(b5);
        if (b5 == 1) {
            ((f) serializable).writeExternal(objectOutput);
            return;
        }
        if (b5 == 2) {
            ((b) serializable).writeExternal(objectOutput);
        } else if (b5 == 3) {
            ((e) serializable).writeExternal(objectOutput);
        } else {
            if (b5 == 100) {
                ((f) serializable).l(objectOutput);
                return;
            }
            throw new InvalidClassException("Unknown serialized type");
        }
    }

    @Override // java.io.Externalizable
    public final void readExternal(ObjectInput objectInput) throws IOException {
        Serializable serializableK;
        byte b5 = objectInput.readByte();
        this.f19389a = b5;
        if (b5 == 1) {
            serializableK = f.k(objectInput);
        } else if (b5 == 2) {
            long jA = a(objectInput);
            ZoneOffset zoneOffsetB = b(objectInput);
            ZoneOffset zoneOffsetB2 = b(objectInput);
            if (zoneOffsetB.equals(zoneOffsetB2)) {
                throw new IllegalArgumentException("Offsets must not be equal");
            }
            serializableK = new b(jA, zoneOffsetB, zoneOffsetB2);
        } else if (b5 == 3) {
            serializableK = e.b(objectInput);
        } else {
            if (b5 != 100) {
                throw new StreamCorruptedException("Unknown serialized type");
            }
            serializableK = new f(TimeZone.getTimeZone(objectInput.readUTF()));
        }
        this.f19390b = serializableK;
    }

    private Object readResolve() {
        return this.f19390b;
    }

    static void d(ZoneOffset zoneOffset, ObjectOutput objectOutput) {
        int iC0 = zoneOffset.c0();
        int i6 = iC0 % SQLitePersistence.MAX_ARGS == 0 ? iC0 / SQLitePersistence.MAX_ARGS : 127;
        objectOutput.writeByte(i6);
        if (i6 == 127) {
            objectOutput.writeInt(iC0);
        }
    }

    static ZoneOffset b(ObjectInput objectInput) throws IOException {
        byte b5 = objectInput.readByte();
        return b5 == 127 ? ZoneOffset.f0(objectInput.readInt()) : ZoneOffset.f0(b5 * 900);
    }

    static void c(long j4, ObjectOutput objectOutput) {
        if (j4 >= -4575744000L && j4 < 10413792000L && j4 % 900 == 0) {
            int i6 = (int) ((j4 + 4575744000L) / 900);
            objectOutput.writeByte((i6 >>> 16) & 255);
            objectOutput.writeByte((i6 >>> 8) & 255);
            objectOutput.writeByte(i6 & 255);
            return;
        }
        objectOutput.writeByte(255);
        objectOutput.writeLong(j4);
    }

    static long a(ObjectInput objectInput) {
        int i6 = objectInput.readByte() & 255;
        if (i6 == 255) {
            return objectInput.readLong();
        }
        return (((long) (((i6 << 16) + ((objectInput.readByte() & 255) << 8)) + (objectInput.readByte() & 255))) * 900) - 4575744000L;
    }
}
