I've got this data class which works for my data, ...
# serialization
z
I've got this data class which works for my data, but I wanna change it up some so its easier to work with. I need to make it so a value of
1
represents it being present, and if its null then its not present. That way it can just be a list of the present `Feature`s
Copy code
@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class SearchFilter(
    val sortBy: SortBy? = null,
    val filters: List<Filter>
) {
    @Serializable
    data class Filter(
        val uploadDate: UploadDate? = null, // ignore these
        val type: Type? = null, // ignore these
        val duration: Duration? = null, // ignore these
        val hd: Int? = null,
        @ProtoNumber(14)
        val uhd: Int? = null,
        val subtitles: Int? = null,
        val creativeCommons: Int? = null,
        @ProtoNumber(15)
        val spherical: Int? = null,
        @ProtoNumber(26)
        val vr: Int? = null
    )
}

@Serializable
enum class Feature {
    LIVE,
    UHD,
    HD,
    SUBTITLES,
    CREATIVE_COMMONS,
    /** 360° video */
    SPHERICAL,
    VR
}
d
Definitely custom serializer territory.
You want to use the external serializer feature, to generate the default serializer, which will give a descriptor that "just works".
Then you can use this descriptor in your custom serializer to loop through the fields in protobuf.
e