package com.google.protobuf;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import p138.p139.p143.p144.C2803;
import p138.p176.p328.AbstractC6011;
import p138.p176.p328.AbstractC6013;
import p138.p176.p328.C6041;
import p138.p176.p328.C6063;
import p138.p176.p328.C6065;
import p138.p176.p328.InterfaceC6049;

/* JADX INFO: loaded from: classes.dex */
public abstract class CodedOutputStream extends AbstractC6011 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final Logger f2161 = Logger.getLogger(CodedOutputStream.class.getName());

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static final boolean f2162 = C6063.f16964;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static final long f2163 = C6063.f16965;

    public static class OutOfSpaceException extends IOException {
        public OutOfSpaceException() {
            super("CodedOutputStream was writing to a flat byte array and ran out of space.");
        }

        public OutOfSpaceException(String str, Throwable th) {
            super(C2803.m4879("CodedOutputStream was writing to a flat byte array and ran out of space.: ", str), th);
        }

        public OutOfSpaceException(Throwable th) {
            super("CodedOutputStream was writing to a flat byte array and ran out of space.", th);
        }
    }

    /* JADX INFO: renamed from: com.google.protobuf.CodedOutputStream$ؠ, reason: contains not printable characters */
    public static class C0345 extends CodedOutputStream {

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public final byte[] f2164;

        /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
        public final int f2165;

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public int f2166;

        public C0345(byte[] bArr, int i, int i2) {
            super(null);
            if (bArr == null) {
                throw new NullPointerException("buffer");
            }
            int i3 = i + i2;
            if ((i | i2 | (bArr.length - i3)) < 0) {
                throw new IllegalArgumentException(String.format("Array range is invalid. Buffer.length=%d, offset=%d, length=%d", Integer.valueOf(bArr.length), Integer.valueOf(i), Integer.valueOf(i2)));
            }
            this.f2164 = bArr;
            this.f2166 = i;
            this.f2165 = i3;
        }

        @Override // com.google.protobuf.CodedOutputStream
        /* JADX INFO: renamed from: ֏ */
        public final int mo1449() {
            return this.f2165 - this.f2166;
        }

        @Override // com.google.protobuf.CodedOutputStream
        /* JADX INFO: renamed from: ֏ */
        public final void mo1450(int i) {
            if (CodedOutputStream.f2162 && mo1449() >= 10) {
                long j = CodedOutputStream.f2163 + ((long) this.f2166);
                while ((i & (-128)) != 0) {
                    C6063.m9438(this.f2164, j, (byte) ((i & 127) | 128));
                    this.f2166++;
                    i >>>= 7;
                    j = 1 + j;
                }
                C6063.m9438(this.f2164, j, (byte) i);
                this.f2166++;
                return;
            }
            while ((i & (-128)) != 0) {
                try {
                    byte[] bArr = this.f2164;
                    int i2 = this.f2166;
                    this.f2166 = i2 + 1;
                    bArr[i2] = (byte) ((i & 127) | 128);
                    i >>>= 7;
                } catch (IndexOutOfBoundsException e) {
                    throw new OutOfSpaceException(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f2166), Integer.valueOf(this.f2165), 1), e);
                }
            }
            byte[] bArr2 = this.f2164;
            int i3 = this.f2166;
            this.f2166 = i3 + 1;
            bArr2[i3] = (byte) i;
        }

        @Override // com.google.protobuf.CodedOutputStream
        /* JADX INFO: renamed from: ֏ */
        public final void mo1451(int i, int i2) throws OutOfSpaceException {
            mo1450((i << 3) | 0);
            if (i2 >= 0) {
                mo1450(i2);
                return;
            }
            long j = i2;
            if (CodedOutputStream.f2162 && mo1449() >= 10) {
                long j2 = CodedOutputStream.f2163 + ((long) this.f2166);
                while ((j & (-128)) != 0) {
                    C6063.m9438(this.f2164, j2, (byte) ((((int) j) & 127) | 128));
                    this.f2166++;
                    j >>>= 7;
                    j2 = 1 + j2;
                }
                C6063.m9438(this.f2164, j2, (byte) j);
                this.f2166++;
                return;
            }
            while ((j & (-128)) != 0) {
                try {
                    byte[] bArr = this.f2164;
                    int i3 = this.f2166;
                    this.f2166 = i3 + 1;
                    bArr[i3] = (byte) ((((int) j) & 127) | 128);
                    j >>>= 7;
                } catch (IndexOutOfBoundsException e) {
                    throw new OutOfSpaceException(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f2166), Integer.valueOf(this.f2165), 1), e);
                }
            }
            byte[] bArr2 = this.f2164;
            int i4 = this.f2166;
            this.f2166 = i4 + 1;
            bArr2[i4] = (byte) j;
        }

        @Override // com.google.protobuf.CodedOutputStream
        /* JADX INFO: renamed from: ֏ */
        public final void mo1452(int i, String str) throws OutOfSpaceException {
            mo1450((i << 3) | 2);
            int i2 = this.f2166;
            try {
                int iM1447 = CodedOutputStream.m1447(str.length() * 3);
                int iM14472 = CodedOutputStream.m1447(str.length());
                if (iM14472 == iM1447) {
                    int i3 = i2 + iM14472;
                    this.f2166 = i3;
                    int iMo9447 = C6065.f16966.mo9447(str, this.f2164, i3, mo1449());
                    this.f2166 = i2;
                    mo1450((iMo9447 - i2) - iM14472);
                    this.f2166 = iMo9447;
                } else {
                    mo1450(C6065.m9444(str));
                    this.f2166 = C6065.f16966.mo9447(str, this.f2164, this.f2166, mo1449());
                }
            } catch (IndexOutOfBoundsException e) {
                throw new OutOfSpaceException(e);
            } catch (C6065.C6068 e2) {
                this.f2166 = i2;
                CodedOutputStream.f2161.log(Level.WARNING, "Converting ill-formed UTF-16. Your Protocol Buffer will not round trip correctly!", (Throwable) e2);
                byte[] bytes = str.getBytes(C6041.f16935);
                try {
                    mo1450(bytes.length);
                    mo1456(bytes, 0, bytes.length);
                } catch (OutOfSpaceException e3) {
                    throw e3;
                } catch (IndexOutOfBoundsException e4) {
                    throw new OutOfSpaceException(e4);
                }
            }
        }

        @Override // com.google.protobuf.CodedOutputStream
        /* JADX INFO: renamed from: ֏ */
        public final void mo1453(int i, AbstractC6013 abstractC6013) {
            mo1450((i << 3) | 2);
            mo1450(abstractC6013.size());
            AbstractC6013.C6020 c6020 = (AbstractC6013.C6020) abstractC6013;
            mo1456(c6020.f16893, c6020.mo9363(), c6020.size());
        }

        @Override // com.google.protobuf.CodedOutputStream
        /* JADX INFO: renamed from: ֏ */
        public final void mo1454(int i, InterfaceC6049 interfaceC6049) {
            mo1450((i << 3) | 2);
            mo1450(interfaceC6049.mo8729());
            interfaceC6049.mo8728(this);
        }

        @Override // p138.p176.p328.AbstractC6011
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void mo1456(byte[] bArr, int i, int i2) throws OutOfSpaceException {
            try {
                System.arraycopy(bArr, i, this.f2164, this.f2166, i2);
                this.f2166 += i2;
            } catch (IndexOutOfBoundsException e) {
                throw new OutOfSpaceException(String.format("Pos: %d, limit: %d, len: %d", Integer.valueOf(this.f2166), Integer.valueOf(this.f2165), Integer.valueOf(i2)), e);
            }
        }

        @Override // com.google.protobuf.CodedOutputStream
        /* JADX INFO: renamed from: ؠ */
        public final void mo1455(int i, int i2) {
            mo1450((i << 3) | 0);
            mo1450(i2);
        }
    }

    public CodedOutputStream() {
    }

    public /* synthetic */ CodedOutputStream(C0344 c0344) {
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static CodedOutputStream m1440(byte[] bArr) {
        return new C0345(bArr, 0, bArr.length);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static int m1441(int i) {
        return m1447(i) + i;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static int m1442(int i, String str) {
        int length;
        int iM1445 = m1445(i);
        try {
            length = C6065.m9444(str);
        } catch (C6065.C6068 unused) {
            length = str.getBytes(C6041.f16935).length;
        }
        return iM1445 + m1441(length);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static int m1443(int i, AbstractC6013 abstractC6013) {
        return m1445(i) + m1441(abstractC6013.size());
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static int m1444(int i, InterfaceC6049 interfaceC6049) {
        return m1445(i) + m1441(interfaceC6049.mo8729());
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static int m1445(int i) {
        return m1447((i << 3) | 0);
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static int m1446(int i, int i2) {
        return m1445(i) + (i2 >= 0 ? m1447(i2) : 10);
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static int m1447(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;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static int m1448(int i, int i2) {
        return m1447(i2) + m1445(i);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public abstract int mo1449();

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public abstract void mo1450(int i);

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public abstract void mo1451(int i, int i2);

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public abstract void mo1452(int i, String str);

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public abstract void mo1453(int i, AbstractC6013 abstractC6013);

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public abstract void mo1454(int i, InterfaceC6049 interfaceC6049);

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public abstract void mo1455(int i, int i2);
}
