This page summarizes how to use FastProto on Android.
FastProto.decode(...) and FastProto.encode(...)FastProto provides compile-time support for lambda formulas so @DecodingFormula(lambda = "...") and @EncodingFormula(lambda = "...") remain Android-friendly.
Android projects can use the fastproto dependency directly. If you use lambda formulas, make sure annotation processing is enabled in your build.
Gradle (Kotlin DSL):
dependencies {
implementation("org.indunet:fastproto:4.1.0")
}Gradle (Groovy DSL):
dependencies {
implementation 'org.indunet:fastproto:4.1.0'
}Maven (Android):
<dependency>
<groupId>org.indunet</groupId>
<artifactId>fastproto</artifactId>
<version>4.1.0</version>
</dependency>The annotation processor scans your code at compile time and generates Function implementation classes for each lambda expression. These generated classes are included in your APK and used at runtime instead of dynamic compilation.
For example, this annotation:
@Int16Type(offset = 0)
@DecodingFormula(lambda = "x -> x * 0.1")
private double temperature;Generates a class like:
public class YourClass_temperature_DecodingFormula implements Function<Integer, Object> {
@Override
public Object apply(Integer x) {
return x * 0.1;
}
}You can also use custom function classes directly without relying on the annotation processor:
public class TemperatureFormula implements Function<Integer, Double> {
@Override
public Double apply(Integer value) {
return value * 0.1;
}
}
public class SensorData {
@Int16Type(offset = 0)
@DecodingFormula(TemperatureFormula.class)
private double temperature;
}java.sql.Timestamp is not part of Android standard APIs
java.sql.* will not work. Prefer long epoch millis or java.time.* (with desugaring) instead.long (epoch millis) or java.time.Instant/LocalDateTime.java.time.* on older Android.com.android.tools:desugar_jdk_libs-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations, Signature, InnerClasses, EnclosingMethod
-keep class org.indunet.fastproto.annotation.** { *; }
-keep class org.indunet.fastproto.formula.generated.** { *; }@DecodingFormula(lambda = "...") or @EncodingFormula(lambda = "..."), yes. If you only use class-based formulas like @DecodingFormula(MyFormula.class), the annotation processor is optional.