package o;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.RandomAccess;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public abstract class Ns0 {
    protected int zza;

    public static void c(Iterable iterable, List list) {
        Charset charset = Et0.a;
        iterable.getClass();
        if (iterable instanceof It0) {
            List listZza = ((It0) iterable).zza();
            if (list != null) {
                throw new ClassCastException();
            }
            list.size();
            Iterator it = listZza.iterator();
            if (it.hasNext()) {
                Object next = it.next();
                next.getClass();
                if (next instanceof Ws0) {
                    throw null;
                }
                if (!(next instanceof byte[])) {
                    throw null;
                }
                byte[] bArr = (byte[]) next;
                Ws0.d(bArr, 0, bArr.length);
                throw null;
            }
            return;
        }
        if (iterable instanceof InterfaceC1049du0) {
            list.addAll((Collection) iterable);
            return;
        }
        if (iterable instanceof Collection) {
            int size = ((Collection) iterable).size();
            if (list instanceof ArrayList) {
                ((ArrayList) list).ensureCapacity(list.size() + size);
            } else if (list instanceof C1337gu0) {
                C1337gu0 c1337gu0 = (C1337gu0) list;
                int i = c1337gu0.n + size;
                int length = c1337gu0.m.length;
                if (i > length) {
                    if (length != 0) {
                        while (length < i) {
                            length = Math.max(((length * 3) / 2) + 1, 10);
                        }
                        c1337gu0.m = Arrays.copyOf(c1337gu0.m, length);
                    } else {
                        c1337gu0.m = new Object[Math.max(i, 10)];
                    }
                }
            }
        }
        int size2 = list.size();
        if (!(iterable instanceof List) || !(iterable instanceof RandomAccess)) {
            for (Object obj : iterable) {
                if (obj == null) {
                    AbstractC2286qt0.a(size2, list);
                    throw null;
                }
                list.add(obj);
            }
            return;
        }
        List list2 = (List) iterable;
        int size3 = list2.size();
        for (int i2 = 0; i2 < size3; i2++) {
            Object obj2 = list2.get(i2);
            if (obj2 == null) {
                AbstractC2286qt0.a(size2, list);
                throw null;
            }
            list.add(obj2);
        }
    }

    public final byte[] a() {
        try {
            AbstractC2665ut0 abstractC2665ut0 = (AbstractC2665ut0) this;
            int iK = abstractC2665ut0.k();
            byte[] bArr = new byte[iK];
            Zs0 zs0 = new Zs0(iK, bArr);
            abstractC2665ut0.d(zs0);
            if (iK - zs0.f443o == 0) {
                return bArr;
            }
            throw new IllegalStateException("Did not write as much data as expected.");
        } catch (IOException e) {
            String name = getClass().getName();
            StringBuilder sb = new StringBuilder(name.length() + 72);
            sb.append("Serializing ");
            sb.append(name);
            sb.append(" to a byte array threw an IOException (should never happen).");
            throw new RuntimeException(sb.toString(), e);
        }
    }

    public abstract int b(InterfaceC1718ku0 interfaceC1718ku0);
}
