ref: 1c43831d9d4fa397acce499a6919fbc43e54013a
app/src/debug/java/xyz/apiote/bimba/czwek/api/responses/DevResponses.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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
// 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.AlertV1 import xyz.apiote.bimba.czwek.api.DepartureV4 import xyz.apiote.bimba.czwek.api.LineV3 import xyz.apiote.bimba.czwek.api.LocatableV3 import xyz.apiote.bimba.czwek.api.QueryableV4 import xyz.apiote.bimba.czwek.api.StopV2 import xyz.apiote.bimba.czwek.api.UnknownResourceVersionException import xyz.apiote.bimba.czwek.api.VehicleV3 import xyz.apiote.bimba.czwek.api.structs.FeedInfoV2 import xyz.apiote.fruchtfleisch.Reader import java.io.InputStream data class DeparturesResponseDev( val alerts: List<AlertV1>, val departures: List<DepartureV4>, val stop: StopV2 ) : DeparturesResponse { companion object { fun unmarshal(stream: InputStream): DeparturesResponseDev { val alerts = mutableListOf<AlertV1>() val departures = mutableListOf<DepartureV4>() val reader = Reader(stream) val alertsNum = reader.readUInt().toULong() for (i in 0UL until alertsNum) { val alert = AlertV1.unmarshal(stream) alerts.add(alert) } val departuresNum = reader.readUInt().toULong() for (i in 0UL until departuresNum) { val departure = DepartureV4.unmarshal(stream) departures.add(departure) } return DeparturesResponseDev(alerts, departures, StopV2.unmarshal(stream)) } } } data class FeedsResponseDev( 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 LineResponseDev( val line: LineV3 ) : LineResponse { companion object { fun unmarshal(stream: InputStream): LineResponseDev { return LineResponseDev(LineV3.unmarshal(stream)) } } } data class LocatablesResponseDev(val locatables: List<LocatableV3>) : LocatablesResponse { companion object { fun unmarshal(stream: InputStream): LocatablesResponseDev { val locatables = mutableListOf<LocatableV3>() val reader = Reader(stream) val n = reader.readUInt().toULong() for (i in 0UL until n) { when (val r = reader.readUInt().toULong()) { 0UL -> { locatables.add(StopV2.unmarshal(stream)) } 1UL -> { locatables.add(VehicleV3.unmarshal(stream)) } else -> { throw UnknownResourceVersionException("Locatable/$r", 0u) } } } return LocatablesResponseDev(locatables) } } } data class QueryablesResponseDev(val queryables: List<QueryableV4>) : QueryablesResponse { companion object { fun unmarshal(stream: InputStream): QueryablesResponseDev { val queryables = mutableListOf<QueryableV4>() val reader = Reader(stream) val n = reader.readUInt().toULong() for (i in 0UL until n) { when (val r = reader.readUInt().toULong()) { 0UL -> { queryables.add(StopV2.unmarshal(stream)) } 1UL -> { queryables.add(LineV3.unmarshal(stream)) } else -> { throw UnknownResourceVersionException("Queryable/$r", 0u) } } } return QueryablesResponseDev(queryables) } } } |