package com.czhj.wire; import com.czhj.wire.Message; import com.czhj.wire.WireField; import com.czhj.wire.okio.Buffer; import com.czhj.wire.okio.BufferedSink; import com.czhj.wire.okio.BufferedSource; import com.czhj.wire.okio.ByteString; import com.czhj.wire.okio.Okio; import com.czhj.wire.okio.Utf8; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Collections; import java.util.List; import java.util.Map; public abstract class ProtoAdapter<E> { public static final ProtoAdapter<Boolean> BOOL = new ProtoAdapter<Boolean>(FieldEncoding.VARINT, Boolean.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass1 */ @Override // com.czhj.wire.ProtoAdapter public Boolean decode(ProtoReader protoReader) throws IOException { int readVarint32 = protoReader.readVarint32(); if (readVarint32 == 0) { return Boolean.FALSE; } if (readVarint32 == 1) { return Boolean.TRUE; } throw new IOException(String.format("Invalid boolean value 0x%02x", Integer.valueOf(readVarint32))); } public void encode(ProtoWriter protoWriter, Boolean bool) throws IOException { protoWriter.writeVarint32(bool.booleanValue() ? 1 : 0); } public int encodedSize(Boolean bool) { return 1; } }; public static final ProtoAdapter<ByteString> BYTES = new ProtoAdapter<ByteString>(FieldEncoding.LENGTH_DELIMITED, ByteString.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass13 */ @Override // com.czhj.wire.ProtoAdapter public ByteString decode(ProtoReader protoReader) throws IOException { return protoReader.readBytes(); } public void encode(ProtoWriter protoWriter, ByteString byteString) throws IOException { protoWriter.writeBytes(byteString); } public int encodedSize(ByteString byteString) { return byteString.size(); } }; public static final ProtoAdapter<Double> DOUBLE = new ProtoAdapter<Double>(FieldEncoding.FIXED64, Double.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass11 */ @Override // com.czhj.wire.ProtoAdapter public Double decode(ProtoReader protoReader) throws IOException { return Double.valueOf(Double.longBitsToDouble(protoReader.readFixed64())); } public void encode(ProtoWriter protoWriter, Double d) throws IOException { protoWriter.writeFixed64(Double.doubleToLongBits(d.doubleValue())); } public int encodedSize(Double d) { return 8; } }; public static final ProtoAdapter<Integer> FIXED32; public static final ProtoAdapter<Long> FIXED64; private static final int FIXED_32_SIZE = 4; private static final int FIXED_64_SIZE = 8; private static final int FIXED_BOOL_SIZE = 1; public static final ProtoAdapter<Float> FLOAT = new ProtoAdapter<Float>(FieldEncoding.FIXED32, Float.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass10 */ @Override // com.czhj.wire.ProtoAdapter public Float decode(ProtoReader protoReader) throws IOException { return Float.valueOf(Float.intBitsToFloat(protoReader.readFixed32())); } public void encode(ProtoWriter protoWriter, Float f) throws IOException { protoWriter.writeFixed32(Float.floatToIntBits(f.floatValue())); } public int encodedSize(Float f) { return 4; } }; public static final ProtoAdapter<Integer> INT32 = new ProtoAdapter<Integer>(FieldEncoding.VARINT, Integer.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass2 */ @Override // com.czhj.wire.ProtoAdapter public Integer decode(ProtoReader protoReader) throws IOException { return Integer.valueOf(protoReader.readVarint32()); } public void encode(ProtoWriter protoWriter, Integer num) throws IOException { protoWriter.f(num.intValue()); } public int encodedSize(Integer num) { return ProtoWriter.b(num.intValue()); } }; public static final ProtoAdapter<Long> INT64 = new ProtoAdapter<Long>(FieldEncoding.VARINT, Long.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass6 */ @Override // com.czhj.wire.ProtoAdapter public Long decode(ProtoReader protoReader) throws IOException { return Long.valueOf(protoReader.readVarint64()); } public void encode(ProtoWriter protoWriter, Long l) throws IOException { protoWriter.writeVarint64(l.longValue()); } public int encodedSize(Long l) { return ProtoWriter.a(l.longValue()); } }; public static final ProtoAdapter<Integer> SFIXED32; public static final ProtoAdapter<Long> SFIXED64; public static final ProtoAdapter<Integer> SINT32 = new ProtoAdapter<Integer>(FieldEncoding.VARINT, Integer.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass4 */ @Override // com.czhj.wire.ProtoAdapter public Integer decode(ProtoReader protoReader) throws IOException { return Integer.valueOf(ProtoWriter.e(protoReader.readVarint32())); } public void encode(ProtoWriter protoWriter, Integer num) throws IOException { protoWriter.writeVarint32(ProtoWriter.d(num.intValue())); } public int encodedSize(Integer num) { return ProtoWriter.c(ProtoWriter.d(num.intValue())); } }; public static final ProtoAdapter<Long> SINT64 = new ProtoAdapter<Long>(FieldEncoding.VARINT, Long.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass8 */ @Override // com.czhj.wire.ProtoAdapter public Long decode(ProtoReader protoReader) throws IOException { return Long.valueOf(ProtoWriter.c(protoReader.readVarint64())); } public void encode(ProtoWriter protoWriter, Long l) throws IOException { protoWriter.writeVarint64(ProtoWriter.b(l.longValue())); } public int encodedSize(Long l) { return ProtoWriter.a(ProtoWriter.b(l.longValue())); } }; public static final ProtoAdapter<String> STRING = new ProtoAdapter<String>(FieldEncoding.LENGTH_DELIMITED, String.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass12 */ @Override // com.czhj.wire.ProtoAdapter public String decode(ProtoReader protoReader) throws IOException { return protoReader.readString(); } public void encode(ProtoWriter protoWriter, String str) throws IOException { protoWriter.writeString(str); } public int encodedSize(String str) { return (int) Utf8.size(str); } }; public static final ProtoAdapter<Integer> UINT32 = new ProtoAdapter<Integer>(FieldEncoding.VARINT, Integer.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass3 */ @Override // com.czhj.wire.ProtoAdapter public Integer decode(ProtoReader protoReader) throws IOException { return Integer.valueOf(protoReader.readVarint32()); } public void encode(ProtoWriter protoWriter, Integer num) throws IOException { protoWriter.writeVarint32(num.intValue()); } public int encodedSize(Integer num) { return ProtoWriter.c(num.intValue()); } }; public static final ProtoAdapter<Long> UINT64 = new ProtoAdapter<Long>(FieldEncoding.VARINT, Long.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass7 */ @Override // com.czhj.wire.ProtoAdapter public Long decode(ProtoReader protoReader) throws IOException { return Long.valueOf(protoReader.readVarint64()); } public void encode(ProtoWriter protoWriter, Long l) throws IOException { protoWriter.writeVarint64(l.longValue()); } public int encodedSize(Long l) { return ProtoWriter.a(l.longValue()); } }; private final FieldEncoding fieldEncoding; final Class<?> javaType; ProtoAdapter<List<E>> packedAdapter; ProtoAdapter<List<E>> repeatedAdapter; public static final class EnumConstantNotFoundException extends IllegalArgumentException { public final int value; public EnumConstantNotFoundException(int i, Class<?> cls) { super("Unknown enum tag " + i + " for " + cls.getCanonicalName()); this.value = i; } } /* access modifiers changed from: private */ public static final class MapEntryProtoAdapter<K, V> extends ProtoAdapter<Map.Entry<K, V>> { final ProtoAdapter<K> a; final ProtoAdapter<V> b; MapEntryProtoAdapter(ProtoAdapter<K> protoAdapter, ProtoAdapter<V> protoAdapter2) { super(FieldEncoding.LENGTH_DELIMITED, Map.Entry.class); this.a = protoAdapter; this.b = protoAdapter2; } @Override // com.czhj.wire.ProtoAdapter public Map.Entry<K, V> decode(ProtoReader protoReader) { throw new UnsupportedOperationException(); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ void encode(ProtoWriter protoWriter, Object obj) throws IOException { encode(protoWriter, (Map.Entry) ((Map.Entry) obj)); } public void encode(ProtoWriter protoWriter, Map.Entry<K, V> entry) throws IOException { this.a.encodeWithTag(protoWriter, 1, entry.getKey()); this.b.encodeWithTag(protoWriter, 2, entry.getValue()); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ int encodedSize(Object obj) { return encodedSize((Map.Entry) ((Map.Entry) obj)); } public int encodedSize(Map.Entry<K, V> entry) { return this.a.encodedSizeWithTag(1, entry.getKey()) + this.b.encodedSizeWithTag(2, entry.getValue()); } } private static final class MapProtoAdapter<K, V> extends ProtoAdapter<Map<K, V>> { private final MapEntryProtoAdapter<K, V> a; MapProtoAdapter(ProtoAdapter<K> protoAdapter, ProtoAdapter<V> protoAdapter2) { super(FieldEncoding.LENGTH_DELIMITED, Map.class); this.a = new MapEntryProtoAdapter<>(protoAdapter, protoAdapter2); } @Override // com.czhj.wire.ProtoAdapter public Map<K, V> decode(ProtoReader protoReader) throws IOException { long beginMessage = protoReader.beginMessage(); K k = null; V v = null; while (true) { int nextTag = protoReader.nextTag(); if (nextTag == -1) { break; } else if (nextTag == 1) { k = this.a.a.decode(protoReader); } else if (nextTag == 2) { v = this.a.b.decode(protoReader); } } protoReader.endMessage(beginMessage); if (k == null) { throw new IllegalStateException("Map entry with null key"); } else if (v != null) { return Collections.singletonMap(k, v); } else { throw new IllegalStateException("Map entry with null value"); } } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ void encode(ProtoWriter protoWriter, Object obj) throws IOException { encode(protoWriter, (Map) ((Map) obj)); } public void encode(ProtoWriter protoWriter, Map<K, V> map) { throw new UnsupportedOperationException("Repeated values can only be encoded with a tag."); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ void encodeWithTag(ProtoWriter protoWriter, int i, Object obj) throws IOException { encodeWithTag(protoWriter, i, (Map) ((Map) obj)); } public void encodeWithTag(ProtoWriter protoWriter, int i, Map<K, V> map) throws IOException { for (Map.Entry<K, V> entry : map.entrySet()) { this.a.encodeWithTag(protoWriter, i, entry); } } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ int encodedSize(Object obj) { return encodedSize((Map) ((Map) obj)); } public int encodedSize(Map<K, V> map) { throw new UnsupportedOperationException("Repeated values can only be sized with a tag."); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ int encodedSizeWithTag(int i, Object obj) { return encodedSizeWithTag(i, (Map) ((Map) obj)); } public int encodedSizeWithTag(int i, Map<K, V> map) { int i2 = 0; for (Map.Entry<K, V> entry : map.entrySet()) { i2 += this.a.encodedSizeWithTag(i, entry); } return i2; } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ Object redact(Object obj) { return redact((Map) ((Map) obj)); } public Map<K, V> redact(Map<K, V> map) { return Collections.emptyMap(); } } static { AnonymousClass5 r0 = new ProtoAdapter<Integer>(FieldEncoding.FIXED32, Integer.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass5 */ @Override // com.czhj.wire.ProtoAdapter public Integer decode(ProtoReader protoReader) throws IOException { return Integer.valueOf(protoReader.readFixed32()); } public void encode(ProtoWriter protoWriter, Integer num) throws IOException { protoWriter.writeFixed32(num.intValue()); } public int encodedSize(Integer num) { return 4; } }; FIXED32 = r0; SFIXED32 = r0; AnonymousClass9 r02 = new ProtoAdapter<Long>(FieldEncoding.FIXED64, Long.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass9 */ @Override // com.czhj.wire.ProtoAdapter public Long decode(ProtoReader protoReader) throws IOException { return Long.valueOf(protoReader.readFixed64()); } public void encode(ProtoWriter protoWriter, Long l) throws IOException { protoWriter.writeFixed64(l.longValue()); } public int encodedSize(Long l) { return 8; } }; FIXED64 = r02; SFIXED64 = r02; } public ProtoAdapter(FieldEncoding fieldEncoding2, Class<?> cls) { this.fieldEncoding = fieldEncoding2; this.javaType = cls; } private ProtoAdapter<List<E>> createPacked() { if (this.fieldEncoding != FieldEncoding.LENGTH_DELIMITED) { return new ProtoAdapter<List<E>>(FieldEncoding.LENGTH_DELIMITED, List.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass14 */ @Override // com.czhj.wire.ProtoAdapter public List<E> decode(ProtoReader protoReader) throws IOException { return Collections.singletonList(ProtoAdapter.this.decode(protoReader)); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ void encode(ProtoWriter protoWriter, Object obj) throws IOException { encode(protoWriter, (List) ((List) obj)); } public void encode(ProtoWriter protoWriter, List<E> list) throws IOException { int size = list.size(); for (int i = 0; i < size; i++) { ProtoAdapter.this.encode(protoWriter, list.get(i)); } } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ void encodeWithTag(ProtoWriter protoWriter, int i, Object obj) throws IOException { encodeWithTag(protoWriter, i, (List) ((List) obj)); } public void encodeWithTag(ProtoWriter protoWriter, int i, List<E> list) throws IOException { if (!list.isEmpty()) { ProtoAdapter.super.encodeWithTag(protoWriter, i, (Object) list); } } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ int encodedSize(Object obj) { return encodedSize((List) ((List) obj)); } public int encodedSize(List<E> list) { int size = list.size(); int i = 0; for (int i2 = 0; i2 < size; i2++) { i += ProtoAdapter.this.encodedSize(list.get(i2)); } return i; } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ int encodedSizeWithTag(int i, Object obj) { return encodedSizeWithTag(i, (List) ((List) obj)); } public int encodedSizeWithTag(int i, List<E> list) { if (list.isEmpty()) { return 0; } return ProtoAdapter.super.encodedSizeWithTag(i, (Object) list); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ Object redact(Object obj) { return redact((List) ((List) obj)); } public List<E> redact(List<E> list) { return Collections.emptyList(); } }; } throw new IllegalArgumentException("Unable to pack a length-delimited type."); } private ProtoAdapter<List<E>> createRepeated() { return new ProtoAdapter<List<E>>(this.fieldEncoding, List.class) { /* class com.czhj.wire.ProtoAdapter.AnonymousClass15 */ @Override // com.czhj.wire.ProtoAdapter public List<E> decode(ProtoReader protoReader) throws IOException { return Collections.singletonList(ProtoAdapter.this.decode(protoReader)); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ void encode(ProtoWriter protoWriter, Object obj) throws IOException { encode(protoWriter, (List) ((List) obj)); } public void encode(ProtoWriter protoWriter, List<E> list) { throw new UnsupportedOperationException("Repeated values can only be encoded with a tag."); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ void encodeWithTag(ProtoWriter protoWriter, int i, Object obj) throws IOException { encodeWithTag(protoWriter, i, (List) ((List) obj)); } public void encodeWithTag(ProtoWriter protoWriter, int i, List<E> list) throws IOException { int size = list.size(); for (int i2 = 0; i2 < size; i2++) { ProtoAdapter.this.encodeWithTag(protoWriter, i, list.get(i2)); } } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ int encodedSize(Object obj) { return encodedSize((List) ((List) obj)); } public int encodedSize(List<E> list) { throw new UnsupportedOperationException("Repeated values can only be sized with a tag."); } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ int encodedSizeWithTag(int i, Object obj) { return encodedSizeWithTag(i, (List) ((List) obj)); } public int encodedSizeWithTag(int i, List<E> list) { int size = list.size(); int i2 = 0; for (int i3 = 0; i3 < size; i3++) { i2 += ProtoAdapter.this.encodedSizeWithTag(i, list.get(i3)); } return i2; } @Override // com.czhj.wire.ProtoAdapter public /* bridge */ /* synthetic */ Object redact(Object obj) { return redact((List) ((List) obj)); } public List<E> redact(List<E> list) { return Collections.emptyList(); } }; } public static <M extends Message> ProtoAdapter<M> get(M m) { return get(m.getClass()); } public static <M> ProtoAdapter<M> get(Class<M> cls) { try { return (ProtoAdapter) cls.getField("ADAPTER").get(null); } catch (Throwable th) { throw new IllegalArgumentException("failed to access " + cls.getName() + "#ADAPTER", th); } } public static ProtoAdapter<?> get(String str) { try { int indexOf = str.indexOf(35); String substring = str.substring(0, indexOf); return (ProtoAdapter) Class.forName(substring).getField(str.substring(indexOf + 1)).get(null); } catch (Throwable th) { throw new IllegalArgumentException("failed to access " + str, th); } } public static <E extends WireEnum> RuntimeEnumAdapter<E> newEnumAdapter(Class<E> cls) { return new RuntimeEnumAdapter<>(cls); } public static <K, V> ProtoAdapter<Map<K, V>> newMapAdapter(ProtoAdapter<K> protoAdapter, ProtoAdapter<V> protoAdapter2) { return new MapProtoAdapter(protoAdapter, protoAdapter2); } public static <M extends Message<M, B>, B extends Message.Builder<M, B>> ProtoAdapter<M> newMessageAdapter(Class<M> cls) { return RuntimeMessageAdapter.a(cls); } public final ProtoAdapter<List<E>> asPacked() { ProtoAdapter<List<E>> protoAdapter = this.packedAdapter; if (protoAdapter != null) { return protoAdapter; } ProtoAdapter<List<E>> createPacked = createPacked(); this.packedAdapter = createPacked; return createPacked; } public final ProtoAdapter<List<E>> asRepeated() { ProtoAdapter<List<E>> protoAdapter = this.repeatedAdapter; if (protoAdapter != null) { return protoAdapter; } ProtoAdapter<List<E>> createRepeated = createRepeated(); this.repeatedAdapter = createRepeated; return createRepeated; } public abstract E decode(ProtoReader protoReader) throws IOException; public final E decode(BufferedSource bufferedSource) throws IOException { Preconditions.a(bufferedSource, "source == null"); return decode(new ProtoReader(bufferedSource)); } public final E decode(ByteString byteString) throws IOException { Preconditions.a(byteString, "bytes == null"); return decode(new Buffer().write(byteString)); } public final E decode(InputStream inputStream) throws IOException { Preconditions.a(inputStream, "stream == null"); return decode(Okio.buffer(Okio.source(inputStream))); } public final E decode(byte[] bArr) throws IOException { Preconditions.a(bArr, "bytes == null"); return decode(new Buffer().write(bArr)); } public abstract void encode(ProtoWriter protoWriter, E e) throws IOException; public final void encode(BufferedSink bufferedSink, E e) throws IOException { Preconditions.a(e, "value == null"); Preconditions.a(bufferedSink, "sink == null"); encode(new ProtoWriter(bufferedSink), e); } public final void encode(OutputStream outputStream, E e) throws IOException { Preconditions.a(e, "value == null"); Preconditions.a(outputStream, "stream == null"); BufferedSink buffer = Okio.buffer(Okio.sink(outputStream)); encode(buffer, e); buffer.emit(); } public final byte[] encode(E e) { Preconditions.a(e, "value == null"); Buffer buffer = new Buffer(); try { encode(buffer, e); return buffer.readByteArray(); } catch (IOException e2) { throw new AssertionError(e2); } } public void encodeWithTag(ProtoWriter protoWriter, int i, E e) throws IOException { if (e != null) { protoWriter.writeTag(i, this.fieldEncoding); if (this.fieldEncoding == FieldEncoding.LENGTH_DELIMITED) { protoWriter.writeVarint32(encodedSize(e)); } encode(protoWriter, e); } } public abstract int encodedSize(E e); public int encodedSizeWithTag(int i, E e) { if (e == null) { return 0; } int encodedSize = encodedSize(e); if (this.fieldEncoding == FieldEncoding.LENGTH_DELIMITED) { encodedSize += ProtoWriter.c(encodedSize); } return encodedSize + ProtoWriter.a(i); } public E redact(E e) { return null; } public String toString(E e) { return e.toString(); } /* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: com.czhj.wire.ProtoAdapter<E> */ /* JADX WARN: Multi-variable type inference failed */ /* access modifiers changed from: package-private */ public ProtoAdapter<?> withLabel(WireField.Label label) { return label.a() ? label.b() ? asPacked() : asRepeated() : this; } }