ref: v3.7.0
app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Feeds.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
// SPDX-FileCopyrightText: Adam Evyčędo // // SPDX-License-Identifier: GPL-3.0-or-later package xyz.apiote.bimba.czwek.api.responses import xyz.apiote.bimba.czwek.api.structs.FeedInfoV1 import xyz.apiote.bimba.czwek.api.structs.FeedInfoV2 import xyz.apiote.fruchtfleisch.Reader import java.io.InputStream interface FeedsResponse { companion object { fun unmarshal(stream: InputStream): FeedsResponse { val reader = Reader(stream) return when (val v = reader.readUInt().toULong()) { // 0UL -> FeedsResponseDev.unmarshal(stream) 1UL -> FeedsResponseV1.unmarshal(stream) 2UL -> FeedsResponseV2.unmarshal(stream) else -> throw UnknownResponseVersion("Feeds", v) } } } } data class FeedsResponseV2( val feeds: List<FeedInfoV2> ) : FeedsResponse { companion object { fun unmarshal(stream: InputStream): FeedsResponseDev { val feeds = mutableListOf<FeedInfoV2>() val reader = Reader(stream) val n = reader.readUInt().toULong() for (i in 0UL until n) { feeds.add(FeedInfoV2.unmarshal(stream)) } return FeedsResponseDev(feeds) } } } data class FeedsResponseV1( val feeds: List<FeedInfoV1> ) : FeedsResponse { companion object { fun unmarshal(stream: InputStream): FeedsResponseV1 { val feeds = mutableListOf<FeedInfoV1>() val reader = Reader(stream) val n = reader.readUInt().toULong() for (i in 0UL until n) { feeds.add(FeedInfoV1.unmarshal(stream)) } return FeedsResponseV1(feeds) } } } |