package kotlin.reflect.w.internal.y0.i;

import com.cvte.vman.instance.InvokeCmd;
import java.io.IOException;
import java.io.InputStream;
import kotlin.reflect.w.internal.y0.i.a;
import kotlin.reflect.w.internal.y0.i.p;

/* JADX INFO: loaded from: classes2.dex */
public abstract class b<MessageType extends p> implements r<MessageType> {
    static {
        f fVar = f.a;
    }

    public final MessageType b(MessageType messagetype) throws j {
        v vVar;
        if (messagetype == null || messagetype.i()) {
            return messagetype;
        }
        if (messagetype instanceof a) {
            vVar = new v();
        } else {
            vVar = new v();
        }
        j jVar = new j(vVar.getMessage());
        jVar.f8275f = messagetype;
        throw jVar;
    }

    public Object c(InputStream inputStream, f fVar) throws j {
        p pVarD;
        try {
            int i2 = inputStream.read();
            if (i2 == -1) {
                pVarD = null;
            } else {
                if ((i2 & 128) != 0) {
                    i2 &= InvokeCmd.CMD_SYSTEMCTRL_IS_PRODUCTION_MODE;
                    int i3 = 7;
                    while (true) {
                        if (i3 >= 32) {
                            while (i3 < 64) {
                                int i4 = inputStream.read();
                                if (i4 == -1) {
                                    throw j.d();
                                }
                                if ((i4 & 128) != 0) {
                                    i3 += 7;
                                }
                            }
                            throw new j("CodedInputStream encountered a malformed varint.");
                        }
                        int i5 = inputStream.read();
                        if (i5 == -1) {
                            throw j.d();
                        }
                        i2 |= (i5 & InvokeCmd.CMD_SYSTEMCTRL_IS_PRODUCTION_MODE) << i3;
                        if ((i5 & 128) == 0) {
                            break;
                        }
                        i3 += 7;
                    }
                }
                pVarD = d(new a.AbstractC0155a.C0156a(inputStream, i2), fVar);
            }
            b(pVarD);
            return pVarD;
        } catch (IOException e2) {
            throw new j(e2.getMessage());
        }
    }

    public MessageType d(InputStream inputStream, f fVar) throws j {
        d dVar = new d(inputStream);
        MessageType messagetypeA = a(dVar, fVar);
        try {
            dVar.a(0);
            return messagetypeA;
        } catch (j e2) {
            e2.f8275f = messagetypeA;
            throw e2;
        }
    }
}
