Skip to content

Commit

Permalink
Update SnowflakeCodec.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
NoComment1105 authored Sep 15, 2023
1 parent 7903682 commit 1cc298e
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.kotlindiscord.kord.extensions.adapters.mongodb.codecs

import dev.kord.common.entity.Snowflake
import org.bson.BsonInvalidOperationException
import org.bson.BsonReader
import org.bson.BsonWriter
import org.bson.codecs.Codec
Expand All @@ -15,10 +16,10 @@ import org.bson.codecs.EncoderContext

public object SnowflakeCodec : Codec<Snowflake> {
override fun decode(reader: BsonReader, decoderContext: DecoderContext): Snowflake = try {
Snowflake(reader.readString())
} catch (e: BsonInvalidOperationException) {
Snowflake(reader.readInt64())
}
Snowflake(reader.readString())
} catch (e: BsonInvalidOperationException) {
Snowflake(reader.readInt64())
}

override fun encode(writer: BsonWriter, value: Snowflake, encoderContext: EncoderContext) {
writer.writeString(value.toString())
Expand Down

0 comments on commit 1cc298e

Please sign in to comment.