Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Snowflake and flags to inline value classes #886

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,701 changes: 942 additions & 759 deletions common/api/common.api

Large diffs are not rendered by default.

768 changes: 417 additions & 351 deletions common/api/common.klib.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ package dev.kord.common.entity
import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmInline
import kotlin.jvm.JvmName
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [ActivityFlag]s in the
Expand Down Expand Up @@ -191,8 +185,9 @@ public sealed class ActivityFlag(
* @see ActivityFlag
* @see ActivityFlags.Builder
*/
@Serializable(with = ActivityFlags.Serializer::class)
public class ActivityFlags internal constructor(
@JvmInline
@Serializable
public value class ActivityFlags internal constructor(
/**
* The raw value used by Discord.
*/
Expand Down Expand Up @@ -260,11 +255,6 @@ public class ActivityFlags internal constructor(
return Builder(value).apply(builder).build()
}

override fun equals(other: Any?): Boolean = this === other ||
(other is ActivityFlags && this.value == other.value)

override fun hashCode(): Int = value.hashCode()

override fun toString(): String = "ActivityFlags(values=$values)"

public class Builder(
Expand Down Expand Up @@ -304,20 +294,6 @@ public class ActivityFlags internal constructor(
*/
public fun build(): ActivityFlags = ActivityFlags(value)
}

internal object Serializer : KSerializer<ActivityFlags> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.ActivityFlags", PrimitiveKind.INT)

private val `delegate`: KSerializer<Int> = Int.serializer()

override fun serialize(encoder: Encoder, `value`: ActivityFlags) {
encoder.encodeSerializableValue(delegate, value.value)
}

override fun deserialize(decoder: Decoder): ActivityFlags =
ActivityFlags(decoder.decodeSerializableValue(delegate))
}
}

/**
Expand All @@ -336,14 +312,6 @@ public fun ActivityFlags(vararg flags: ActivityFlag): ActivityFlags = ActivityFl
flags.forEach { +it }
}

/**
* Returns an instance of [ActivityFlags] that has all bits set that are set in any element of
* [flags].
*/
public fun ActivityFlags(vararg flags: ActivityFlags): ActivityFlags = ActivityFlags {
flags.forEach { +it }
}

/**
* Returns an instance of [ActivityFlags] that has all bits set that are set in any element of
* [flags].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ package dev.kord.common.entity
import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmInline
import kotlin.jvm.JvmName
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [ApplicationFlag]s in the
Expand Down Expand Up @@ -237,8 +231,9 @@ public sealed class ApplicationFlag(
* @see ApplicationFlag
* @see ApplicationFlags.Builder
*/
@Serializable(with = ApplicationFlags.Serializer::class)
public class ApplicationFlags internal constructor(
@JvmInline
@Serializable
public value class ApplicationFlags internal constructor(
/**
* The raw code used by Discord.
*/
Expand Down Expand Up @@ -306,11 +301,6 @@ public class ApplicationFlags internal constructor(
return Builder(code).apply(builder).build()
}

override fun equals(other: Any?): Boolean = this === other ||
(other is ApplicationFlags && this.code == other.code)

override fun hashCode(): Int = code.hashCode()

override fun toString(): String = "ApplicationFlags(values=$values)"

public class Builder(
Expand Down Expand Up @@ -350,21 +340,6 @@ public class ApplicationFlags internal constructor(
*/
public fun build(): ApplicationFlags = ApplicationFlags(code)
}

internal object Serializer : KSerializer<ApplicationFlags> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.ApplicationFlags",
PrimitiveKind.INT)

private val `delegate`: KSerializer<Int> = Int.serializer()

override fun serialize(encoder: Encoder, `value`: ApplicationFlags) {
encoder.encodeSerializableValue(delegate, value.code)
}

override fun deserialize(decoder: Decoder): ApplicationFlags =
ApplicationFlags(decoder.decodeSerializableValue(delegate))
}
}

/**
Expand All @@ -384,14 +359,6 @@ public fun ApplicationFlags(vararg flags: ApplicationFlag): ApplicationFlags = A
flags.forEach { +it }
}

/**
* Returns an instance of [ApplicationFlags] that has all bits set that are set in any element of
* [flags].
*/
public fun ApplicationFlags(vararg flags: ApplicationFlags): ApplicationFlags = ApplicationFlags {
flags.forEach { +it }
}

/**
* Returns an instance of [ApplicationFlags] that has all bits set that are set in any element of
* [flags].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ package dev.kord.common.entity
import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmInline
import kotlin.jvm.JvmName
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [AttachmentFlag]s in the
Expand Down Expand Up @@ -162,8 +156,9 @@ public sealed class AttachmentFlag(
* @see AttachmentFlag
* @see AttachmentFlags.Builder
*/
@Serializable(with = AttachmentFlags.Serializer::class)
public class AttachmentFlags internal constructor(
@JvmInline
@Serializable
public value class AttachmentFlags internal constructor(
/**
* The raw value used by Discord.
*/
Expand Down Expand Up @@ -231,11 +226,6 @@ public class AttachmentFlags internal constructor(
return Builder(value).apply(builder).build()
}

override fun equals(other: Any?): Boolean = this === other ||
(other is AttachmentFlags && this.value == other.value)

override fun hashCode(): Int = value.hashCode()

override fun toString(): String = "AttachmentFlags(values=$values)"

public class Builder(
Expand Down Expand Up @@ -275,21 +265,6 @@ public class AttachmentFlags internal constructor(
*/
public fun build(): AttachmentFlags = AttachmentFlags(value)
}

internal object Serializer : KSerializer<AttachmentFlags> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.AttachmentFlags",
PrimitiveKind.INT)

private val `delegate`: KSerializer<Int> = Int.serializer()

override fun serialize(encoder: Encoder, `value`: AttachmentFlags) {
encoder.encodeSerializableValue(delegate, value.value)
}

override fun deserialize(decoder: Decoder): AttachmentFlags =
AttachmentFlags(decoder.decodeSerializableValue(delegate))
}
}

/**
Expand All @@ -309,14 +284,6 @@ public fun AttachmentFlags(vararg flags: AttachmentFlag): AttachmentFlags = Atta
flags.forEach { +it }
}

/**
* Returns an instance of [AttachmentFlags] that has all bits set that are set in any element of
* [flags].
*/
public fun AttachmentFlags(vararg flags: AttachmentFlags): AttachmentFlags = AttachmentFlags {
flags.forEach { +it }
}

/**
* Returns an instance of [AttachmentFlags] that has all bits set that are set in any element of
* [flags].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ package dev.kord.common.entity
import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmInline
import kotlin.jvm.JvmName
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [ChannelFlag]s in the
Expand Down Expand Up @@ -176,8 +170,9 @@ public sealed class ChannelFlag(
* @see ChannelFlag
* @see ChannelFlags.Builder
*/
@Serializable(with = ChannelFlags.Serializer::class)
public class ChannelFlags internal constructor(
@JvmInline
@Serializable
public value class ChannelFlags internal constructor(
/**
* The raw code used by Discord.
*/
Expand Down Expand Up @@ -243,11 +238,6 @@ public class ChannelFlags internal constructor(
return Builder(code).apply(builder).build()
}

override fun equals(other: Any?): Boolean = this === other ||
(other is ChannelFlags && this.code == other.code)

override fun hashCode(): Int = code.hashCode()

override fun toString(): String = "ChannelFlags(values=$values)"

public class Builder(
Expand Down Expand Up @@ -287,20 +277,6 @@ public class ChannelFlags internal constructor(
*/
public fun build(): ChannelFlags = ChannelFlags(code)
}

internal object Serializer : KSerializer<ChannelFlags> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.ChannelFlags", PrimitiveKind.INT)

private val `delegate`: KSerializer<Int> = Int.serializer()

override fun serialize(encoder: Encoder, `value`: ChannelFlags) {
encoder.encodeSerializableValue(delegate, value.code)
}

override fun deserialize(decoder: Decoder): ChannelFlags =
ChannelFlags(decoder.decodeSerializableValue(delegate))
}
}

/**
Expand All @@ -319,14 +295,6 @@ public fun ChannelFlags(vararg flags: ChannelFlag): ChannelFlags = ChannelFlags
flags.forEach { +it }
}

/**
* Returns an instance of [ChannelFlags] that has all bits set that are set in any element of
* [flags].
*/
public fun ChannelFlags(vararg flags: ChannelFlags): ChannelFlags = ChannelFlags {
flags.forEach { +it }
}

/**
* Returns an instance of [ChannelFlags] that has all bits set that are set in any element of
* [flags].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ package dev.kord.common.entity
import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmInline
import kotlin.jvm.JvmName
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [GuildMemberFlag]s in the
Expand Down Expand Up @@ -183,8 +177,9 @@ public sealed class GuildMemberFlag(
* @see GuildMemberFlag
* @see GuildMemberFlags.Builder
*/
@Serializable(with = GuildMemberFlags.Serializer::class)
public class GuildMemberFlags internal constructor(
@JvmInline
@Serializable
public value class GuildMemberFlags internal constructor(
/**
* The raw code used by Discord.
*/
Expand Down Expand Up @@ -252,11 +247,6 @@ public class GuildMemberFlags internal constructor(
return Builder(code).apply(builder).build()
}

override fun equals(other: Any?): Boolean = this === other ||
(other is GuildMemberFlags && this.code == other.code)

override fun hashCode(): Int = code.hashCode()

override fun toString(): String = "GuildMemberFlags(values=$values)"

public class Builder(
Expand Down Expand Up @@ -296,21 +286,6 @@ public class GuildMemberFlags internal constructor(
*/
public fun build(): GuildMemberFlags = GuildMemberFlags(code)
}

internal object Serializer : KSerializer<GuildMemberFlags> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.GuildMemberFlags",
PrimitiveKind.INT)

private val `delegate`: KSerializer<Int> = Int.serializer()

override fun serialize(encoder: Encoder, `value`: GuildMemberFlags) {
encoder.encodeSerializableValue(delegate, value.code)
}

override fun deserialize(decoder: Decoder): GuildMemberFlags =
GuildMemberFlags(decoder.decodeSerializableValue(delegate))
}
}

/**
Expand All @@ -330,14 +305,6 @@ public fun GuildMemberFlags(vararg flags: GuildMemberFlag): GuildMemberFlags = G
flags.forEach { +it }
}

/**
* Returns an instance of [GuildMemberFlags] that has all bits set that are set in any element of
* [flags].
*/
public fun GuildMemberFlags(vararg flags: GuildMemberFlags): GuildMemberFlags = GuildMemberFlags {
flags.forEach { +it }
}

/**
* Returns an instance of [GuildMemberFlags] that has all bits set that are set in any element of
* [flags].
Expand Down
Loading