function AnyBase::pack
The type_url will be created according to the given message’s type and the value is encoded data from the given message..
Parameters
Message $msg A proto message.:
File
-
vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ AnyBase.php, line 55
Class
- AnyBase
- Base class for Google\Protobuf\Any, this contains hand-written convenience methods like pack() and unpack().
Namespace
Google\Protobuf\InternalCode
public function pack($msg) {
if (!$msg instanceof Message) {
trigger_error("Given parameter is not a message instance.", E_USER_ERROR);
return;
}
// Set value using serialized message.
$this->value = $msg->serializeToString();
// Set type url.
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName(get_class($msg));
$fully_qualified_name = $desc->getFullName();
$this->type_url = GPBUtil::TYPE_URL_PREFIX . $fully_qualified_name;
}