package com.google.crypto.tink.shaded.protobuf;

import com.google.crypto.tink.shaded.protobuf.ByteString;
import java.io.IOException;

/* JADX INFO: loaded from: classes2.dex */
public abstract class b implements o0 {
    protected int memoizedHashCode;

    public abstract int c(a1 a1Var);

    public final String d(String str) {
        return "Serializing " + getClass().getName() + " to a " + str + " threw an IOException (should never happen).";
    }

    public final byte[] e() {
        try {
            int iC = ((x) this).c(null);
            byte[] bArr = new byte[iC];
            n nVar = new n(bArr, iC);
            ((x) this).C(nVar);
            if (iC - nVar.f23949e == 0) {
                return bArr;
            }
            throw new IllegalStateException("Did not write as much data as expected.");
        } catch (IOException e10) {
            throw new RuntimeException(d("byte array"), e10);
        }
    }

    public final ByteString f() {
        try {
            int iC = ((x) this).c(null);
            ByteString byteString = ByteString.f23846a;
            i iVar = new i(iC);
            n nVar = iVar.f23905a;
            ((x) this).C(nVar);
            if (nVar.f23948d - nVar.f23949e == 0) {
                return new ByteString.LiteralByteString(iVar.f23906b);
            }
            throw new IllegalStateException("Did not write as much data as expected.");
        } catch (IOException e10) {
            throw new RuntimeException(d("ByteString"), e10);
        }
    }
}
