ref: 68ae37f62658ef2b5dfe364bfa283d03b4f35951
app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Queryables.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 124 125 126 127 128 129 130 131 132 |
// 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.LineV1 import xyz.apiote.bimba.czwek.api.LineV2 import xyz.apiote.bimba.czwek.api.QueryableV1 import xyz.apiote.bimba.czwek.api.QueryableV2 import xyz.apiote.bimba.czwek.api.QueryableV3 import xyz.apiote.bimba.czwek.api.StopV1 import xyz.apiote.bimba.czwek.api.StopV2 import xyz.apiote.bimba.czwek.api.UnknownResourceVersionException import xyz.apiote.bimba.czwek.api.responses.UnknownResponseVersion import xyz.apiote.fruchtfleisch.Reader import java.io.InputStream interface QueryablesResponse { companion object { fun unmarshal(stream: InputStream): QueryablesResponse { val reader = Reader(stream) return when (val v = reader.readUInt().toULong()) { 0UL -> QueryablesResponseDev.unmarshal(stream) 1UL -> QueryablesResponseV1.unmarshal(stream) 2UL -> QueryablesResponseV2.unmarshal(stream) 3UL -> QueryablesResponseV3.unmarshal(stream) else -> throw UnknownResponseVersion("Queryables", v) } } } } data class QueryablesResponseDev(val queryables: List<QueryableV3>) : QueryablesResponse { companion object { fun unmarshal(stream: InputStream): QueryablesResponseDev { val queryables = mutableListOf<QueryableV3>() 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(LineV2.unmarshal(stream)) } else -> { throw UnknownResourceVersionException("Queryable/$r", 0u) } } } return QueryablesResponseDev(queryables) } } } data class QueryablesResponseV3(val queryables: List<QueryableV3>) : QueryablesResponse { companion object { fun unmarshal(stream: InputStream): QueryablesResponseDev { val queryables = mutableListOf<QueryableV3>() 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(LineV2.unmarshal(stream)) } else -> { throw UnknownResourceVersionException("Queryable/$r", 0u) } } } return QueryablesResponseDev(queryables) } } } data class QueryablesResponseV2(val queryables: List<QueryableV2>) : QueryablesResponse { companion object { fun unmarshal(stream: InputStream): QueryablesResponseV2 { val queryables = mutableListOf<QueryableV2>() 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(LineV1.unmarshal(stream)) } else -> { throw UnknownResourceVersionException("Queryable/$r", 2u) } } } return QueryablesResponseV2(queryables) } } } data class QueryablesResponseV1(val queryables: List<QueryableV1>) : QueryablesResponse { companion object { fun unmarshal(stream: InputStream): QueryablesResponseV1 { val queryables = mutableListOf<QueryableV1>() val reader = Reader(stream) val n = reader.readUInt().toULong() for (i in 0UL until n) { when (val r = reader.readUInt().toULong()) { 0UL -> { queryables.add(StopV1.unmarshal(stream)) } else -> { throw UnknownResourceVersionException("Queryable/$r", 1u) } } } return QueryablesResponseV1(queryables) } } } |