1ffe3c632Sopenharmony_ci<?php 2ffe3c632Sopenharmony_ci# Generated by the protocol buffer compiler. DO NOT EDIT! 3ffe3c632Sopenharmony_ci# source: google/protobuf/any.proto 4ffe3c632Sopenharmony_ci 5ffe3c632Sopenharmony_cinamespace Google\Protobuf; 6ffe3c632Sopenharmony_ci 7ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\GPBType; 8ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\Message; 9ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\RepeatedField; 10ffe3c632Sopenharmony_ciuse Google\Protobuf\Internal\GPBUtil; 11ffe3c632Sopenharmony_ci 12ffe3c632Sopenharmony_ci/** 13ffe3c632Sopenharmony_ci * `Any` contains an arbitrary serialized protocol buffer message along with a 14ffe3c632Sopenharmony_ci * URL that describes the type of the serialized message. 15ffe3c632Sopenharmony_ci * Protobuf library provides support to pack/unpack Any values in the form 16ffe3c632Sopenharmony_ci * of utility functions or additional generated methods of the Any type. 17ffe3c632Sopenharmony_ci * Example 1: Pack and unpack a message in C++. 18ffe3c632Sopenharmony_ci * Foo foo = ...; 19ffe3c632Sopenharmony_ci * Any any; 20ffe3c632Sopenharmony_ci * any.PackFrom(foo); 21ffe3c632Sopenharmony_ci * ... 22ffe3c632Sopenharmony_ci * if (any.UnpackTo(&foo)) { 23ffe3c632Sopenharmony_ci * ... 24ffe3c632Sopenharmony_ci * } 25ffe3c632Sopenharmony_ci * Example 2: Pack and unpack a message in Java. 26ffe3c632Sopenharmony_ci * Foo foo = ...; 27ffe3c632Sopenharmony_ci * Any any = Any.pack(foo); 28ffe3c632Sopenharmony_ci * ... 29ffe3c632Sopenharmony_ci * if (any.is(Foo.class)) { 30ffe3c632Sopenharmony_ci * foo = any.unpack(Foo.class); 31ffe3c632Sopenharmony_ci * } 32ffe3c632Sopenharmony_ci * Example 3: Pack and unpack a message in Python. 33ffe3c632Sopenharmony_ci * foo = Foo(...) 34ffe3c632Sopenharmony_ci * any = Any() 35ffe3c632Sopenharmony_ci * any.Pack(foo) 36ffe3c632Sopenharmony_ci * ... 37ffe3c632Sopenharmony_ci * if any.Is(Foo.DESCRIPTOR): 38ffe3c632Sopenharmony_ci * any.Unpack(foo) 39ffe3c632Sopenharmony_ci * ... 40ffe3c632Sopenharmony_ci * Example 4: Pack and unpack a message in Go 41ffe3c632Sopenharmony_ci * foo := &pb.Foo{...} 42ffe3c632Sopenharmony_ci * any, err := ptypes.MarshalAny(foo) 43ffe3c632Sopenharmony_ci * ... 44ffe3c632Sopenharmony_ci * foo := &pb.Foo{} 45ffe3c632Sopenharmony_ci * if err := ptypes.UnmarshalAny(any, foo); err != nil { 46ffe3c632Sopenharmony_ci * ... 47ffe3c632Sopenharmony_ci * } 48ffe3c632Sopenharmony_ci * The pack methods provided by protobuf library will by default use 49ffe3c632Sopenharmony_ci * 'type.googleapis.com/full.type.name' as the type URL and the unpack 50ffe3c632Sopenharmony_ci * methods only use the fully qualified type name after the last '/' 51ffe3c632Sopenharmony_ci * in the type URL, for example "foo.bar.com/x/y.z" will yield type 52ffe3c632Sopenharmony_ci * name "y.z". 53ffe3c632Sopenharmony_ci * JSON 54ffe3c632Sopenharmony_ci * ==== 55ffe3c632Sopenharmony_ci * The JSON representation of an `Any` value uses the regular 56ffe3c632Sopenharmony_ci * representation of the deserialized, embedded message, with an 57ffe3c632Sopenharmony_ci * additional field `@type` which contains the type URL. Example: 58ffe3c632Sopenharmony_ci * package google.profile; 59ffe3c632Sopenharmony_ci * message Person { 60ffe3c632Sopenharmony_ci * string first_name = 1; 61ffe3c632Sopenharmony_ci * string last_name = 2; 62ffe3c632Sopenharmony_ci * } 63ffe3c632Sopenharmony_ci * { 64ffe3c632Sopenharmony_ci * "@type": "type.googleapis.com/google.profile.Person", 65ffe3c632Sopenharmony_ci * "firstName": <string>, 66ffe3c632Sopenharmony_ci * "lastName": <string> 67ffe3c632Sopenharmony_ci * } 68ffe3c632Sopenharmony_ci * If the embedded message type is well-known and has a custom JSON 69ffe3c632Sopenharmony_ci * representation, that representation will be embedded adding a field 70ffe3c632Sopenharmony_ci * `value` which holds the custom JSON in addition to the `@type` 71ffe3c632Sopenharmony_ci * field. Example (for message [google.protobuf.Duration][]): 72ffe3c632Sopenharmony_ci * { 73ffe3c632Sopenharmony_ci * "@type": "type.googleapis.com/google.protobuf.Duration", 74ffe3c632Sopenharmony_ci * "value": "1.212s" 75ffe3c632Sopenharmony_ci * } 76ffe3c632Sopenharmony_ci * 77ffe3c632Sopenharmony_ci * Generated from protobuf message <code>google.protobuf.Any</code> 78ffe3c632Sopenharmony_ci */ 79ffe3c632Sopenharmony_ciclass Any extends \Google\Protobuf\Internal\Message 80ffe3c632Sopenharmony_ci{ 81ffe3c632Sopenharmony_ci /** 82ffe3c632Sopenharmony_ci * A URL/resource name that uniquely identifies the type of the serialized 83ffe3c632Sopenharmony_ci * protocol buffer message. The last segment of the URL's path must represent 84ffe3c632Sopenharmony_ci * the fully qualified name of the type (as in 85ffe3c632Sopenharmony_ci * `path/google.protobuf.Duration`). The name should be in a canonical form 86ffe3c632Sopenharmony_ci * (e.g., leading "." is not accepted). 87ffe3c632Sopenharmony_ci * In practice, teams usually precompile into the binary all types that they 88ffe3c632Sopenharmony_ci * expect it to use in the context of Any. However, for URLs which use the 89ffe3c632Sopenharmony_ci * scheme `http`, `https`, or no scheme, one can optionally set up a type 90ffe3c632Sopenharmony_ci * server that maps type URLs to message definitions as follows: 91ffe3c632Sopenharmony_ci * * If no scheme is provided, `https` is assumed. 92ffe3c632Sopenharmony_ci * * An HTTP GET on the URL must yield a [google.protobuf.Type][] 93ffe3c632Sopenharmony_ci * value in binary format, or produce an error. 94ffe3c632Sopenharmony_ci * * Applications are allowed to cache lookup results based on the 95ffe3c632Sopenharmony_ci * URL, or have them precompiled into a binary to avoid any 96ffe3c632Sopenharmony_ci * lookup. Therefore, binary compatibility needs to be preserved 97ffe3c632Sopenharmony_ci * on changes to types. (Use versioned type names to manage 98ffe3c632Sopenharmony_ci * breaking changes.) 99ffe3c632Sopenharmony_ci * Note: this functionality is not currently available in the official 100ffe3c632Sopenharmony_ci * protobuf release, and it is not used for type URLs beginning with 101ffe3c632Sopenharmony_ci * type.googleapis.com. 102ffe3c632Sopenharmony_ci * Schemes other than `http`, `https` (or the empty scheme) might be 103ffe3c632Sopenharmony_ci * used with implementation specific semantics. 104ffe3c632Sopenharmony_ci * 105ffe3c632Sopenharmony_ci * Generated from protobuf field <code>string type_url = 1;</code> 106ffe3c632Sopenharmony_ci */ 107ffe3c632Sopenharmony_ci private $type_url = ''; 108ffe3c632Sopenharmony_ci /** 109ffe3c632Sopenharmony_ci * Must be a valid serialized protocol buffer of the above specified type. 110ffe3c632Sopenharmony_ci * 111ffe3c632Sopenharmony_ci * Generated from protobuf field <code>bytes value = 2;</code> 112ffe3c632Sopenharmony_ci */ 113ffe3c632Sopenharmony_ci private $value = ''; 114ffe3c632Sopenharmony_ci 115ffe3c632Sopenharmony_ci const TYPE_URL_PREFIX = 'type.googleapis.com/'; 116ffe3c632Sopenharmony_ci 117ffe3c632Sopenharmony_ci /** 118ffe3c632Sopenharmony_ci * Constructor. 119ffe3c632Sopenharmony_ci * 120ffe3c632Sopenharmony_ci * @param array $data { 121ffe3c632Sopenharmony_ci * Optional. Data for populating the Message object. 122ffe3c632Sopenharmony_ci * 123ffe3c632Sopenharmony_ci * @type string $type_url 124ffe3c632Sopenharmony_ci * A URL/resource name that uniquely identifies the type of the serialized 125ffe3c632Sopenharmony_ci * protocol buffer message. The last segment of the URL's path must represent 126ffe3c632Sopenharmony_ci * the fully qualified name of the type (as in 127ffe3c632Sopenharmony_ci * `path/google.protobuf.Duration`). The name should be in a canonical form 128ffe3c632Sopenharmony_ci * (e.g., leading "." is not accepted). 129ffe3c632Sopenharmony_ci * In practice, teams usually precompile into the binary all types that they 130ffe3c632Sopenharmony_ci * expect it to use in the context of Any. However, for URLs which use the 131ffe3c632Sopenharmony_ci * scheme `http`, `https`, or no scheme, one can optionally set up a type 132ffe3c632Sopenharmony_ci * server that maps type URLs to message definitions as follows: 133ffe3c632Sopenharmony_ci * * If no scheme is provided, `https` is assumed. 134ffe3c632Sopenharmony_ci * * An HTTP GET on the URL must yield a [google.protobuf.Type][] 135ffe3c632Sopenharmony_ci * value in binary format, or produce an error. 136ffe3c632Sopenharmony_ci * * Applications are allowed to cache lookup results based on the 137ffe3c632Sopenharmony_ci * URL, or have them precompiled into a binary to avoid any 138ffe3c632Sopenharmony_ci * lookup. Therefore, binary compatibility needs to be preserved 139ffe3c632Sopenharmony_ci * on changes to types. (Use versioned type names to manage 140ffe3c632Sopenharmony_ci * breaking changes.) 141ffe3c632Sopenharmony_ci * Note: this functionality is not currently available in the official 142ffe3c632Sopenharmony_ci * protobuf release, and it is not used for type URLs beginning with 143ffe3c632Sopenharmony_ci * type.googleapis.com. 144ffe3c632Sopenharmony_ci * Schemes other than `http`, `https` (or the empty scheme) might be 145ffe3c632Sopenharmony_ci * used with implementation specific semantics. 146ffe3c632Sopenharmony_ci * @type string $value 147ffe3c632Sopenharmony_ci * Must be a valid serialized protocol buffer of the above specified type. 148ffe3c632Sopenharmony_ci * } 149ffe3c632Sopenharmony_ci */ 150ffe3c632Sopenharmony_ci public function __construct($data = NULL) { 151ffe3c632Sopenharmony_ci \GPBMetadata\Google\Protobuf\Any::initOnce(); 152ffe3c632Sopenharmony_ci parent::__construct($data); 153ffe3c632Sopenharmony_ci } 154ffe3c632Sopenharmony_ci 155ffe3c632Sopenharmony_ci /** 156ffe3c632Sopenharmony_ci * A URL/resource name that uniquely identifies the type of the serialized 157ffe3c632Sopenharmony_ci * protocol buffer message. The last segment of the URL's path must represent 158ffe3c632Sopenharmony_ci * the fully qualified name of the type (as in 159ffe3c632Sopenharmony_ci * `path/google.protobuf.Duration`). The name should be in a canonical form 160ffe3c632Sopenharmony_ci * (e.g., leading "." is not accepted). 161ffe3c632Sopenharmony_ci * In practice, teams usually precompile into the binary all types that they 162ffe3c632Sopenharmony_ci * expect it to use in the context of Any. However, for URLs which use the 163ffe3c632Sopenharmony_ci * scheme `http`, `https`, or no scheme, one can optionally set up a type 164ffe3c632Sopenharmony_ci * server that maps type URLs to message definitions as follows: 165ffe3c632Sopenharmony_ci * * If no scheme is provided, `https` is assumed. 166ffe3c632Sopenharmony_ci * * An HTTP GET on the URL must yield a [google.protobuf.Type][] 167ffe3c632Sopenharmony_ci * value in binary format, or produce an error. 168ffe3c632Sopenharmony_ci * * Applications are allowed to cache lookup results based on the 169ffe3c632Sopenharmony_ci * URL, or have them precompiled into a binary to avoid any 170ffe3c632Sopenharmony_ci * lookup. Therefore, binary compatibility needs to be preserved 171ffe3c632Sopenharmony_ci * on changes to types. (Use versioned type names to manage 172ffe3c632Sopenharmony_ci * breaking changes.) 173ffe3c632Sopenharmony_ci * Note: this functionality is not currently available in the official 174ffe3c632Sopenharmony_ci * protobuf release, and it is not used for type URLs beginning with 175ffe3c632Sopenharmony_ci * type.googleapis.com. 176ffe3c632Sopenharmony_ci * Schemes other than `http`, `https` (or the empty scheme) might be 177ffe3c632Sopenharmony_ci * used with implementation specific semantics. 178ffe3c632Sopenharmony_ci * 179ffe3c632Sopenharmony_ci * Generated from protobuf field <code>string type_url = 1;</code> 180ffe3c632Sopenharmony_ci * @return string 181ffe3c632Sopenharmony_ci */ 182ffe3c632Sopenharmony_ci public function getTypeUrl() 183ffe3c632Sopenharmony_ci { 184ffe3c632Sopenharmony_ci return $this->type_url; 185ffe3c632Sopenharmony_ci } 186ffe3c632Sopenharmony_ci 187ffe3c632Sopenharmony_ci /** 188ffe3c632Sopenharmony_ci * A URL/resource name that uniquely identifies the type of the serialized 189ffe3c632Sopenharmony_ci * protocol buffer message. The last segment of the URL's path must represent 190ffe3c632Sopenharmony_ci * the fully qualified name of the type (as in 191ffe3c632Sopenharmony_ci * `path/google.protobuf.Duration`). The name should be in a canonical form 192ffe3c632Sopenharmony_ci * (e.g., leading "." is not accepted). 193ffe3c632Sopenharmony_ci * In practice, teams usually precompile into the binary all types that they 194ffe3c632Sopenharmony_ci * expect it to use in the context of Any. However, for URLs which use the 195ffe3c632Sopenharmony_ci * scheme `http`, `https`, or no scheme, one can optionally set up a type 196ffe3c632Sopenharmony_ci * server that maps type URLs to message definitions as follows: 197ffe3c632Sopenharmony_ci * * If no scheme is provided, `https` is assumed. 198ffe3c632Sopenharmony_ci * * An HTTP GET on the URL must yield a [google.protobuf.Type][] 199ffe3c632Sopenharmony_ci * value in binary format, or produce an error. 200ffe3c632Sopenharmony_ci * * Applications are allowed to cache lookup results based on the 201ffe3c632Sopenharmony_ci * URL, or have them precompiled into a binary to avoid any 202ffe3c632Sopenharmony_ci * lookup. Therefore, binary compatibility needs to be preserved 203ffe3c632Sopenharmony_ci * on changes to types. (Use versioned type names to manage 204ffe3c632Sopenharmony_ci * breaking changes.) 205ffe3c632Sopenharmony_ci * Note: this functionality is not currently available in the official 206ffe3c632Sopenharmony_ci * protobuf release, and it is not used for type URLs beginning with 207ffe3c632Sopenharmony_ci * type.googleapis.com. 208ffe3c632Sopenharmony_ci * Schemes other than `http`, `https` (or the empty scheme) might be 209ffe3c632Sopenharmony_ci * used with implementation specific semantics. 210ffe3c632Sopenharmony_ci * 211ffe3c632Sopenharmony_ci * Generated from protobuf field <code>string type_url = 1;</code> 212ffe3c632Sopenharmony_ci * @param string $var 213ffe3c632Sopenharmony_ci * @return $this 214ffe3c632Sopenharmony_ci */ 215ffe3c632Sopenharmony_ci public function setTypeUrl($var) 216ffe3c632Sopenharmony_ci { 217ffe3c632Sopenharmony_ci GPBUtil::checkString($var, True); 218ffe3c632Sopenharmony_ci $this->type_url = $var; 219ffe3c632Sopenharmony_ci 220ffe3c632Sopenharmony_ci return $this; 221ffe3c632Sopenharmony_ci } 222ffe3c632Sopenharmony_ci 223ffe3c632Sopenharmony_ci /** 224ffe3c632Sopenharmony_ci * Must be a valid serialized protocol buffer of the above specified type. 225ffe3c632Sopenharmony_ci * 226ffe3c632Sopenharmony_ci * Generated from protobuf field <code>bytes value = 2;</code> 227ffe3c632Sopenharmony_ci * @return string 228ffe3c632Sopenharmony_ci */ 229ffe3c632Sopenharmony_ci public function getValue() 230ffe3c632Sopenharmony_ci { 231ffe3c632Sopenharmony_ci return $this->value; 232ffe3c632Sopenharmony_ci } 233ffe3c632Sopenharmony_ci 234ffe3c632Sopenharmony_ci /** 235ffe3c632Sopenharmony_ci * Must be a valid serialized protocol buffer of the above specified type. 236ffe3c632Sopenharmony_ci * 237ffe3c632Sopenharmony_ci * Generated from protobuf field <code>bytes value = 2;</code> 238ffe3c632Sopenharmony_ci * @param string $var 239ffe3c632Sopenharmony_ci * @return $this 240ffe3c632Sopenharmony_ci */ 241ffe3c632Sopenharmony_ci public function setValue($var) 242ffe3c632Sopenharmony_ci { 243ffe3c632Sopenharmony_ci GPBUtil::checkString($var, False); 244ffe3c632Sopenharmony_ci $this->value = $var; 245ffe3c632Sopenharmony_ci 246ffe3c632Sopenharmony_ci return $this; 247ffe3c632Sopenharmony_ci } 248ffe3c632Sopenharmony_ci 249ffe3c632Sopenharmony_ci /** 250ffe3c632Sopenharmony_ci * This method will try to resolve the type_url in Any message to get the 251ffe3c632Sopenharmony_ci * targeted message type. If failed, an error will be thrown. Otherwise, 252ffe3c632Sopenharmony_ci * the method will create a message of the targeted type and fill it with 253ffe3c632Sopenharmony_ci * the decoded value in Any. 254ffe3c632Sopenharmony_ci * @return Message unpacked message 255ffe3c632Sopenharmony_ci * @throws \Exception Type url needs to be type.googleapis.com/fully-qualified. 256ffe3c632Sopenharmony_ci * @throws \Exception Class hasn't been added to descriptor pool. 257ffe3c632Sopenharmony_ci * @throws \Exception cannot decode data in value field. 258ffe3c632Sopenharmony_ci */ 259ffe3c632Sopenharmony_ci public function unpack() 260ffe3c632Sopenharmony_ci { 261ffe3c632Sopenharmony_ci // Get fully qualified name from type url. 262ffe3c632Sopenharmony_ci $url_prifix_len = strlen(GPBUtil::TYPE_URL_PREFIX); 263ffe3c632Sopenharmony_ci if (substr($this->type_url, 0, $url_prifix_len) != 264ffe3c632Sopenharmony_ci GPBUtil::TYPE_URL_PREFIX) { 265ffe3c632Sopenharmony_ci throw new \Exception( 266ffe3c632Sopenharmony_ci "Type url needs to be type.googleapis.com/fully-qulified"); 267ffe3c632Sopenharmony_ci } 268ffe3c632Sopenharmony_ci $fully_qualifed_name = 269ffe3c632Sopenharmony_ci substr($this->type_url, $url_prifix_len); 270ffe3c632Sopenharmony_ci 271ffe3c632Sopenharmony_ci // Create message according to fully qualified name. 272ffe3c632Sopenharmony_ci $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool(); 273ffe3c632Sopenharmony_ci $desc = $pool->getDescriptorByProtoName($fully_qualifed_name); 274ffe3c632Sopenharmony_ci if (is_null($desc)) { 275ffe3c632Sopenharmony_ci throw new \Exception("Class ".$fully_qualifed_name 276ffe3c632Sopenharmony_ci ." hasn't been added to descriptor pool"); 277ffe3c632Sopenharmony_ci } 278ffe3c632Sopenharmony_ci $klass = $desc->getClass(); 279ffe3c632Sopenharmony_ci $msg = new $klass(); 280ffe3c632Sopenharmony_ci 281ffe3c632Sopenharmony_ci // Merge data into message. 282ffe3c632Sopenharmony_ci $msg->mergeFromString($this->value); 283ffe3c632Sopenharmony_ci return $msg; 284ffe3c632Sopenharmony_ci } 285ffe3c632Sopenharmony_ci 286ffe3c632Sopenharmony_ci /** 287ffe3c632Sopenharmony_ci * The type_url will be created according to the given message’s type and 288ffe3c632Sopenharmony_ci * the value is encoded data from the given message.. 289ffe3c632Sopenharmony_ci * @param message: A proto message. 290ffe3c632Sopenharmony_ci */ 291ffe3c632Sopenharmony_ci public function pack($msg) 292ffe3c632Sopenharmony_ci { 293ffe3c632Sopenharmony_ci if (!$msg instanceof Message) { 294ffe3c632Sopenharmony_ci trigger_error("Given parameter is not a message instance.", 295ffe3c632Sopenharmony_ci E_USER_ERROR); 296ffe3c632Sopenharmony_ci return; 297ffe3c632Sopenharmony_ci } 298ffe3c632Sopenharmony_ci 299ffe3c632Sopenharmony_ci // Set value using serialized message. 300ffe3c632Sopenharmony_ci $this->value = $msg->serializeToString(); 301ffe3c632Sopenharmony_ci 302ffe3c632Sopenharmony_ci // Set type url. 303ffe3c632Sopenharmony_ci $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool(); 304ffe3c632Sopenharmony_ci $desc = $pool->getDescriptorByClassName(get_class($msg)); 305ffe3c632Sopenharmony_ci $fully_qualifed_name = $desc->getFullName(); 306ffe3c632Sopenharmony_ci $this->type_url = GPBUtil::TYPE_URL_PREFIX . $fully_qualifed_name; 307ffe3c632Sopenharmony_ci } 308ffe3c632Sopenharmony_ci 309ffe3c632Sopenharmony_ci /** 310ffe3c632Sopenharmony_ci * This method returns whether the type_url in any_message is corresponded 311ffe3c632Sopenharmony_ci * to the given class. 312ffe3c632Sopenharmony_ci * @param klass: The fully qualified PHP class name of a proto message type. 313ffe3c632Sopenharmony_ci */ 314ffe3c632Sopenharmony_ci public function is($klass) 315ffe3c632Sopenharmony_ci { 316ffe3c632Sopenharmony_ci $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool(); 317ffe3c632Sopenharmony_ci $desc = $pool->getDescriptorByClassName($klass); 318ffe3c632Sopenharmony_ci $fully_qualifed_name = $desc->getFullName(); 319ffe3c632Sopenharmony_ci $type_url = GPBUtil::TYPE_URL_PREFIX . $fully_qualifed_name; 320ffe3c632Sopenharmony_ci return $this->type_url === $type_url; 321ffe3c632Sopenharmony_ci } 322ffe3c632Sopenharmony_ci} 323ffe3c632Sopenharmony_ci 324