contains

inline fun <T : Any> Any.contains(): Boolean(source)

Checks if this Any message contains a message of type T.

This method examines the type URL Any.typeUrl and compares it against the fully qualified protobuf message type name of T. The check is performed by verifying that the type URL ends with "/<fully.qualified.message.name>".

Example:

val any = Any.pack(Timestamp { seconds = 123 })
if (any.contains<Timestamp>()) {
val timestamp = any.unpack<Timestamp>()
}

Return

true if this Any contains a message of type T, false otherwise

Type Parameters

T

the protobuf message type to check for

See also


fun <T : Any> Any.contains(messageClass: KClass<T>): Boolean(source)

Checks if this Any message contains a message of the specified messageClass type.

This method examines the type URL Any.typeUrl and compares it against the fully qualified protobuf message type name of T. The check is performed by verifying that the type URL ends with "/<fully.qualified.message.name>".

Example:

val any = Any.pack(Duration { seconds = 60 })
if (any.contains(Duration::class)) {
val duration = any.unpack<Duration>()
}

Return

true if this Any contains a message of type messageClass, false otherwise

Parameters

messageClass

the KClass of the message type to check

Type Parameters

T

the protobuf message type to check for

See also


fun <T : Any> Any.contains(messageType: KType): Boolean(source)

Checks if this Any message contains a message of the specified messageType type.

This method examines the type URL Any.typeUrl and compares it against the fully qualified protobuf message type name of T. The check is performed by verifying that the type URL ends with "/<fully.qualified.message.name>".

Example:

val any = Any.pack(Duration { seconds = 60 })
if (any.contains<Duration>(typeOf<Duration>)) {
val duration = any.unpack<Duration>()
}

Return

true if this Any contains a message of type messageType, false otherwise

Parameters

messageType

the message KType to check

Type Parameters

T

the protobuf message type to check for

See also