pack

inline fun <T : Any> ERROR CLASS: Symbol not found for Any.Companion.pack(value: T, urlPrefix: String = "type.googleapis.com"): Any(source)

Packs a protobuf message into an Any message.

This method serializes the given value and wraps it in an Any message with a type URL (Any.typeUrl) that identifies the message type. The type URL is constructed as "<urlPrefix>/<fully.qualified.message.name>".

The resulting Any message can be transmitted over the wire and later unpacked using unpack by a receiver that knows the message type.

Example:

val timestamp = Timestamp { seconds = 1234567890; nanos = 123456789 }
val any = Any.pack(timestamp)
// any.typeUrl = "type.googleapis.com/google.protobuf.Timestamp"

Example with custom URL prefix:

val message = MyMessage { field = "value" }
val any = Any.pack(message, urlPrefix = "example.com/protos")
// any.typeUrl = "example.com/protos/my.package.MyMessage"

Return

an Any message containing the serialized value

Parameters

value

the message instance to pack

urlPrefix

the URL prefix for the type URL (default: "type.googleapis.com")

Type Parameters

T

the protobuf message type to pack

See also