This repository has been archived by the owner on Dec 4, 2022. It is now read-only.
-
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.
- Dropped klaxon, using kotlinx.serialization instead
- Loading branch information
1 parent
cdeda8d
commit 4c28f7f
Showing
8 changed files
with
235 additions
and
192 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
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,22 @@ | ||
package app.shosetsu.lib | ||
|
||
import app.shosetsu.lib.json.J_VERSION | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind.STRING | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
/** | ||
* [KSerializer] for [Version], to convert it from and to string | ||
*/ | ||
internal class VersionSerializer : KSerializer<Version> { | ||
override fun deserialize(decoder: Decoder): Version = Version(decoder.decodeString()) | ||
|
||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor(J_VERSION, STRING) | ||
|
||
override fun serialize(encoder: Encoder, value: Version) { | ||
encoder.encodeString(value.toString()) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,29 @@ | ||
package app.shosetsu.lib.json | ||
|
||
import app.shosetsu.lib.Version | ||
import app.shosetsu.lib.exceptions.JsonMissingKeyException | ||
import com.beust.klaxon.JsonObject | ||
import com.beust.klaxon.Parser | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.decodeFromString | ||
import kotlinx.serialization.json.Json | ||
import java.io.File | ||
import java.io.FileReader | ||
import java.io.StringReader | ||
|
||
/** | ||
* shosetsu-kotlin-lib | ||
* 17 / 10 / 2020 | ||
* @param libraries Libraries used by the repository | ||
* @param extensions Extensions listed in this repository | ||
*/ | ||
@Serializable | ||
data class RepoIndex internal constructor( | ||
@SerialName(LIBS_KEY) | ||
val libraries: List<RepoLibrary>, | ||
|
||
@SerialName(SCPS_KEY) | ||
val extensions: List<RepoExtension> | ||
) { | ||
companion object { | ||
const val LIBS_KEY = "libraries" | ||
const val SCPS_KEY = "scripts" | ||
} | ||
|
||
constructor(jsonFile: File) : this( | ||
Parser.default().parse(FileReader(jsonFile)) as JsonObject | ||
) | ||
|
||
constructor(jsonString: String) : this( | ||
Parser.default().parse(StringReader(jsonString)) as JsonObject | ||
) | ||
|
||
// Using .toAndroid() to provide android compatiblity | ||
internal constructor(json: JsonObject) : this( | ||
json.array<JsonObject>(LIBS_KEY)?.map { | ||
RepoLibrary( | ||
name = it.string(J_NAME) ?: throw JsonMissingKeyException( | ||
LIBS_KEY, | ||
J_NAME | ||
), | ||
version = Version( | ||
it.string(J_VERSION) ?: throw JsonMissingKeyException( | ||
LIBS_KEY, | ||
J_VERSION | ||
) | ||
) | ||
) | ||
} ?: emptyList(), | ||
json.array<JsonObject>(SCPS_KEY)?.map { | ||
RepoExtension( | ||
id = it.int(J_ID) ?: throw JsonMissingKeyException( | ||
SCPS_KEY, | ||
J_ID | ||
), | ||
name = it.string(J_NAME) ?: throw JsonMissingKeyException( | ||
SCPS_KEY, | ||
J_NAME | ||
), | ||
fileName = it.string(J_FILE_NAME) | ||
?: throw JsonMissingKeyException( | ||
SCPS_KEY, | ||
J_FILE_NAME | ||
), | ||
imageURL = it.string(J_IMAGE_URL) | ||
?: throw JsonMissingKeyException( | ||
SCPS_KEY, | ||
J_IMAGE_URL | ||
), | ||
lang = it.string(J_LANGUAGE) ?: throw JsonMissingKeyException( | ||
SCPS_KEY, | ||
J_LANGUAGE | ||
), | ||
version = Version( | ||
it.string(J_VERSION) ?: throw JsonMissingKeyException( | ||
SCPS_KEY, | ||
J_VERSION | ||
) | ||
), | ||
libVersion = Version( | ||
it.string(J_LIB_VERSION) | ||
?: throw JsonMissingKeyException( | ||
SCPS_KEY, | ||
J_LIB_VERSION | ||
) | ||
), | ||
md5 = it.string(J_MD5) ?: throw JsonMissingKeyException( | ||
SCPS_KEY, | ||
J_MD5 | ||
) | ||
) | ||
} ?: emptyList() | ||
) | ||
fun fromString(json: String): RepoIndex = Json.decodeFromString(json) | ||
} | ||
} |
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
Oops, something went wrong.