Skip to content

Commit

Permalink
Update kotlinx.serialization to 1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWoodworth committed Jan 6, 2025
1 parent 23caa96 commit e7d9c19
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![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-2.1.0-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)
[![kotlinx.serialization](https://img.shields.io/badge/kotlinx.serialization-1.8.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
21 changes: 0 additions & 21 deletions api/knbt.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ public abstract interface class net/benwoodworth/knbt/CompositeNbtDecoder : kotl
public abstract fun getNbt ()Lnet/benwoodworth/knbt/NbtFormat;
}

public final class net/benwoodworth/knbt/CompositeNbtDecoder$DefaultImpls {
public static fun decodeCollectionSize (Lnet/benwoodworth/knbt/CompositeNbtDecoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)I
public static fun decodeSequentially (Lnet/benwoodworth/knbt/CompositeNbtDecoder;)Z
}

public abstract interface class net/benwoodworth/knbt/CompositeNbtEncoder : kotlinx/serialization/encoding/CompositeEncoder {
public abstract fun encodeByteArrayElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I[B)V
public abstract fun encodeIntArrayElement (Lkotlinx/serialization/descriptors/SerialDescriptor;I[I)V
Expand All @@ -19,10 +14,6 @@ public abstract interface class net/benwoodworth/knbt/CompositeNbtEncoder : kotl
public abstract fun getNbt ()Lnet/benwoodworth/knbt/NbtFormat;
}

public final class net/benwoodworth/knbt/CompositeNbtEncoder$DefaultImpls {
public static fun shouldEncodeElementDefault (Lnet/benwoodworth/knbt/CompositeNbtEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;I)Z
}

public abstract interface annotation class net/benwoodworth/knbt/ExperimentalNbtApi : java/lang/annotation/Annotation {
}

Expand Down Expand Up @@ -260,11 +251,6 @@ public abstract interface class net/benwoodworth/knbt/NbtDecoder : kotlinx/seria
public abstract fun getNbt ()Lnet/benwoodworth/knbt/NbtFormat;
}

public final class net/benwoodworth/knbt/NbtDecoder$DefaultImpls {
public static fun decodeNullableSerializableValue (Lnet/benwoodworth/knbt/NbtDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
public static fun decodeSerializableValue (Lnet/benwoodworth/knbt/NbtDecoder;Lkotlinx/serialization/DeserializationStrategy;)Ljava/lang/Object;
}

public final class net/benwoodworth/knbt/NbtDecoderKt {
public static final fun asNbtDecoder (Lkotlinx/serialization/encoding/Decoder;)Lnet/benwoodworth/knbt/NbtDecoder;
}
Expand Down Expand Up @@ -303,13 +289,6 @@ public abstract interface class net/benwoodworth/knbt/NbtEncoder : kotlinx/seria
public abstract fun getNbt ()Lnet/benwoodworth/knbt/NbtFormat;
}

public final class net/benwoodworth/knbt/NbtEncoder$DefaultImpls {
public static fun beginCollection (Lnet/benwoodworth/knbt/NbtEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;I)Lkotlinx/serialization/encoding/CompositeEncoder;
public static fun encodeNotNullMark (Lnet/benwoodworth/knbt/NbtEncoder;)V
public static fun encodeNullableSerializableValue (Lnet/benwoodworth/knbt/NbtEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
public static fun encodeSerializableValue (Lnet/benwoodworth/knbt/NbtEncoder;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/Object;)V
}

public final class net/benwoodworth/knbt/NbtEncoderKt {
public static final fun asNbtEncoder (Lkotlinx/serialization/encoding/Encoder;)Lnet/benwoodworth/knbt/NbtEncoder;
}
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.11.8-SNAPSHOT

kotlinx_serialization_version=1.6.3
kotlinx_serialization_version=1.8.0
okio_version=3.9.0

kotlin.code.style=official
Expand Down
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/NbtFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public inline fun <reified T> NbtFormat.encodeToNbtTag(value: T): NbtTag =
public inline fun <reified T> NbtFormat.decodeFromNbtTag(tag: NbtTag): T =
decodeFromNbtTag(serializersModule.serializer(), tag)

@OptIn(ExperimentalSerializationApi::class, InternalSerializationApi::class)
@OptIn(InternalSerializationApi::class)
internal fun <T> NbtFormat.encodeToNbtWriter(writer: NbtWriter, serializer: SerializationStrategy<T>, value: T) {
val rootSerializer = if (
configuration.nameRootClasses &&
Expand All @@ -107,7 +107,7 @@ internal fun <T> NbtFormat.encodeToNbtWriter(writer: NbtWriter, serializer: Seri
.encodeSerializableValue(rootSerializer, value)
}

@OptIn(ExperimentalSerializationApi::class, InternalSerializationApi::class)
@OptIn(InternalSerializationApi::class)
internal fun <T> NbtFormat.decodeFromNbtReader(reader: NbtReader, deserializer: DeserializationStrategy<T>): T {
val rootDeserializer = if (
configuration.nameRootClasses &&
Expand Down
50 changes: 15 additions & 35 deletions src/commonMain/kotlin/NbtTagSerializers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.benwoodworth.knbt
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SealedSerializationApi
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.serializer
Expand Down Expand Up @@ -115,12 +116,8 @@ internal object NbtDoubleSerializer : KSerializer<NbtDouble> {
}

internal object NbtByteArraySerializer : KSerializer<NbtByteArray> {
private object NbtByteArrayDescriptor : SerialDescriptor by serialDescriptor<ByteArray>() {
@ExperimentalSerializationApi
override val serialName: String = "net.benwoodworth.knbt.NbtByteArray"
}

override val descriptor: SerialDescriptor = NbtByteArrayDescriptor
override val descriptor: SerialDescriptor =
SerialDescriptor("net.benwoodworth.knbt.NbtByteArray", serialDescriptor<ByteArray>())

override fun serialize(encoder: Encoder, value: NbtByteArray): Unit =
encoder.asNbtEncoder().encodeByteArray(value.content)
Expand All @@ -143,51 +140,37 @@ internal object NbtStringSerializer : KSerializer<NbtString> {
internal class NbtListSerializer<T : NbtTag>(
elementSerializer: KSerializer<T>,
) : KSerializer<NbtList<T>> {
override val descriptor: SerialDescriptor = NbtListDescriptor(elementSerializer.descriptor)
private val listSerializer = ListSerializer(elementSerializer)

override val descriptor: SerialDescriptor =
SerialDescriptor("net.benwoodworth.knbt.NbtList", listSerializer.descriptor)

override fun serialize(encoder: Encoder, value: NbtList<T>): Unit =
encoder.asNbtEncoder().encodeNbtTag(value)

@OptIn(UnsafeNbtApi::class)
override fun deserialize(decoder: Decoder): NbtList<T> =
NbtList(listSerializer.deserialize(decoder))

@OptIn(ExperimentalSerializationApi::class)
private class NbtListDescriptor(
val elementDescriptor: SerialDescriptor,
) : SerialDescriptor by listSerialDescriptor(elementDescriptor) {
override val serialName: String = "net.benwoodworth.knbt.NbtList"
}
}

internal object NbtCompoundSerializer : KSerializer<NbtCompound> {
override val descriptor: SerialDescriptor = NbtCompoundDescriptor(NbtTag.serializer().descriptor)
private val mapSerializer = MapSerializer(String.serializer(), NbtTag.serializer())

override val descriptor: SerialDescriptor =
SerialDescriptor("net.benwoodworth.knbt.NbtCompound", mapSerializer.descriptor)

override fun serialize(encoder: Encoder, value: NbtCompound): Unit =
encoder.asNbtEncoder().encodeNbtTag(value)

override fun deserialize(decoder: Decoder): NbtCompound {
val map = mapSerializer.deserialize(decoder)
return NbtCompound(map)
}

@OptIn(ExperimentalSerializationApi::class)
private class NbtCompoundDescriptor(
val elementDescriptor: SerialDescriptor,
) : SerialDescriptor by mapSerialDescriptor(String.serializer().descriptor, elementDescriptor) {
override val serialName: String = "net.benwoodworth.knbt.NbtCompound"
}
}

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

override val descriptor: SerialDescriptor = NbtIntArrayDescriptor
override val descriptor: SerialDescriptor =
SerialDescriptor("net.benwoodworth.knbt.NbtIntArray", serialDescriptor<IntArray>())

override fun serialize(encoder: Encoder, value: NbtIntArray): Unit =
encoder.asNbtEncoder().encodeIntArray(value.content)
Expand All @@ -197,12 +180,8 @@ internal object NbtIntArraySerializer : KSerializer<NbtIntArray> {
}

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

override val descriptor: SerialDescriptor = NbtLongArrayDescriptor
override val descriptor: SerialDescriptor =
SerialDescriptor("net.benwoodworth.knbt.NbtLongArray", serialDescriptor<LongArray>())

override fun serialize(encoder: Encoder, value: NbtLongArray): Unit =
encoder.asNbtEncoder().encodeLongArray(value.content)
Expand All @@ -216,7 +195,8 @@ internal object NbtLongArraySerializer : KSerializer<NbtLongArray> {
* Returns serial descriptor that delegates all the calls to descriptor returned by [deferred] block.
* Used to resolve cyclic dependencies between recursive serializable structures.
*/
@OptIn(ExperimentalSerializationApi::class)
// SealedSerializationApi: https://github.com/Kotlin/kotlinx.serialization/issues/1815
@OptIn(SealedSerializationApi::class)
private fun defer(deferred: () -> SerialDescriptor): SerialDescriptor = object : SerialDescriptor {
private val original: SerialDescriptor by lazy(deferred)

Expand Down
1 change: 0 additions & 1 deletion src/commonMain/kotlin/NbtTransformingSerializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public abstract class NbtTransformingSerializer<T : Any>(
val output = encoder.asNbtEncoder()
var element: NbtTag? = null

@OptIn(ExperimentalSerializationApi::class)
DefaultNbtEncoder(output.nbt, TreeNbtWriter { element = it })
.encodeSerializableValue(tSerializer, value)

Expand Down
1 change: 0 additions & 1 deletion src/commonMain/kotlin/internal/NbtDecoder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ private class ClassNbtDecoder(
var index: Int

do {
@OptIn(ExperimentalSerializationApi::class)
index = descriptor.getElementIndex(compoundEntryInfo.name)

if (index == CompositeDecoder.UNKNOWN_NAME) {
Expand Down
2 changes: 0 additions & 2 deletions src/commonMain/kotlin/internal/RootClassSerializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.encoding.*

@OptIn(ExperimentalSerializationApi::class)
private fun rootClassSerialDescriptor(classDescriptor: SerialDescriptor): SerialDescriptor =
buildClassSerialDescriptor("net.benwoodworth.knbt.internal.RootClass", classDescriptor) {
element(classDescriptor.serialName, classDescriptor)
Expand All @@ -30,7 +29,6 @@ internal class RootClassDeserializer<T>(
) : DeserializationStrategy<T> {
override val descriptor: SerialDescriptor = rootClassSerialDescriptor(classDeserializer.descriptor)

@OptIn(ExperimentalSerializationApi::class)
override fun deserialize(decoder: Decoder): T {
var root: T? = null
var rootDecoded = false
Expand Down
1 change: 0 additions & 1 deletion src/commonTest/kotlin/NestRootClassesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import kotlinx.serialization.modules.SerializersModule
import kotlin.test.Test
import kotlin.test.assertEquals

@OptIn(ExperimentalSerializationApi::class)
class NestRootClassesTest {
private class TestCase<T>(
val serializer: KSerializer<T>,
Expand Down

0 comments on commit e7d9c19

Please sign in to comment.