jimu-decompiled/sources/com/google/android/gms/internal/measurement/zzya.java
2025-05-13 19:24:51 +02:00

432 lines
15 KiB
Java

package com.google.android.gms.internal.measurement;
import com.ubtrobot.jimu.robotapi.PeripheralType;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;
/* loaded from: classes.dex */
public final class zzya {
private final ByteBuffer a;
private zztv b;
private int c;
private zzya(byte[] bArr, int i, int i2) {
this(ByteBuffer.wrap(bArr, i, i2));
}
public static zzya a(byte[] bArr, int i, int i2) {
return new zzya(bArr, 0, i2);
}
public static int b(long j) {
if (((-128) & j) == 0) {
return 1;
}
if (((-16384) & j) == 0) {
return 2;
}
if (((-2097152) & j) == 0) {
return 3;
}
if (((-268435456) & j) == 0) {
return 4;
}
if (((-34359738368L) & j) == 0) {
return 5;
}
if (((-4398046511104L) & j) == 0) {
return 6;
}
if (((-562949953421312L) & j) == 0) {
return 7;
}
if (((-72057594037927936L) & j) == 0) {
return 8;
}
return (j & Long.MIN_VALUE) == 0 ? 9 : 10;
}
public static zzya b(byte[] bArr) {
return a(bArr, 0, bArr.length);
}
public static int c(int i, long j) {
return b(i) + b(j);
}
public static int d(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;
}
private final void e(int i) throws IOException {
byte b = (byte) i;
if (!this.a.hasRemaining()) {
throw new zzyb(this.a.position(), this.a.limit());
}
this.a.put(b);
}
private zzya(ByteBuffer byteBuffer) {
this.a = byteBuffer;
this.a.order(ByteOrder.LITTLE_ENDIAN);
}
private final zztv b() throws IOException {
if (this.b == null) {
this.b = zztv.a(this.a);
this.c = this.a.position();
} else if (this.c != this.a.position()) {
this.b.b(this.a.array(), this.c, this.a.position() - this.c);
this.c = this.a.position();
}
return this.b;
}
public final void a(int i, double d) throws IOException {
a(i, 1);
long doubleToLongBits = Double.doubleToLongBits(d);
if (this.a.remaining() < 8) {
throw new zzyb(this.a.position(), this.a.limit());
}
this.a.putLong(doubleToLongBits);
}
public static int c(int i, int i2) {
return b(i) + c(i2);
}
public static int c(int i) {
if (i >= 0) {
return d(i);
}
return 10;
}
public final void a(int i, float f) throws IOException {
a(i, 5);
int floatToIntBits = Float.floatToIntBits(f);
if (this.a.remaining() >= 4) {
this.a.putInt(floatToIntBits);
return;
}
throw new zzyb(this.a.position(), this.a.limit());
}
public final void b(int i, long j) throws IOException {
a(i, 0);
a(j);
}
public final void a(int i, long j) throws IOException {
a(i, 0);
a(j);
}
public final void b(int i, int i2) throws IOException {
a(i, 0);
if (i2 >= 0) {
a(i2);
} else {
a(i2);
}
}
public final void a(int i, boolean z) throws IOException {
a(i, 0);
byte b = z ? (byte) 1 : (byte) 0;
if (this.a.hasRemaining()) {
this.a.put(b);
return;
}
throw new zzyb(this.a.position(), this.a.limit());
}
public static int b(int i, String str) {
return b(i) + a(str);
}
public static int b(int i, zzyi zzyiVar) {
int b = b(i);
int b2 = zzyiVar.b();
return b + d(b2) + b2;
}
public final void a(int i, String str) throws IOException {
a(i, 2);
try {
int d = d(str.length());
if (d == d(str.length() * 3)) {
int position = this.a.position();
if (this.a.remaining() >= d) {
this.a.position(position + d);
a(str, this.a);
int position2 = this.a.position();
this.a.position(position);
a((position2 - position) - d);
this.a.position(position2);
return;
}
throw new zzyb(position + d, this.a.limit());
}
a(a((CharSequence) str));
a(str, this.a);
} catch (BufferOverflowException e) {
zzyb zzybVar = new zzyb(this.a.position(), this.a.limit());
zzybVar.initCause(e);
throw zzybVar;
}
}
public static int b(int i) {
return d(i << 3);
}
public final void a(int i, zzyi zzyiVar) throws IOException {
a(i, 2);
a(zzyiVar);
}
public final void a(int i, zzvv zzvvVar) throws IOException {
zztv b = b();
b.a(i, zzvvVar);
b.a();
this.c = this.a.position();
}
private static int a(CharSequence charSequence) {
int length = charSequence.length();
int i = 0;
int i2 = 0;
while (i2 < length && charSequence.charAt(i2) < 128) {
i2++;
}
int i3 = length;
while (true) {
if (i2 >= length) {
break;
}
char charAt = charSequence.charAt(i2);
if (charAt < 2048) {
i3 += (127 - charAt) >>> 31;
i2++;
} else {
int length2 = charSequence.length();
while (i2 < length2) {
char charAt2 = charSequence.charAt(i2);
if (charAt2 < 2048) {
i += (127 - charAt2) >>> 31;
} else {
i += 2;
if (55296 <= charAt2 && charAt2 <= 57343) {
if (Character.codePointAt(charSequence, i2) < 65536) {
StringBuilder sb = new StringBuilder(39);
sb.append("Unpaired surrogate at index ");
sb.append(i2);
throw new IllegalArgumentException(sb.toString());
}
i2++;
}
}
i2++;
}
i3 += i;
}
}
if (i3 >= length) {
return i3;
}
long j = i3 + 4294967296L;
StringBuilder sb2 = new StringBuilder(54);
sb2.append("UTF-8 length does not fit in int: ");
sb2.append(j);
throw new IllegalArgumentException(sb2.toString());
}
private static void a(CharSequence charSequence, ByteBuffer byteBuffer) {
int i;
int i2;
char charAt;
if (!byteBuffer.isReadOnly()) {
int i3 = 0;
if (byteBuffer.hasArray()) {
try {
byte[] array = byteBuffer.array();
int arrayOffset = byteBuffer.arrayOffset() + byteBuffer.position();
int remaining = byteBuffer.remaining();
int length = charSequence.length();
int i4 = remaining + arrayOffset;
while (i3 < length) {
int i5 = i3 + arrayOffset;
if (i5 >= i4 || (charAt = charSequence.charAt(i3)) >= 128) {
break;
}
array[i5] = (byte) charAt;
i3++;
}
if (i3 == length) {
i = arrayOffset + length;
} else {
i = arrayOffset + i3;
while (i3 < length) {
char charAt2 = charSequence.charAt(i3);
if (charAt2 >= 128 || i >= i4) {
if (charAt2 < 2048 && i <= i4 - 2) {
int i6 = i + 1;
array[i] = (byte) ((charAt2 >>> 6) | 960);
i = i6 + 1;
array[i6] = (byte) ((charAt2 & '?') | PeripheralType.SERVO);
} else {
if ((charAt2 >= 55296 && 57343 >= charAt2) || i > i4 - 3) {
if (i <= i4 - 4) {
int i7 = i3 + 1;
if (i7 != charSequence.length()) {
char charAt3 = charSequence.charAt(i7);
if (Character.isSurrogatePair(charAt2, charAt3)) {
int codePoint = Character.toCodePoint(charAt2, charAt3);
int i8 = i + 1;
array[i] = (byte) ((codePoint >>> 18) | 240);
int i9 = i8 + 1;
array[i8] = (byte) (((codePoint >>> 12) & 63) | PeripheralType.SERVO);
int i10 = i9 + 1;
array[i9] = (byte) (((codePoint >>> 6) & 63) | PeripheralType.SERVO);
i = i10 + 1;
array[i10] = (byte) ((codePoint & 63) | PeripheralType.SERVO);
i3 = i7;
} else {
i3 = i7;
}
}
StringBuilder sb = new StringBuilder(39);
sb.append("Unpaired surrogate at index ");
sb.append(i3 - 1);
throw new IllegalArgumentException(sb.toString());
}
StringBuilder sb2 = new StringBuilder(37);
sb2.append("Failed writing ");
sb2.append(charAt2);
sb2.append(" at index ");
sb2.append(i);
throw new ArrayIndexOutOfBoundsException(sb2.toString());
}
int i11 = i + 1;
array[i] = (byte) ((charAt2 >>> '\f') | 480);
int i12 = i11 + 1;
array[i11] = (byte) (((charAt2 >>> 6) & 63) | PeripheralType.SERVO);
i2 = i12 + 1;
array[i12] = (byte) ((charAt2 & '?') | PeripheralType.SERVO);
}
i3++;
} else {
i2 = i + 1;
array[i] = (byte) charAt2;
}
i = i2;
i3++;
}
}
byteBuffer.position(i - byteBuffer.arrayOffset());
return;
} catch (ArrayIndexOutOfBoundsException e) {
BufferOverflowException bufferOverflowException = new BufferOverflowException();
bufferOverflowException.initCause(e);
throw bufferOverflowException;
}
}
int length2 = charSequence.length();
while (i3 < length2) {
char charAt4 = charSequence.charAt(i3);
if (charAt4 < 128) {
byteBuffer.put((byte) charAt4);
} else if (charAt4 < 2048) {
byteBuffer.put((byte) ((charAt4 >>> 6) | 960));
byteBuffer.put((byte) ((charAt4 & '?') | PeripheralType.SERVO));
} else {
if (charAt4 >= 55296 && 57343 >= charAt4) {
int i13 = i3 + 1;
if (i13 != charSequence.length()) {
char charAt5 = charSequence.charAt(i13);
if (Character.isSurrogatePair(charAt4, charAt5)) {
int codePoint2 = Character.toCodePoint(charAt4, charAt5);
byteBuffer.put((byte) ((codePoint2 >>> 18) | 240));
byteBuffer.put((byte) (((codePoint2 >>> 12) & 63) | PeripheralType.SERVO));
byteBuffer.put((byte) (((codePoint2 >>> 6) & 63) | PeripheralType.SERVO));
byteBuffer.put((byte) ((codePoint2 & 63) | PeripheralType.SERVO));
i3 = i13;
} else {
i3 = i13;
}
}
StringBuilder sb3 = new StringBuilder(39);
sb3.append("Unpaired surrogate at index ");
sb3.append(i3 - 1);
throw new IllegalArgumentException(sb3.toString());
}
byteBuffer.put((byte) ((charAt4 >>> '\f') | 480));
byteBuffer.put((byte) (((charAt4 >>> 6) & 63) | PeripheralType.SERVO));
byteBuffer.put((byte) ((charAt4 & '?') | PeripheralType.SERVO));
}
i3++;
}
return;
}
throw new ReadOnlyBufferException();
}
public final void a(zzyi zzyiVar) throws IOException {
a(zzyiVar.d());
zzyiVar.a(this);
}
public static int a(String str) {
int a = a((CharSequence) str);
return d(a) + a;
}
public final void a() {
if (this.a.remaining() != 0) {
throw new IllegalStateException(String.format("Did not write as much data as expected, %s bytes remaining.", Integer.valueOf(this.a.remaining())));
}
}
public final void a(byte[] bArr) throws IOException {
int length = bArr.length;
if (this.a.remaining() >= length) {
this.a.put(bArr, 0, length);
return;
}
throw new zzyb(this.a.position(), this.a.limit());
}
public final void a(int i, int i2) throws IOException {
a((i << 3) | i2);
}
public final void a(int i) throws IOException {
while ((i & (-128)) != 0) {
e((i & 127) | PeripheralType.SERVO);
i >>>= 7;
}
e(i);
}
private final void a(long j) throws IOException {
while (((-128) & j) != 0) {
e((((int) j) & 127) | PeripheralType.SERVO);
j >>>= 7;
}
e((int) j);
}
}