diff --git a/src/com/squareup/wire/EnumAdapter.java b/src/com/squareup/wire/EnumAdapter.java new file mode 100644 index 0000000..e39c720 --- /dev/null +++ b/src/com/squareup/wire/EnumAdapter.java @@ -0,0 +1,37 @@ +package com.squareup.wire; + +import java.io.IOException; + +/** + * Compatibility shim. The stock light_camera APK's generated {@code ltpb} enum adapters + * (e.g. {@code ViewPreferences$AspectRatio$ProtoAdapter_AspectRatio}) extend + * {@code com.squareup.wire.EnumAdapter} and call its {@code (Class)} constructor + override + * {@code fromValue(int)}. That abstract base class is NOT present in any released + * wire-runtime 2.0.0–2.2.0 (which ship the reflection-based {@code RuntimeEnumAdapter} instead), + * so {@code download-libs.sh}'s wire-runtime-2.2.0 lacks it and the adapters fail to link at + * runtime ({@code NoClassDefFoundError} during the first capture's image-save path). + * + * This restores the small abstract base, implemented on top of 2.2.0's {@link ProtoAdapter} + * exactly like {@code RuntimeEnumAdapter}: an enum is wire-encoded as a VARINT of its value. + */ +public abstract class EnumAdapter extends ProtoAdapter { + protected EnumAdapter(Class type) { + super(FieldEncoding.VARINT, type); + } + + /** Subclasses (generated {@code ProtoAdapter_*}) map a proto int back to the enum constant. */ + protected abstract E fromValue(int value); + + @Override public int encodedSize(E value) { + return ProtoWriter.varint32Size(value.getValue()); + } + + @Override public void encode(ProtoWriter writer, E value) throws IOException { + writer.writeVarint32(value.getValue()); + } + + @Override public E decode(ProtoReader reader) throws IOException { + int value = reader.readVarint32(); + return fromValue(value); + } +}