ref: 717e18b931e82fe600f5f8fb98869623a34d4790
app/src/main/java/xyz/apiote/bimba/czwek/api/responses/Line.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 |
// 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.responses.UnknownResponseVersion import xyz.apiote.fruchtfleisch.Reader import java.io.InputStream interface LineResponse { companion object { fun unmarshal(stream: InputStream): LineResponse { val reader = Reader(stream) return when (val v = reader.readUInt().toULong()) { 0UL -> LineResponseDev.unmarshal(stream) 1UL -> LineResponseV1.unmarshal(stream) 2UL -> LineResponseV2.unmarshal(stream) else -> throw UnknownResponseVersion("Line", v) } } } } data class LineResponseDev( val line: LineV2 ) : LineResponse { companion object { fun unmarshal(stream: InputStream): LineResponseDev { return LineResponseDev(LineV2.unmarshal(stream)) } } } data class LineResponseV2( val line: LineV2 ) : LineResponse { companion object { fun unmarshal(stream: InputStream): LineResponseDev { return LineResponseDev(LineV2.unmarshal(stream)) } } } data class LineResponseV1( val line: LineV1 ) : LineResponse { companion object { fun unmarshal(stream: InputStream): LineResponseV1 { return LineResponseV1(LineV1.unmarshal(stream)) } } } |