OptionalSnowflake

Represents a value that encapsulate a Snowflake's optional and value state in the Discord API.

Specifically:

  • Missing - a Snowflake field that was not present in the serialized entity.

  • Value - a Snowflake field that was assigned a non-null value in the serialized entity.

Note that there is no nullable variant present. Use Snowflake? or OptionalSnowflake? for this case instead.

The base class is (de)serializable with kotlinx.serialization.

Note that kotlinx.serialization does not call serializers for values that are not present in the serialized format. Optional fields should have a default value of OptionalSnowflake.Missing:

@Serializable
class DiscordUser(
val id: Long,
val username: String,
val bot: OptionalSnowflake = OptionalSnowflake.Missing
)

Inheritors

Types

Link copied to clipboard

Represents a Snowflake field that was not present in the serialized entity.

Link copied to clipboard
class Value(uLongValue: ULong) : OptionalSnowflake

Represents a Snowflake field that was assigned a non-null value in the serialized entity. Equality and hashcode is implemented through its value.

Properties

Link copied to clipboard
Link copied to clipboard
open val value: Snowflake?
Link copied to clipboard

returns null if this is null or OptionalSnowflake.Missing, calls OptionalSnowflake.Value.value otherwise.

Functions

Link copied to clipboard
inline fun <T : Any> OptionalSnowflake.map(mapper: (Snowflake) -> T): Optional<T>
Link copied to clipboard
fun orElse(default: Snowflake): Snowflake

returns default if the optional is Missing, or Value.value if is Value.