Dominaezzz
05/09/2021, 9:52 PMBen Woodworth
05/09/2021, 11:04 PMinterface MyFormatEncoder : Encoder {
fun encodeMyType(value: MyType)
}
interface CompositeMyFormatEncoder : CompositeEncoder {
fun encodeMyTypeElement(descriptor: SerialDescriptor, index: Int, value: MyType)
}
fun Encoder.asMyFormatEncoder(): MyFormatEncoder =
this as? MyFormatEncoder ?: throw MyEncodingException(
"This serializer can only be used with MyFormat format. " +
"Expected MyFormatEncoder, but got ${this::class}"
)
// And the same for a MyFormatDecoder
Then just a custom serializer that uses encoder.asMyFormatEncoder() when encoding. No annotations, and doesn't matter if it's inlineDominaezzz
05/10/2021, 8:21 AM