From 65556569547913faaa403c33ad1fe7b06ca178f0 Mon Sep 17 00:00:00 2001 From: Kazik Pogoda Date: Fri, 6 Sep 2024 15:51:13 +0200 Subject: [PATCH] add JvmAndNativeOscTypeTags.kt --- .../src/jvmAndNativeMain/kotlin/Package.kt | 19 +++++++++ .../kotlin/type/JvmAndNativeOscTypeTags.kt | 40 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 xemantic-osc-api/src/jvmAndNativeMain/kotlin/Package.kt create mode 100644 xemantic-osc-api/src/jvmAndNativeMain/kotlin/type/JvmAndNativeOscTypeTags.kt diff --git a/xemantic-osc-api/src/jvmAndNativeMain/kotlin/Package.kt b/xemantic-osc-api/src/jvmAndNativeMain/kotlin/Package.kt new file mode 100644 index 0000000..fbe67ed --- /dev/null +++ b/xemantic-osc-api/src/jvmAndNativeMain/kotlin/Package.kt @@ -0,0 +1,19 @@ +/* + * xemantic-osc - Kotlin idiomatic and multiplatform OSC protocol support + * Copyright (C) 2024 Kazimierz Pogoda + * + * This file is part of xemantic-osc. + * + * xemantic-osc is free software: you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * xemantic-osc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with xemantic-osc. + * If not, see . + */ + +package com.xemantic.osc diff --git a/xemantic-osc-api/src/jvmAndNativeMain/kotlin/type/JvmAndNativeOscTypeTags.kt b/xemantic-osc-api/src/jvmAndNativeMain/kotlin/type/JvmAndNativeOscTypeTags.kt new file mode 100644 index 0000000..fb49731 --- /dev/null +++ b/xemantic-osc-api/src/jvmAndNativeMain/kotlin/type/JvmAndNativeOscTypeTags.kt @@ -0,0 +1,40 @@ +/* + * xemantic-osc - Kotlin idiomatic and multiplatform OSC protocol support + * Copyright (C) 2024 Kazimierz Pogoda + * + * This file is part of xemantic-osc. + * + * xemantic-osc is free software: you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * xemantic-osc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with xemantic-osc. + * If not, see . + */ + +package com.xemantic.osc.type + +import com.xemantic.osc.OscException + +public actual inline val Any.oscTypeTag: String get() = when (this) { + is Int -> "i" + is Float -> "f" + is String -> "s" + is ByteArray -> "b" + is Boolean -> oscTypeTag + is OscImpulse -> "I" + is OscTimeTag -> "t" + is Long -> "h" + is Double -> "d" + is Char -> "c" + is OscColor -> "r" + is OscMidiMessage -> "m" + is List<*> -> "[${oscTypeTags()}]" + else -> throw OscException( + "Type unsupported in OSC: ${this::class}" + ) +}