Skip to content

Commit

Permalink
Update kotlinx.serialization to 1.3.0, and Kotlin to 1.5.31
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWoodworth committed Sep 24, 2021
1 parent 2bb8d97 commit afa5ebf
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 39 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
[![Maven Central](https://img.shields.io/maven-central/v/net.benwoodworth.knbt/knbt)](https://search.maven.org/artifact/net.benwoodworth.knbt/knbt)
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.benwoodworth.knbt/knbt?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://s01.oss.sonatype.org/content/repositories/snapshots/net/benwoodworth/knbt/knbt/)
[![KDoc](https://img.shields.io/badge/api-KDoc-blue)](https://benwoodworth.github.io/knbt)
[![Kotlin](https://img.shields.io/badge/kotlin-1.5.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![kotlinx.serialization](https://img.shields.io/badge/kotlinx.serialization-1.2.0-blue.svg?logo=kotlin)](https://github.com/Kotlin/kotlinx.serialization)
[![Kotlin](https://img.shields.io/badge/kotlin-1.5.31-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![kotlinx.serialization](https://img.shields.io/badge/kotlinx.serialization-1.3.0-blue.svg?logo=kotlin)](https://github.com/Kotlin/kotlinx.serialization)

An implementation of [Minecraft's NBT format](https://minecraft.fandom.com/wiki/NBT_format)
for [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization).
Expand Down Expand Up @@ -206,7 +206,7 @@ Replacement refactorings will be provided where possible for broken APIs. Change

```kotlin
plugins {
kotlin("jvm") version "1.5.0" // or kotlin("multiplatform"), etc.
kotlin("jvm") version "1.5.31" // or kotlin("multiplatform"), etc.
//kotlin("plugin.serialization") version "1.5.0"
}

Expand Down
11 changes: 6 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ System.getenv("GIT_REF")?.let { gitRef ->
val isSnapshot = version.toString().contains("SNAPSHOT", true)

plugins {
kotlin("multiplatform") version "1.5.0"
kotlin("plugin.serialization") version "1.5.0"
kotlin("multiplatform") version "1.5.31"
kotlin("plugin.serialization") version "1.5.31"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.7.1"
id("org.jetbrains.dokka") version "1.5.0"
id("maven-publish")
Expand Down Expand Up @@ -51,12 +51,13 @@ kotlin {
watchosX86()
mingwX64()

@Suppress("UNUSED_VARIABLE")
sourceSets {
configureEach {
languageSettings.apply {
useExperimentalAnnotation("kotlin.RequiresOptIn")
useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
useExperimentalAnnotation("net.benwoodworth.knbt.InternalNbtApi")
optIn("kotlin.RequiresOptIn")
optIn("kotlin.contracts.ExperimentalContracts")
optIn("net.benwoodworth.knbt.InternalNbtApi")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
group=net.benwoodworth.knbt
version=0.10.0-SNAPSHOT

kotlinx_serialization_version=1.2.0
kotlinx_serialization_version=1.3.0
okio_version=2.10.0

kotlin.code.style=official
Expand Down
7 changes: 0 additions & 7 deletions src/commonMain/kotlin/Nbt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ import okio.Sink
import okio.Source
import okio.use

@OptIn(ExperimentalSerializationApi::class)
public sealed class Nbt constructor(
@Suppress("EXPERIMENTAL_OVERRIDE")
@ExperimentalNbtApi
override val configuration: NbtConfiguration,

override val serializersModule: SerializersModule,
) : NbtFormat, BinaryFormat {
/**
Expand Down Expand Up @@ -77,7 +73,6 @@ public fun Nbt(from: Nbt = DefaultNbt, builderAction: NbtBuilder.() -> Unit): Nb
* Builder of the [Nbt] instance provided by `Nbt { ... }` factory function.
*/
@NbtDslMarker
@OptIn(ExperimentalNbtApi::class)
public class NbtBuilder internal constructor(nbt: Nbt) {
/**
* The variant of NBT binary format to use. Required.
Expand Down Expand Up @@ -124,7 +119,6 @@ public class NbtBuilder internal constructor(nbt: Nbt) {
*/
public var serializersModule: SerializersModule = nbt.serializersModule

@OptIn(ExperimentalSerializationApi::class, ExperimentalNbtApi::class)
internal fun build(): Nbt {
val variant = variant
val compression = compression
Expand All @@ -150,7 +144,6 @@ public class NbtBuilder internal constructor(nbt: Nbt) {
}
}

@OptIn(ExperimentalSerializationApi::class)
private class NbtImpl(
configuration: NbtConfiguration,
serializersModule: SerializersModule,
Expand Down
1 change: 0 additions & 1 deletion src/commonMain/kotlin/NbtDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ internal abstract class AbstractNbtDecoder : AbstractDecoder(), NbtDecoder, Comp
final override fun decodeNbtTagElement(descriptor: SerialDescriptor, index: Int): NbtTag =
decodeNbtTag()

@ExperimentalSerializationApi
override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder =
if (descriptor.kind == StructureKind.LIST) {
beginList(descriptor)
Expand Down
2 changes: 0 additions & 2 deletions src/commonMain/kotlin/NbtFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import kotlinx.serialization.*
import kotlinx.serialization.descriptors.StructureKind
import net.benwoodworth.knbt.internal.*

@OptIn(ExperimentalSerializationApi::class)
public sealed interface NbtFormat : SerialFormat {
@ExperimentalNbtApi
public val configuration: NbtFormatConfiguration

/**
Expand Down
6 changes: 2 additions & 4 deletions src/commonMain/kotlin/NbtTagSerializers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ internal class NbtListSerializer<T : NbtTag>(
private class NbtListDescriptor(
val elementDescriptor: SerialDescriptor,
) : SerialDescriptor by listSerialDescriptor(elementDescriptor) {
@ExperimentalSerializationApi
override val serialName: String = "net.benwoodworth.knbt.NbtList"
}
}
Expand All @@ -139,14 +138,13 @@ internal object NbtCompoundSerializer : KSerializer<NbtCompound> {
private class NbtCompoundDescriptor(
val elementDescriptor: SerialDescriptor,
) : SerialDescriptor by mapSerialDescriptor(String.serializer().descriptor, elementDescriptor) {
@ExperimentalSerializationApi
override val serialName: String = "net.benwoodworth.knbt.NbtCompound"
}
}

internal object NbtIntArraySerializer : KSerializer<NbtIntArray> {
@OptIn(ExperimentalSerializationApi::class)
private object NbtIntArrayDescriptor : SerialDescriptor by serialDescriptor<IntArray>() {
@ExperimentalSerializationApi
override val serialName: String = "net.benwoodworth.knbt.NbtIntArray"
}

Expand All @@ -160,8 +158,8 @@ internal object NbtIntArraySerializer : KSerializer<NbtIntArray> {
}

internal object NbtLongArraySerializer : KSerializer<NbtLongArray> {
@OptIn(ExperimentalSerializationApi::class)
private object NbtLongArrayDescriptor : SerialDescriptor by serialDescriptor<LongArray>() {
@ExperimentalSerializationApi
override val serialName: String = "net.benwoodworth.knbt.NbtLongArray"
}

Expand Down
10 changes: 2 additions & 8 deletions src/commonMain/kotlin/StringifiedNbt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import kotlinx.serialization.modules.SerializersModule
import net.benwoodworth.knbt.internal.StringifiedNbtWriter
import kotlin.native.concurrent.ThreadLocal

@OptIn(ExperimentalSerializationApi::class)
public sealed class StringifiedNbt constructor(
@Suppress("EXPERIMENTAL_OVERRIDE")
@ExperimentalNbtApi
override val configuration: StringifiedNbtConfiguration,

override val serializersModule: SerializersModule,
) : NbtFormat, StringFormat {
/**
* The default instance of [StringifiedNbt] with default configuration.
*/
@OptIn(ExperimentalNbtApi::class)
@OptIn(ExperimentalNbtApi::class, ExperimentalSerializationApi::class)
@ThreadLocal
public companion object Default : StringifiedNbt(
configuration = StringifiedNbtConfiguration(
Expand Down Expand Up @@ -65,7 +61,6 @@ public fun StringifiedNbt(
* Builder of the [StringifiedNbt] instance provided by `StringifiedNbt { ... }` factory function.
*/
@NbtDslMarker
@OptIn(ExperimentalNbtApi::class)
public class StringifiedNbtBuilder internal constructor(stringifiedNbt: StringifiedNbt) {
/**
* Specifies whether default values of Kotlin properties should be encoded.
Expand Down Expand Up @@ -100,7 +95,7 @@ public class StringifiedNbtBuilder internal constructor(stringifiedNbt: Stringif
*/
public var serializersModule: SerializersModule = stringifiedNbt.serializersModule

@OptIn(ExperimentalSerializationApi::class, ExperimentalNbtApi::class)
@OptIn(ExperimentalNbtApi::class)
internal fun build(): StringifiedNbt {
if (!prettyPrint) {
require(prettyPrintIndent == StringifiedNbt.configuration.prettyPrintIndent) {
Expand All @@ -126,7 +121,6 @@ public class StringifiedNbtBuilder internal constructor(stringifiedNbt: Stringif
}
}

@OptIn(ExperimentalSerializationApi::class)
private class StringifiedNbtImpl(
configuration: StringifiedNbtConfiguration,
serializersModule: SerializersModule,
Expand Down
3 changes: 1 addition & 2 deletions src/commonMain/kotlin/internal/DefaultNbtEncoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.serialization.modules.SerializersModule
import net.benwoodworth.knbt.*
import net.benwoodworth.knbt.internal.NbtTagType.*

@ExperimentalSerializationApi
@OptIn(ExperimentalSerializationApi::class)
internal class DefaultNbtEncoder(
private val nbt: NbtFormat,
private val writer: NbtWriter,
Expand Down Expand Up @@ -124,7 +124,6 @@ internal class DefaultNbtEncoder(
}
}

@ExperimentalSerializationApi
@OptIn(ExperimentalNbtApi::class)
override fun shouldEncodeElementDefault(descriptor: SerialDescriptor, index: Int): Boolean =
nbt.configuration.encodeDefaults
Expand Down
8 changes: 6 additions & 2 deletions src/commonMain/kotlin/internal/NbtDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private abstract class BaseNbtDecoder : AbstractNbtDecoder() {
private fun expectTagType(expected: NbtTagType) {
val actual = entryType
if (expected != actual) {
throw NbtDecodingException("Expected ${expected}, but was ${actual}", getPath())
throw NbtDecodingException("Expected $expected, but was $actual", getPath())
}
}

Expand Down Expand Up @@ -179,7 +179,6 @@ private abstract class BaseNbtDecoder : AbstractNbtDecoder() {
final override fun <T> decodeSerializableValue(deserializer: DeserializationStrategy<T>, previousValue: T?): T =
super.decodeSerializableValue(deserializer, previousValue)

@ExperimentalSerializationApi
final override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder =
super.beginStructure(descriptor)
//endregion
Expand Down Expand Up @@ -213,6 +212,7 @@ private abstract class CompoundNbtDecoder : BaseNbtDecoder() {
override fun getPathNode(): NbtPath.Node =
NbtPath.NameNode(compoundEntryInfo.name, entryType)

@OptIn(ExperimentalSerializationApi::class)
override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endCompound()
}

Expand Down Expand Up @@ -353,6 +353,7 @@ private class ListNbtDecoder(

override fun beginEntry(): Boolean = reader.beginListEntry()

@OptIn(ExperimentalSerializationApi::class)
override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endList()
}

Expand All @@ -371,6 +372,7 @@ private class ByteArrayNbtDecoder(

override fun beginEntry(): Boolean = reader.beginByteArrayEntry()

@OptIn(ExperimentalSerializationApi::class)
override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endByteArray()
}

Expand All @@ -389,6 +391,7 @@ private class IntArrayNbtDecoder(

override fun beginEntry(): Boolean = reader.beginIntArrayEntry()

@OptIn(ExperimentalSerializationApi::class)
override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endIntArray()
}

Expand All @@ -407,5 +410,6 @@ private class LongArrayNbtDecoder(

override fun beginEntry(): Boolean = reader.beginLongArrayEntry()

@OptIn(ExperimentalSerializationApi::class)
override fun endStructure(descriptor: SerialDescriptor): Unit = reader.endLongArray()
}
2 changes: 1 addition & 1 deletion src/commonTest/kotlin/internal/DefaultNbtEncoderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import kotlin.test.Test
import kotlin.test.assertEquals

class DefaultNbtEncoderTest {
@OptIn(ExperimentalSerializationApi::class)
private fun assertEncodesCorrectly(tag: NbtTag, expectedLog: String) {
val stringBuilder = StringBuilder()
var actualTag: NbtTag? = null
val writer = LoggingNbtWriter(TreeNbtWriter { actualTag = it }, stringBuilder)

try {
@OptIn(ExperimentalSerializationApi::class)
DefaultNbtEncoder(NbtFormat(), writer).encodeSerializableValue(NbtTag.serializer(), tag)
} catch (e: Exception) {
throw Exception("Error encoding. NbtWriter log: <\n$stringBuilder>", e)
Expand Down
1 change: 0 additions & 1 deletion src/commonTest/kotlin/internal/NbtDecoderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class NbtDecoderTest {
val reader = LoggingNbtReader(TreeNbtReader(tag), stringBuilder)

val actualValue = try {
@OptIn(ExperimentalSerializationApi::class)
NbtDecoder(NbtFormat(), reader).decodeSerializableValue(serializer)
} catch (e: Exception) {
val log = stringBuilder.toString().trimIndent()
Expand Down
3 changes: 1 addition & 2 deletions src/commonTest/kotlin/internal/RootClassSerializerTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.benwoodworth.knbt.internal

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.benwoodworth.knbt.ExperimentalNbtApi
Expand All @@ -10,7 +9,7 @@ import net.benwoodworth.knbt.put
import kotlin.test.Test
import kotlin.test.assertEquals

@OptIn(ExperimentalSerializationApi::class, ExperimentalNbtApi::class)
@OptIn(ExperimentalNbtApi::class)
class RootClassSerializerTest {
@Serializable
@SerialName("root-name")
Expand Down

0 comments on commit afa5ebf

Please sign in to comment.