Started implementing client
This commit is contained in:
@ -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> {
|
||||
//
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user