-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add iOS target on multiplatform module
Resolves: #130
- Loading branch information
1 parent
94e32ff
commit e811af9
Showing
9 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
krossbow-stomp-core/src/iosMain/kotlin/org/hildan/krossbow/stomp/charsets/CharsetsIos.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.hildan.krossbow.stomp.charsets | ||
|
||
actual abstract class Charset(internal val _name: String) { | ||
actual abstract fun newEncoder(): CharsetEncoder | ||
actual abstract fun newDecoder(): CharsetDecoder | ||
} | ||
|
||
internal data class CharsetImpl(val name: String) : Charset(name) { | ||
override fun newEncoder(): CharsetEncoder = CharsetEncoderImpl(this) | ||
override fun newDecoder(): CharsetDecoder = CharsetDecoderImpl(this) | ||
} | ||
|
||
internal actual fun String.toCharset() = when (lowercase().replace('_', '-')) { | ||
"utf-8", "utf8" -> Charsets.UTF_8 | ||
"iso-8859-1", "latin1" -> Charsets.ISO_8859_1 | ||
else -> throw IllegalArgumentException("Charset $this is not supported") | ||
} | ||
|
||
actual abstract class CharsetDecoder(internal val _charset: Charset) | ||
actual abstract class CharsetEncoder(internal val _charset: Charset) | ||
|
||
internal data class CharsetDecoderImpl(private val charset: Charset) : CharsetDecoder(charset) | ||
internal data class CharsetEncoderImpl(private val charset: Charset) : CharsetEncoder(charset) | ||
|
||
actual object Charsets { | ||
actual val UTF_8: Charset = CharsetImpl("UTF-8") | ||
actual val ISO_8859_1: Charset = CharsetImpl("ISO-8859-1") | ||
} | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
actual fun CharsetEncoder.encode(input: String): ByteArray = when (_charset) { | ||
Charsets.UTF_8 -> input.encodeToByteArray() | ||
else -> error("Non UTF-8 encodings are not supported on iOS platform") | ||
} | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
actual fun CharsetDecoder.decode(bytes: ByteArray): String = when (_charset) { | ||
Charsets.UTF_8 -> bytes.decodeToString() | ||
else -> error("Non UTF-8 encodings are not supported on iOS platform") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ kotlin { | |
nodejs() | ||
browser() | ||
} | ||
ios() | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
krossbow-websocket-core/src/iosMain/kotlin/org/hildan/krossbow/websocket/DefaultIosClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.hildan.krossbow.websocket | ||
|
||
actual fun defaultWebSocketClient(): WebSocketClient = | ||
throw NotImplementedError("There is no default web socket client on iOS target at the moment, please provide your" + | ||
" own client implementation.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ocket-test/src/iosMain/kotlin/org/hildan/krossbow/websocket/test/WebSocketTestUtilsIos.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.hildan.krossbow.websocket.test | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.runBlocking | ||
|
||
actual fun runSuspendingTest(block: suspend CoroutineScope.() -> Unit) = runBlocking { block() } | ||
|
||
internal actual suspend fun runAlongEchoWSServer(block: suspend (port: Int) -> Unit) { | ||
TODO("Implement test WS echo server on native platform") | ||
} |