Skip to content

Commit

Permalink
Merge pull request #39 from Peanuuutz/dev
Browse files Browse the repository at this point in the history
0.3.1 Improve tests, fix several bugs. (2/2)
  • Loading branch information
Peanuuutz authored Sep 8, 2023
2 parents 4ad64f9 + 25eaa86 commit c451f08
Show file tree
Hide file tree
Showing 43 changed files with 4,273 additions and 777 deletions.
5 changes: 3 additions & 2 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ dependencies {
jmh("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.15.1")
jmh("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.1")
jmh("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.1")
// ...

// official JSON
val serializationVersion: String by rootProject
jmh("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
}

jmh {
Expand Down
8 changes: 8 additions & 0 deletions benchmark/src/jmh/kotlin/test/BytecodeChecker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package test

import kotlinx.serialization.Serializable

@Serializable
data class M(
val n: Nothing?
)
34 changes: 33 additions & 1 deletion benchmark/src/jmh/kotlin/test/Objects.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
@file:OptIn(ExperimentalUnsignedTypes::class)

package test

import kotlinx.datetime.Instant
import kotlinx.datetime.serializers.InstantIso8601Serializer
import kotlinx.datetime.toKotlinInstant
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import net.peanuuutz.tomlkt.NativeOffsetDateTime
import net.peanuuutz.tomlkt.TomlDecoder
import net.peanuuutz.tomlkt.TomlEncoder
import net.peanuuutz.tomlkt.TomlOffsetDateTimeSerializer
import org.intellij.lang.annotations.Language
import java.time.ZoneOffset

fun main() {

}

@Serializable
data class Config(
Expand Down Expand Up @@ -74,7 +85,28 @@ object OffsetDateTimeSerializer : KSerializer<Any> {
get() = InstantIso8601Serializer.descriptor

override fun serialize(encoder: Encoder, value: Any) {
TODO("Not yet implemented")
if (encoder is TomlEncoder) {
when (value) {
is NativeOffsetDateTime -> {
TomlOffsetDateTimeSerializer().serialize(encoder, value)
}
is Instant -> {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
val converted = value.value.atOffset(ZoneOffset.UTC)
TomlOffsetDateTimeSerializer().serialize(encoder, converted)
}
}
} else {
when (value) {
is NativeOffsetDateTime -> {
val converted = value.toInstant().toKotlinInstant()
InstantIso8601Serializer.serialize(encoder, converted)
}
is Instant -> {
InstantIso8601Serializer.serialize(encoder, value)
}
}
}
}

override fun deserialize(decoder: Decoder): Any {
Expand Down
1 change: 0 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ kotlin {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Peanuuutz
Copyright 2023 Peanuuutz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2023 Peanuuutz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package net.peanuuutz.tomlkt

// -------- NativeLocalDateTime --------
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/net/peanuuutz/tomlkt/Toml.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Peanuuutz
Copyright 2023 Peanuuutz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Peanuuutz
Copyright 2023 Peanuuutz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
16 changes: 16 additions & 0 deletions core/src/commonMain/kotlin/net/peanuuutz/tomlkt/TomlDateTime.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2023 Peanuuutz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package net.peanuuutz.tomlkt

import kotlinx.serialization.KSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Peanuuutz
Copyright 2023 Peanuuutz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit c451f08

Please sign in to comment.