Skip to content

Commit

Permalink
Properly decode null in gateway events (#286)
Browse files Browse the repository at this point in the history
* Properly decode null in gateway events

* Update gateway/src/main/kotlin/Event.kt

Co-authored-by: Bart Arys <[email protected]>

Co-authored-by: Bart Arys <[email protected]>
  • Loading branch information
DRSchlaubi and BartArys authored May 12, 2021
1 parent 23eded0 commit 32c58d8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gateway/src/main/kotlin/Event.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import dev.kord.common.entity.optional.OptionalSnowflake
import kotlinx.serialization.*
import kotlinx.serialization.builtins.nullable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.CompositeDecoder
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
Expand All @@ -31,6 +28,9 @@ private object NullDecoder : DeserializationStrategy<Nothing?> {

@OptIn(ExperimentalSerializationApi::class)
override fun deserialize(decoder: Decoder): Nothing? {
// decodeNull() doesn't consume the literal null therefore parsing doesn't end and in e.g. a heartbeat event
// the null gets parsed as a key
decoder.decodeNotNullMark()
return decoder.decodeNull()
}

Expand Down

0 comments on commit 32c58d8

Please sign in to comment.