unpackOrNull
Unpacks this Any message into a message of type T, or returns null if the type does not match.
This method deserializes the content of this Any message and returns it as an instance of type T. Before unpacking, it verifies that the type URL matches the expected message type. If the type URL does not match, null is returned instead of throwing an exception.
Example:
val any: Any = receiveFromNetwork()
val timestamp = any.unpackOrNull<Timestamp>()
if (timestamp != null) {
processTimestamp(timestamp)
}Return
the unpacked message of type T, or null if this Any does not contain a message of type T
Type Parameters
the protobuf message type to unpack to
See also
Unpacks this Any message into a message of type kType, or returns null if the type does not match.
This method deserializes the content of this Any message and returns it as an instance of type kType. Before unpacking, it verifies that the type URL matches the expected message type. If the type URL does not match, null is returned instead of throwing an exception.
Example:
val any: Any = receiveFromNetwork()
val timestamp = any.unpackOrNull<Timestamp>(typeOf<Timestamp>())
if (timestamp != null) {
processTimestamp(timestamp)
}Return
the unpacked message of type T, or null if this Any does not contain a message of type kType
Parameters
the protobuf message type to unpack to
See also
Unpacks this Any message into a message of class kClass, or returns null if the type does not match.
This method deserializes the content of this Any message and returns it as an instance of class kClass. Before unpacking, it verifies that the type URL matches the expected message type. If the type URL does not match, null is returned instead of throwing an exception.
Example:
val any: Any = receiveFromNetwork()
val timestamp = any.unpackOrNull(Timestamp::class)
if (timestamp != null) {
processTimestamp(timestamp)
}Return
the unpacked message of type T, or null if this Any does not contain a message of class kClass
Parameters
the protobuf message class to unpack to