aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/src/Google/Protobuf/Any.php
diff options
context:
space:
mode:
Diffstat (limited to 'php/src/Google/Protobuf/Any.php')
-rw-r--r--php/src/Google/Protobuf/Any.php115
1 files changed, 84 insertions, 31 deletions
diff --git a/php/src/Google/Protobuf/Any.php b/php/src/Google/Protobuf/Any.php
index 91ba4bd5..a9928549 100644
--- a/php/src/Google/Protobuf/Any.php
+++ b/php/src/Google/Protobuf/Any.php
@@ -4,11 +4,10 @@
namespace Google\Protobuf;
-use Google\Protobuf\Internal\DescriptorPool;
use Google\Protobuf\Internal\GPBType;
-use Google\Protobuf\Internal\GPBUtil;
use Google\Protobuf\Internal\Message;
use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\GPBUtil;
/**
* `Any` contains an arbitrary serialized protocol buffer message along with a
@@ -38,6 +37,14 @@ use Google\Protobuf\Internal\RepeatedField;
* if any.Is(Foo.DESCRIPTOR):
* any.Unpack(foo)
* ...
+ * Example 4: Pack and unpack a message in Go
+ * foo := &pb.Foo{...}
+ * any, err := ptypes.MarshalAny(foo)
+ * ...
+ * foo := &pb.Foo{}
+ * if err := ptypes.UnmarshalAny(any, foo); err != nil {
+ * ...
+ * }
* The pack methods provided by protobuf library will by default use
* 'type.googleapis.com/full.type.name' as the type URL and the unpack
* methods only use the fully qualified type name after the last '/'
@@ -72,15 +79,16 @@ use Google\Protobuf\Internal\RepeatedField;
class Any extends \Google\Protobuf\Internal\Message
{
/**
- * A URL/resource name whose content describes the type of the
- * serialized protocol buffer message.
- * For URLs which use the scheme `http`, `https`, or no scheme, the
- * following restrictions and interpretations apply:
+ * A URL/resource name that uniquely identifies the type of the serialized
+ * protocol buffer message. The last segment of the URL's path must represent
+ * the fully qualified name of the type (as in
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
+ * (e.g., leading "." is not accepted).
+ * In practice, teams usually precompile into the binary all types that they
+ * expect it to use in the context of Any. However, for URLs which use the
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
+ * server that maps type URLs to message definitions as follows:
* * If no scheme is provided, `https` is assumed.
- * * The last segment of the URL's path must represent the fully
- * qualified name of the type (as in `path/google.protobuf.Duration`).
- * The name should be in a canonical form (e.g., leading "." is
- * not accepted).
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
@@ -88,6 +96,9 @@ class Any extends \Google\Protobuf\Internal\Message
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
+ * Note: this functionality is not currently available in the official
+ * protobuf release, and it is not used for type URLs beginning with
+ * type.googleapis.com.
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
*
@@ -103,21 +114,55 @@ class Any extends \Google\Protobuf\Internal\Message
const TYPE_URL_PREFIX = 'type.googleapis.com/';
- public function __construct() {
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type string $type_url
+ * A URL/resource name that uniquely identifies the type of the serialized
+ * protocol buffer message. The last segment of the URL's path must represent
+ * the fully qualified name of the type (as in
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
+ * (e.g., leading "." is not accepted).
+ * In practice, teams usually precompile into the binary all types that they
+ * expect it to use in the context of Any. However, for URLs which use the
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
+ * server that maps type URLs to message definitions as follows:
+ * * If no scheme is provided, `https` is assumed.
+ * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+ * value in binary format, or produce an error.
+ * * Applications are allowed to cache lookup results based on the
+ * URL, or have them precompiled into a binary to avoid any
+ * lookup. Therefore, binary compatibility needs to be preserved
+ * on changes to types. (Use versioned type names to manage
+ * breaking changes.)
+ * Note: this functionality is not currently available in the official
+ * protobuf release, and it is not used for type URLs beginning with
+ * type.googleapis.com.
+ * Schemes other than `http`, `https` (or the empty scheme) might be
+ * used with implementation specific semantics.
+ * @type string $value
+ * Must be a valid serialized protocol buffer of the above specified type.
+ * }
+ */
+ public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Any::initOnce();
- parent::__construct();
+ parent::__construct($data);
}
/**
- * A URL/resource name whose content describes the type of the
- * serialized protocol buffer message.
- * For URLs which use the scheme `http`, `https`, or no scheme, the
- * following restrictions and interpretations apply:
+ * A URL/resource name that uniquely identifies the type of the serialized
+ * protocol buffer message. The last segment of the URL's path must represent
+ * the fully qualified name of the type (as in
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
+ * (e.g., leading "." is not accepted).
+ * In practice, teams usually precompile into the binary all types that they
+ * expect it to use in the context of Any. However, for URLs which use the
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
+ * server that maps type URLs to message definitions as follows:
* * If no scheme is provided, `https` is assumed.
- * * The last segment of the URL's path must represent the fully
- * qualified name of the type (as in `path/google.protobuf.Duration`).
- * The name should be in a canonical form (e.g., leading "." is
- * not accepted).
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
@@ -125,6 +170,9 @@ class Any extends \Google\Protobuf\Internal\Message
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
+ * Note: this functionality is not currently available in the official
+ * protobuf release, and it is not used for type URLs beginning with
+ * type.googleapis.com.
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
*
@@ -137,15 +185,16 @@ class Any extends \Google\Protobuf\Internal\Message
}
/**
- * A URL/resource name whose content describes the type of the
- * serialized protocol buffer message.
- * For URLs which use the scheme `http`, `https`, or no scheme, the
- * following restrictions and interpretations apply:
+ * A URL/resource name that uniquely identifies the type of the serialized
+ * protocol buffer message. The last segment of the URL's path must represent
+ * the fully qualified name of the type (as in
+ * `path/google.protobuf.Duration`). The name should be in a canonical form
+ * (e.g., leading "." is not accepted).
+ * In practice, teams usually precompile into the binary all types that they
+ * expect it to use in the context of Any. However, for URLs which use the
+ * scheme `http`, `https`, or no scheme, one can optionally set up a type
+ * server that maps type URLs to message definitions as follows:
* * If no scheme is provided, `https` is assumed.
- * * The last segment of the URL's path must represent the fully
- * qualified name of the type (as in `path/google.protobuf.Duration`).
- * The name should be in a canonical form (e.g., leading "." is
- * not accepted).
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
@@ -153,6 +202,9 @@ class Any extends \Google\Protobuf\Internal\Message
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
+ * Note: this functionality is not currently available in the official
+ * protobuf release, and it is not used for type URLs beginning with
+ * type.googleapis.com.
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
*
@@ -217,7 +269,7 @@ class Any extends \Google\Protobuf\Internal\Message
substr($this->type_url, $url_prifix_len);
// Create message according to fully qualified name.
- $pool = DescriptorPool::getGeneratedPool();
+ $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByProtoName( ".".$fully_qualifed_name);
if (is_null($desc)) {
throw new \Exception("Class ".$fully_qualifed_name
@@ -248,7 +300,7 @@ class Any extends \Google\Protobuf\Internal\Message
$this->value = $msg->serializeToString();
// Set type url.
- $pool = DescriptorPool::getGeneratedPool();
+ $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName(get_class($msg));
$fully_qualifed_name = $desc->getFullName();
$this->type_url = GPBUtil::TYPE_URL_PREFIX.substr(
@@ -262,7 +314,7 @@ class Any extends \Google\Protobuf\Internal\Message
*/
public function is($klass)
{
- $pool = DescriptorPool::getGeneratedPool();
+ $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName($klass);
$fully_qualifed_name = $desc->getFullName();
$type_url = GPBUtil::TYPE_URL_PREFIX.substr(
@@ -270,3 +322,4 @@ class Any extends \Google\Protobuf\Internal\Message
return $this->type_url === $type_url;
}
}
+