Started implementing client
This commit is contained in:
parent
c467796823
commit
9d9ca56bc4
|
@ -16,3 +16,4 @@ captures
|
|||
!*.xcodeproj/project.xcworkspace/
|
||||
!*.xcworkspace/contents.xcworkspacedata
|
||||
**/xcshareddata/WorkspaceSettings.xcsettings
|
||||
**/.env
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.jaytux.simd.frontend
|
||||
|
||||
class Greeting {
|
||||
private val platform = getPlatform()
|
||||
|
||||
fun greet(): String {
|
||||
return "Hello, ${platform.name}!"
|
||||
return "Hello, X!"
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package com.jaytux.simd.frontend
|
||||
|
||||
interface Platform {
|
||||
val name: String
|
||||
}
|
||||
import io.ktor.client.*
|
||||
|
||||
expect fun getPlatform(): Platform
|
||||
expect fun getKtorClient(): HttpClient
|
|
@ -0,0 +1,76 @@
|
|||
package com.jaytux.simd.frontend.client
|
||||
|
||||
import com.jaytux.simd.frontend.getKtorClient
|
||||
import io.ktor.client.*
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlin.uuid.ExperimentalUuidApi
|
||||
import kotlin.uuid.Uuid
|
||||
|
||||
@OptIn(ExperimentalUuidApi::class)
|
||||
object Client {
|
||||
val httpClient: HttpClient by lazy { getKtorClient() }
|
||||
|
||||
object UUIDSerializer : KSerializer<Uuid> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING)
|
||||
|
||||
override fun deserialize(decoder: Decoder): Uuid = try {
|
||||
Uuid.parse(decoder.decodeString())
|
||||
} catch (e: IllegalArgumentException) {
|
||||
throw IllegalArgumentException("Invalid UUID format")
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: Uuid) = encoder.encodeString(value.toString())
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class IntrinsicSummary constructor(@Serializable(with = UUIDSerializer::class) val id: Uuid, val name: String)
|
||||
|
||||
@Serializable
|
||||
data class Param(val name: String, val type: String)
|
||||
|
||||
@Serializable
|
||||
data class Instruction(val mnemonic: String, val xed: String, val form: String?)
|
||||
|
||||
@Serializable
|
||||
data class PlatformPerformance(val platform: String, val latency: Float?, val throughput: Float?)
|
||||
|
||||
@Serializable
|
||||
data class IntrinsicDetails(
|
||||
@Serializable(with = UUIDSerializer::class) val id: Uuid,
|
||||
val name: String,
|
||||
val returnType: String,
|
||||
val returnVar: String?,
|
||||
val description: String,
|
||||
val operations: String?,
|
||||
val category: String,
|
||||
val cpuid: String?,
|
||||
val tech: String,
|
||||
val params: List<Param>,
|
||||
val instructions: List<Instruction>?,
|
||||
val performance: List<PlatformPerformance>?
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Versioning(
|
||||
val intelVersion: String, val intelUpdate: LocalDate, val scrapeDate: LocalDate
|
||||
)
|
||||
|
||||
@Serializable data class Paginated<T>(val page: Long, val totalPages: Long, val items: List<T>)
|
||||
|
||||
interface PaginatedResponse<T> {
|
||||
fun currentItems(): List<T>
|
||||
fun hasNextPage(): Boolean
|
||||
suspend fun loadNextPage()
|
||||
}
|
||||
|
||||
suspend fun getAll(): PaginatedResponse<IntrinsicSummary> {
|
||||
//
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.jaytux.simd.frontend
|
||||
|
||||
class JVMPlatform: Platform {
|
||||
override val name: String = "Java ${System.getProperty("java.version")}"
|
||||
}
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.cio.*
|
||||
|
||||
actual fun getPlatform(): Platform = JVMPlatform()
|
||||
actual fun getKtorClient(): HttpClient = HttpClient(CIO)
|
|
@ -1,7 +1,6 @@
|
|||
package com.jaytux.simd.frontend
|
||||
|
||||
class WasmPlatform: Platform {
|
||||
override val name: String = "Web with Kotlin/Wasm"
|
||||
}
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.engine.js.*
|
||||
|
||||
actual fun getPlatform(): Platform = WasmPlatform()
|
||||
actual fun getKtorClient(): HttpClient = HttpClient(Js)
|
|
@ -52,6 +52,11 @@
|
|||
"@jridgewell/resolve-uri" "^3.1.0"
|
||||
"@jridgewell/sourcemap-codec" "^1.4.14"
|
||||
|
||||
"@js-joda/core@3.2.0":
|
||||
version "3.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@js-joda/core/-/core-3.2.0.tgz#3e61e21b7b2b8a6be746df1335cf91d70db2a273"
|
||||
integrity sha512-PMqgJ0sw5B7FKb2d5bWYIoxjri+QlW/Pys7+Rw82jSH0QN3rB05jZ/VrrsUdh1w4+i2kw9JOejXGq/KhDOX7Kg==
|
||||
|
||||
"@leichtgewicht/ip-codec@^2.0.1":
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz#4fc56c15c580b9adb7dc3c333a134e540b44bfb1"
|
||||
|
@ -2837,6 +2842,11 @@ wrappy@1:
|
|||
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
|
||||
integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==
|
||||
|
||||
ws@8.18.0:
|
||||
version "8.18.0"
|
||||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc"
|
||||
integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==
|
||||
|
||||
ws@^8.13.0:
|
||||
version "8.18.1"
|
||||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.1.tgz#ea131d3784e1dfdff91adb0a4a116b127515e3cb"
|
||||
|
|
Loading…
Reference in New Issue