diff options
Diffstat (limited to 'php/src/Google/Protobuf')
38 files changed, 4036 insertions, 43 deletions
diff --git a/php/src/Google/Protobuf/Any.php b/php/src/Google/Protobuf/Any.php new file mode 100644 index 00000000..a39c4e6a --- /dev/null +++ b/php/src/Google/Protobuf/Any.php @@ -0,0 +1,272 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/any.proto + +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; + +/** + * `Any` contains an arbitrary serialized protocol buffer message along with a + * URL that describes the type of the serialized message. + * Protobuf library provides support to pack/unpack Any values in the form + * of utility functions or additional generated methods of the Any type. + * Example 1: Pack and unpack a message in C++. + * Foo foo = ...; + * Any any; + * any.PackFrom(foo); + * ... + * if (any.UnpackTo(&foo)) { + * ... + * } + * Example 2: Pack and unpack a message in Java. + * Foo foo = ...; + * Any any = Any.pack(foo); + * ... + * if (any.is(Foo.class)) { + * foo = any.unpack(Foo.class); + * } + * Example 3: Pack and unpack a message in Python. + * foo = Foo(...) + * any = Any() + * any.Pack(foo) + * ... + * if any.Is(Foo.DESCRIPTOR): + * any.Unpack(foo) + * ... + * 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 '/' + * in the type URL, for example "foo.bar.com/x/y.z" will yield type + * name "y.z". + * JSON + * ==== + * The JSON representation of an `Any` value uses the regular + * representation of the deserialized, embedded message, with an + * additional field `@type` which contains the type URL. Example: + * package google.profile; + * message Person { + * string first_name = 1; + * string last_name = 2; + * } + * { + * "@type": "type.googleapis.com/google.profile.Person", + * "firstName": <string>, + * "lastName": <string> + * } + * If the embedded message type is well-known and has a custom JSON + * representation, that representation will be embedded adding a field + * `value` which holds the custom JSON in addition to the `@type` + * field. Example (for message [google.protobuf.Duration][]): + * { + * "@type": "type.googleapis.com/google.protobuf.Duration", + * "value": "1.212s" + * } + * + * Generated from protobuf message <code>google.protobuf.Any</code> + */ +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: + * * 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 + * 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.) + * Schemes other than `http`, `https` (or the empty scheme) might be + * used with implementation specific semantics. + * + * Generated from protobuf field <code>string type_url = 1;</code> + */ + private $type_url = ''; + /** + * Must be a valid serialized protocol buffer of the above specified type. + * + * Generated from protobuf field <code>bytes value = 2;</code> + */ + private $value = ''; + + const TYPE_URL_PREFIX = 'type.googleapis.com/'; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Any::initOnce(); + parent::__construct(); + } + + /** + * 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: + * * 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 + * 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.) + * Schemes other than `http`, `https` (or the empty scheme) might be + * used with implementation specific semantics. + * + * Generated from protobuf field <code>string type_url = 1;</code> + * @return string + */ + public function getTypeUrl() + { + return $this->type_url; + } + + /** + * 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: + * * 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 + * 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.) + * Schemes other than `http`, `https` (or the empty scheme) might be + * used with implementation specific semantics. + * + * Generated from protobuf field <code>string type_url = 1;</code> + * @param string $var + * @return $this + */ + public function setTypeUrl($var) + { + GPBUtil::checkString($var, True); + $this->type_url = $var; + + return $this; + } + + /** + * Must be a valid serialized protocol buffer of the above specified type. + * + * Generated from protobuf field <code>bytes value = 2;</code> + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * Must be a valid serialized protocol buffer of the above specified type. + * + * Generated from protobuf field <code>bytes value = 2;</code> + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, False); + $this->value = $var; + + return $this; + } + + /** + * This method will try to resolve the type_url in Any message to get the + * targeted message type. If failed, an error will be thrown. Otherwise, + * the method will create a message of the targeted type and fill it with + * the decoded value in Any. + * @return unpacked message + * @throws Exception Type url needs to be type.googleapis.com/fully-qulified. + * @throws Exception Class hasn't been added to descriptor pool. + * @throws Exception cannot decode data in value field. + */ + public function unpack() + { + // Get fully qualifed name from type url. + $url_prifix_len = strlen(Any::TYPE_URL_PREFIX); + if (substr($this->type_url, 0, $url_prifix_len) != + Any::TYPE_URL_PREFIX) { + throw new \Exception( + "Type url needs to be type.googleapis.com/fully-qulified"); + } + $fully_qualifed_name = + substr($this->type_url, $url_prifix_len); + + // Create message according to fully qualified name. + $pool = DescriptorPool::getGeneratedPool(); + $desc = $pool->getDescriptorByProtoName( ".".$fully_qualifed_name); + if (is_null($desc)) { + throw new \Exception("Class ".$fully_qualifed_name + ." hasn't been added to descriptor pool"); + } + $klass = $desc->getClass(); + $msg = new $klass(); + + // Merge data into message. + $msg->mergeFromString($this->value); + return $msg; + } + + /** + * The type_url will be created according to the given message’s type and + * the value is encoded data from the given message.. + * @param message: A proto message. + */ + public function pack($msg) + { + if (!$msg instanceof Message) { + trigger_error("Given parameter is not a message instance.", + E_USER_ERROR); + return; + } + + // Set value using serialzed message. + $this->value = $msg->serializeToString(); + + // Set type url. + $pool = DescriptorPool::getGeneratedPool(); + $desc = $pool->getDescriptorByClassName(get_class($msg)); + $fully_qualifed_name = $desc->getFullName(); + $this->type_url = Any::TYPE_URL_PREFIX.substr( + $fully_qualifed_name, 1, strlen($fully_qualifed_name)); + } + + /** + * This method returns whether the type_url in any_message is corresponded + * to the given class. + * @param klass: The fully qualified PHP class name of a proto message type. + */ + public function is($klass) + { + $pool = DescriptorPool::getGeneratedPool(); + $desc = $pool->getDescriptorByClassName($klass); + $fully_qualifed_name = $desc->getFullName(); + $type_url = Any::TYPE_URL_PREFIX.substr( + $fully_qualifed_name, 1, strlen($fully_qualifed_name)); + return $this->type_url === $type_url; + } +} diff --git a/php/src/Google/Protobuf/Api.php b/php/src/Google/Protobuf/Api.php new file mode 100644 index 00000000..d0dda3cd --- /dev/null +++ b/php/src/Google/Protobuf/Api.php @@ -0,0 +1,310 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/api.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Api is a light-weight descriptor for an API Interface. + * Interfaces are also described as "protocol buffer services" in some contexts, + * such as by the "service" keyword in a .proto file, but they are different + * from API Services, which represent a concrete implementation of an interface + * as opposed to simply a description of methods and bindings. They are also + * sometimes simply referred to as "APIs" in other contexts, such as the name of + * this message itself. See https://cloud.google.com/apis/design/glossary for + * detailed terminology. + * + * Generated from protobuf message <code>google.protobuf.Api</code> + */ +class Api extends \Google\Protobuf\Internal\Message +{ + /** + * The fully qualified name of this interface, including package name + * followed by the interface's simple name. + * + * Generated from protobuf field <code>string name = 1;</code> + */ + private $name = ''; + /** + * The methods of this interface, in unspecified order. + * + * Generated from protobuf field <code>repeated .google.protobuf.Method methods = 2;</code> + */ + private $methods; + /** + * Any metadata attached to the interface. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + */ + private $options; + /** + * A version string for this interface. If specified, must have the form + * `major-version.minor-version`, as in `1.10`. If the minor version is + * omitted, it defaults to zero. If the entire version field is empty, the + * major version is derived from the package name, as outlined below. If the + * field is not empty, the version in the package name will be verified to be + * consistent with what is provided here. + * The versioning schema uses [semantic + * versioning](http://semver.org) where the major version number + * indicates a breaking change and the minor version an additive, + * non-breaking change. Both version numbers are signals to users + * what to expect from different versions, and should be carefully + * chosen based on the product plan. + * The major version is also reflected in the package name of the + * interface, which must end in `v<major-version>`, as in + * `google.feature.v1`. For major versions 0 and 1, the suffix can + * be omitted. Zero major versions must only be used for + * experimental, non-GA interfaces. + * + * Generated from protobuf field <code>string version = 4;</code> + */ + private $version = ''; + /** + * Source context for the protocol buffer service represented by this + * message. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code> + */ + private $source_context = null; + /** + * Included interfaces. See [Mixin][]. + * + * Generated from protobuf field <code>repeated .google.protobuf.Mixin mixins = 6;</code> + */ + private $mixins; + /** + * The source syntax of the service. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code> + */ + private $syntax = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Api::initOnce(); + parent::__construct(); + } + + /** + * The fully qualified name of this interface, including package name + * followed by the interface's simple name. + * + * Generated from protobuf field <code>string name = 1;</code> + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The fully qualified name of this interface, including package name + * followed by the interface's simple name. + * + * Generated from protobuf field <code>string name = 1;</code> + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The methods of this interface, in unspecified order. + * + * Generated from protobuf field <code>repeated .google.protobuf.Method methods = 2;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMethods() + { + return $this->methods; + } + + /** + * The methods of this interface, in unspecified order. + * + * Generated from protobuf field <code>repeated .google.protobuf.Method methods = 2;</code> + * @param \Google\Protobuf\Method[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setMethods($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Method::class); + $this->methods = $arr; + + return $this; + } + + /** + * Any metadata attached to the interface. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Any metadata attached to the interface. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + * @param \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOptions($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class); + $this->options = $arr; + + return $this; + } + + /** + * A version string for this interface. If specified, must have the form + * `major-version.minor-version`, as in `1.10`. If the minor version is + * omitted, it defaults to zero. If the entire version field is empty, the + * major version is derived from the package name, as outlined below. If the + * field is not empty, the version in the package name will be verified to be + * consistent with what is provided here. + * The versioning schema uses [semantic + * versioning](http://semver.org) where the major version number + * indicates a breaking change and the minor version an additive, + * non-breaking change. Both version numbers are signals to users + * what to expect from different versions, and should be carefully + * chosen based on the product plan. + * The major version is also reflected in the package name of the + * interface, which must end in `v<major-version>`, as in + * `google.feature.v1`. For major versions 0 and 1, the suffix can + * be omitted. Zero major versions must only be used for + * experimental, non-GA interfaces. + * + * Generated from protobuf field <code>string version = 4;</code> + * @return string + */ + public function getVersion() + { + return $this->version; + } + + /** + * A version string for this interface. If specified, must have the form + * `major-version.minor-version`, as in `1.10`. If the minor version is + * omitted, it defaults to zero. If the entire version field is empty, the + * major version is derived from the package name, as outlined below. If the + * field is not empty, the version in the package name will be verified to be + * consistent with what is provided here. + * The versioning schema uses [semantic + * versioning](http://semver.org) where the major version number + * indicates a breaking change and the minor version an additive, + * non-breaking change. Both version numbers are signals to users + * what to expect from different versions, and should be carefully + * chosen based on the product plan. + * The major version is also reflected in the package name of the + * interface, which must end in `v<major-version>`, as in + * `google.feature.v1`. For major versions 0 and 1, the suffix can + * be omitted. Zero major versions must only be used for + * experimental, non-GA interfaces. + * + * Generated from protobuf field <code>string version = 4;</code> + * @param string $var + * @return $this + */ + public function setVersion($var) + { + GPBUtil::checkString($var, True); + $this->version = $var; + + return $this; + } + + /** + * Source context for the protocol buffer service represented by this + * message. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code> + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * Source context for the protocol buffer service represented by this + * message. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code> + * @param \Google\Protobuf\SourceContext $var + * @return $this + */ + public function setSourceContext($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\SourceContext::class); + $this->source_context = $var; + + return $this; + } + + /** + * Included interfaces. See [Mixin][]. + * + * Generated from protobuf field <code>repeated .google.protobuf.Mixin mixins = 6;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMixins() + { + return $this->mixins; + } + + /** + * Included interfaces. See [Mixin][]. + * + * Generated from protobuf field <code>repeated .google.protobuf.Mixin mixins = 6;</code> + * @param \Google\Protobuf\Mixin[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setMixins($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Mixin::class); + $this->mixins = $arr; + + return $this; + } + + /** + * The source syntax of the service. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code> + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax of the service. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code> + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/BoolValue.php b/php/src/Google/Protobuf/BoolValue.php new file mode 100644 index 00000000..c28bf941 --- /dev/null +++ b/php/src/Google/Protobuf/BoolValue.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `bool`. + * The JSON representation for `BoolValue` is JSON `true` and `false`. + * + * Generated from protobuf message <code>google.protobuf.BoolValue</code> + */ +class BoolValue extends \Google\Protobuf\Internal\Message +{ + /** + * The bool value. + * + * Generated from protobuf field <code>bool value = 1;</code> + */ + private $value = false; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The bool value. + * + * Generated from protobuf field <code>bool value = 1;</code> + * @return bool + */ + public function getValue() + { + return $this->value; + } + + /** + * The bool value. + * + * Generated from protobuf field <code>bool value = 1;</code> + * @param bool $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkBool($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/BytesValue.php b/php/src/Google/Protobuf/BytesValue.php new file mode 100644 index 00000000..d6a6b2e6 --- /dev/null +++ b/php/src/Google/Protobuf/BytesValue.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `bytes`. + * The JSON representation for `BytesValue` is JSON string. + * + * Generated from protobuf message <code>google.protobuf.BytesValue</code> + */ +class BytesValue extends \Google\Protobuf\Internal\Message +{ + /** + * The bytes value. + * + * Generated from protobuf field <code>bytes value = 1;</code> + */ + private $value = ''; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The bytes value. + * + * Generated from protobuf field <code>bytes value = 1;</code> + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * The bytes value. + * + * Generated from protobuf field <code>bytes value = 1;</code> + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, False); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/DoubleValue.php b/php/src/Google/Protobuf/DoubleValue.php new file mode 100644 index 00000000..6718ce3c --- /dev/null +++ b/php/src/Google/Protobuf/DoubleValue.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `double`. + * The JSON representation for `DoubleValue` is JSON number. + * + * Generated from protobuf message <code>google.protobuf.DoubleValue</code> + */ +class DoubleValue extends \Google\Protobuf\Internal\Message +{ + /** + * The double value. + * + * Generated from protobuf field <code>double value = 1;</code> + */ + private $value = 0.0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The double value. + * + * Generated from protobuf field <code>double value = 1;</code> + * @return float + */ + public function getValue() + { + return $this->value; + } + + /** + * The double value. + * + * Generated from protobuf field <code>double value = 1;</code> + * @param float $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkDouble($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Duration.php b/php/src/Google/Protobuf/Duration.php new file mode 100644 index 00000000..ca1c4c07 --- /dev/null +++ b/php/src/Google/Protobuf/Duration.php @@ -0,0 +1,153 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/duration.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * A Duration represents a signed, fixed-length span of time represented + * as a count of seconds and fractions of seconds at nanosecond + * resolution. It is independent of any calendar and concepts like "day" + * or "month". It is related to Timestamp in that the difference between + * two Timestamp values is a Duration and it can be added or subtracted + * from a Timestamp. Range is approximately +-10,000 years. + * # Examples + * Example 1: Compute Duration from two Timestamps in pseudo code. + * Timestamp start = ...; + * Timestamp end = ...; + * Duration duration = ...; + * duration.seconds = end.seconds - start.seconds; + * duration.nanos = end.nanos - start.nanos; + * if (duration.seconds < 0 && duration.nanos > 0) { + * duration.seconds += 1; + * duration.nanos -= 1000000000; + * } else if (durations.seconds > 0 && duration.nanos < 0) { + * duration.seconds -= 1; + * duration.nanos += 1000000000; + * } + * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. + * Timestamp start = ...; + * Duration duration = ...; + * Timestamp end = ...; + * end.seconds = start.seconds + duration.seconds; + * end.nanos = start.nanos + duration.nanos; + * if (end.nanos < 0) { + * end.seconds -= 1; + * end.nanos += 1000000000; + * } else if (end.nanos >= 1000000000) { + * end.seconds += 1; + * end.nanos -= 1000000000; + * } + * Example 3: Compute Duration from datetime.timedelta in Python. + * td = datetime.timedelta(days=3, minutes=10) + * duration = Duration() + * duration.FromTimedelta(td) + * # JSON Mapping + * In JSON format, the Duration type is encoded as a string rather than an + * object, where the string ends in the suffix "s" (indicating seconds) and + * is preceded by the number of seconds, with nanoseconds expressed as + * fractional seconds. For example, 3 seconds with 0 nanoseconds should be + * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should + * be expressed in JSON format as "3.000000001s", and 3 seconds and 1 + * microsecond should be expressed in JSON format as "3.000001s". + * + * Generated from protobuf message <code>google.protobuf.Duration</code> + */ +class Duration extends \Google\Protobuf\Internal\Message +{ + /** + * Signed seconds of the span of time. Must be from -315,576,000,000 + * to +315,576,000,000 inclusive. Note: these bounds are computed from: + * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + * + * Generated from protobuf field <code>int64 seconds = 1;</code> + */ + private $seconds = 0; + /** + * Signed fractions of a second at nanosecond resolution of the span + * of time. Durations less than one second are represented with a 0 + * `seconds` field and a positive or negative `nanos` field. For durations + * of one second or more, a non-zero value for the `nanos` field must be + * of the same sign as the `seconds` field. Must be from -999,999,999 + * to +999,999,999 inclusive. + * + * Generated from protobuf field <code>int32 nanos = 2;</code> + */ + private $nanos = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Duration::initOnce(); + parent::__construct(); + } + + /** + * Signed seconds of the span of time. Must be from -315,576,000,000 + * to +315,576,000,000 inclusive. Note: these bounds are computed from: + * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + * + * Generated from protobuf field <code>int64 seconds = 1;</code> + * @return int|string + */ + public function getSeconds() + { + return $this->seconds; + } + + /** + * Signed seconds of the span of time. Must be from -315,576,000,000 + * to +315,576,000,000 inclusive. Note: these bounds are computed from: + * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + * + * Generated from protobuf field <code>int64 seconds = 1;</code> + * @param int|string $var + * @return $this + */ + public function setSeconds($var) + { + GPBUtil::checkInt64($var); + $this->seconds = $var; + + return $this; + } + + /** + * Signed fractions of a second at nanosecond resolution of the span + * of time. Durations less than one second are represented with a 0 + * `seconds` field and a positive or negative `nanos` field. For durations + * of one second or more, a non-zero value for the `nanos` field must be + * of the same sign as the `seconds` field. Must be from -999,999,999 + * to +999,999,999 inclusive. + * + * Generated from protobuf field <code>int32 nanos = 2;</code> + * @return int + */ + public function getNanos() + { + return $this->nanos; + } + + /** + * Signed fractions of a second at nanosecond resolution of the span + * of time. Durations less than one second are represented with a 0 + * `seconds` field and a positive or negative `nanos` field. For durations + * of one second or more, a non-zero value for the `nanos` field must be + * of the same sign as the `seconds` field. Must be from -999,999,999 + * to +999,999,999 inclusive. + * + * Generated from protobuf field <code>int32 nanos = 2;</code> + * @param int $var + * @return $this + */ + public function setNanos($var) + { + GPBUtil::checkInt32($var); + $this->nanos = $var; + + return $this; + } +} + diff --git a/php/src/Google/Protobuf/Enum.php b/php/src/Google/Protobuf/Enum.php new file mode 100644 index 00000000..c63efc74 --- /dev/null +++ b/php/src/Google/Protobuf/Enum.php @@ -0,0 +1,185 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/type.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Enum type definition. + * + * Generated from protobuf message <code>google.protobuf.Enum</code> + */ +class Enum extends \Google\Protobuf\Internal\Message +{ + /** + * Enum type name. + * + * Generated from protobuf field <code>string name = 1;</code> + */ + private $name = ''; + /** + * Enum value definitions. + * + * Generated from protobuf field <code>repeated .google.protobuf.EnumValue enumvalue = 2;</code> + */ + private $enumvalue; + /** + * Protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + */ + private $options; + /** + * The source context. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 4;</code> + */ + private $source_context = null; + /** + * The source syntax. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 5;</code> + */ + private $syntax = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Type::initOnce(); + parent::__construct(); + } + + /** + * Enum type name. + * + * Generated from protobuf field <code>string name = 1;</code> + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Enum type name. + * + * Generated from protobuf field <code>string name = 1;</code> + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Enum value definitions. + * + * Generated from protobuf field <code>repeated .google.protobuf.EnumValue enumvalue = 2;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEnumvalue() + { + return $this->enumvalue; + } + + /** + * Enum value definitions. + * + * Generated from protobuf field <code>repeated .google.protobuf.EnumValue enumvalue = 2;</code> + * @param \Google\Protobuf\EnumValue[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setEnumvalue($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\EnumValue::class); + $this->enumvalue = $arr; + + return $this; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + * @param \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOptions($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class); + $this->options = $arr; + + return $this; + } + + /** + * The source context. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 4;</code> + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * The source context. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 4;</code> + * @param \Google\Protobuf\SourceContext $var + * @return $this + */ + public function setSourceContext($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\SourceContext::class); + $this->source_context = $var; + + return $this; + } + + /** + * The source syntax. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 5;</code> + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 5;</code> + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/EnumValue.php b/php/src/Google/Protobuf/EnumValue.php new file mode 100644 index 00000000..e102c29f --- /dev/null +++ b/php/src/Google/Protobuf/EnumValue.php @@ -0,0 +1,121 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/type.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Enum value definition. + * + * Generated from protobuf message <code>google.protobuf.EnumValue</code> + */ +class EnumValue extends \Google\Protobuf\Internal\Message +{ + /** + * Enum value name. + * + * Generated from protobuf field <code>string name = 1;</code> + */ + private $name = ''; + /** + * Enum value number. + * + * Generated from protobuf field <code>int32 number = 2;</code> + */ + private $number = 0; + /** + * Protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + */ + private $options; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Type::initOnce(); + parent::__construct(); + } + + /** + * Enum value name. + * + * Generated from protobuf field <code>string name = 1;</code> + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Enum value name. + * + * Generated from protobuf field <code>string name = 1;</code> + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Enum value number. + * + * Generated from protobuf field <code>int32 number = 2;</code> + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * Enum value number. + * + * Generated from protobuf field <code>int32 number = 2;</code> + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + + return $this; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code> + * @param \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOptions($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class); + $this->options = $arr; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Field.php b/php/src/Google/Protobuf/Field.php new file mode 100644 index 00000000..0b560d89 --- /dev/null +++ b/php/src/Google/Protobuf/Field.php @@ -0,0 +1,351 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/type.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * A single field of a message type. + * + * Generated from protobuf message <code>google.protobuf.Field</code> + */ +class Field extends \Google\Protobuf\Internal\Message +{ + /** + * The field type. + * + * Generated from protobuf field <code>.google.protobuf.Field.Kind kind = 1;</code> + */ + private $kind = 0; + /** + * The field cardinality. + * + * Generated from protobuf field <code>.google.protobuf.Field.Cardinality cardinality = 2;</code> + */ + private $cardinality = 0; + /** + * The field number. + * + * Generated from protobuf field <code>int32 number = 3;</code> + */ + private $number = 0; + /** + * The field name. + * + * Generated from protobuf field <code>string name = 4;</code> + */ + private $name = ''; + /** + * The field type URL, without the scheme, for message or enumeration + * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + * + * Generated from protobuf field <code>string type_url = 6;</code> + */ + private $type_url = ''; + /** + * The index of the field type in `Type.oneofs`, for message or enumeration + * types. The first type has index 1; zero means the type is not in the list. + * + * Generated from protobuf field <code>int32 oneof_index = 7;</code> + */ + private $oneof_index = 0; + /** + * Whether to use alternative packed wire representation. + * + * Generated from protobuf field <code>bool packed = 8;</code> + */ + private $packed = false; + /** + * The protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 9;</code> + */ + private $options; + /** + * The field JSON name. + * + * Generated from protobuf field <code>string json_name = 10;</code> + */ + private $json_name = ''; + /** + * The string value of the default value of this field. Proto2 syntax only. + * + * Generated from protobuf field <code>string default_value = 11;</code> + */ + private $default_value = ''; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Type::initOnce(); + parent::__construct(); + } + + /** + * The field type. + * + * Generated from protobuf field <code>.google.protobuf.Field.Kind kind = 1;</code> + * @return int + */ + public function getKind() + { + return $this->kind; + } + + /** + * The field type. + * + * Generated from protobuf field <code>.google.protobuf.Field.Kind kind = 1;</code> + * @param int $var + * @return $this + */ + public function setKind($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Field_Kind::class); + $this->kind = $var; + + return $this; + } + + /** + * The field cardinality. + * + * Generated from protobuf field <code>.google.protobuf.Field.Cardinality cardinality = 2;</code> + * @return int + */ + public function getCardinality() + { + return $this->cardinality; + } + + /** + * The field cardinality. + * + * Generated from protobuf field <code>.google.protobuf.Field.Cardinality cardinality = 2;</code> + * @param int $var + * @return $this + */ + public function setCardinality($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Field_Cardinality::class); + $this->cardinality = $var; + + return $this; + } + + /** + * The field number. + * + * Generated from protobuf field <code>int32 number = 3;</code> + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * The field number. + * + * Generated from protobuf field <code>int32 number = 3;</code> + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + + return $this; + } + + /** + * The field name. + * + * Generated from protobuf field <code>string name = 4;</code> + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The field name. + * + * Generated from protobuf field <code>string name = 4;</code> + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The field type URL, without the scheme, for message or enumeration + * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + * + * Generated from protobuf field <code>string type_url = 6;</code> + * @return string + */ + public function getTypeUrl() + { + return $this->type_url; + } + + /** + * The field type URL, without the scheme, for message or enumeration + * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + * + * Generated from protobuf field <code>string type_url = 6;</code> + * @param string $var + * @return $this + */ + public function setTypeUrl($var) + { + GPBUtil::checkString($var, True); + $this->type_url = $var; + + return $this; + } + + /** + * The index of the field type in `Type.oneofs`, for message or enumeration + * types. The first type has index 1; zero means the type is not in the list. + * + * Generated from protobuf field <code>int32 oneof_index = 7;</code> + * @return int + */ + public function getOneofIndex() + { + return $this->oneof_index; + } + + /** + * The index of the field type in `Type.oneofs`, for message or enumeration + * types. The first type has index 1; zero means the type is not in the list. + * + * Generated from protobuf field <code>int32 oneof_index = 7;</code> + * @param int $var + * @return $this + */ + public function setOneofIndex($var) + { + GPBUtil::checkInt32($var); + $this->oneof_index = $var; + + return $this; + } + + /** + * Whether to use alternative packed wire representation. + * + * Generated from protobuf field <code>bool packed = 8;</code> + * @return bool + */ + public function getPacked() + { + return $this->packed; + } + + /** + * Whether to use alternative packed wire representation. + * + * Generated from protobuf field <code>bool packed = 8;</code> + * @param bool $var + * @return $this + */ + public function setPacked($var) + { + GPBUtil::checkBool($var); + $this->packed = $var; + + return $this; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 9;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 9;</code> + * @param \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOptions($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class); + $this->options = $arr; + + return $this; + } + + /** + * The field JSON name. + * + * Generated from protobuf field <code>string json_name = 10;</code> + * @return string + */ + public function getJsonName() + { + return $this->json_name; + } + + /** + * The field JSON name. + * + * Generated from protobuf field <code>string json_name = 10;</code> + * @param string $var + * @return $this + */ + public function setJsonName($var) + { + GPBUtil::checkString($var, True); + $this->json_name = $var; + + return $this; + } + + /** + * The string value of the default value of this field. Proto2 syntax only. + * + * Generated from protobuf field <code>string default_value = 11;</code> + * @return string + */ + public function getDefaultValue() + { + return $this->default_value; + } + + /** + * The string value of the default value of this field. Proto2 syntax only. + * + * Generated from protobuf field <code>string default_value = 11;</code> + * @param string $var + * @return $this + */ + public function setDefaultValue($var) + { + GPBUtil::checkString($var, True); + $this->default_value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/FieldMask.php b/php/src/Google/Protobuf/FieldMask.php new file mode 100644 index 00000000..e18586af --- /dev/null +++ b/php/src/Google/Protobuf/FieldMask.php @@ -0,0 +1,209 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/field_mask.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * `FieldMask` represents a set of symbolic field paths, for example: + * paths: "f.a" + * paths: "f.b.d" + * Here `f` represents a field in some root message, `a` and `b` + * fields in the message found in `f`, and `d` a field found in the + * message in `f.b`. + * Field masks are used to specify a subset of fields that should be + * returned by a get operation or modified by an update operation. + * Field masks also have a custom JSON encoding (see below). + * # Field Masks in Projections + * When used in the context of a projection, a response message or + * sub-message is filtered by the API to only contain those fields as + * specified in the mask. For example, if the mask in the previous + * example is applied to a response message as follows: + * f { + * a : 22 + * b { + * d : 1 + * x : 2 + * } + * y : 13 + * } + * z: 8 + * The result will not contain specific values for fields x,y and z + * (their value will be set to the default, and omitted in proto text + * output): + * f { + * a : 22 + * b { + * d : 1 + * } + * } + * A repeated field is not allowed except at the last position of a + * paths string. + * If a FieldMask object is not present in a get operation, the + * operation applies to all fields (as if a FieldMask of all fields + * had been specified). + * Note that a field mask does not necessarily apply to the + * top-level response message. In case of a REST get operation, the + * field mask applies directly to the response, but in case of a REST + * list operation, the mask instead applies to each individual message + * in the returned resource list. In case of a REST custom method, + * other definitions may be used. Where the mask applies will be + * clearly documented together with its declaration in the API. In + * any case, the effect on the returned resource/resources is required + * behavior for APIs. + * # Field Masks in Update Operations + * A field mask in update operations specifies which fields of the + * targeted resource are going to be updated. The API is required + * to only change the values of the fields as specified in the mask + * and leave the others untouched. If a resource is passed in to + * describe the updated values, the API ignores the values of all + * fields not covered by the mask. + * If a repeated field is specified for an update operation, the existing + * repeated values in the target resource will be overwritten by the new values. + * Note that a repeated field is only allowed in the last position of a `paths` + * string. + * If a sub-message is specified in the last position of the field mask for an + * update operation, then the existing sub-message in the target resource is + * overwritten. Given the target message: + * f { + * b { + * d : 1 + * x : 2 + * } + * c : 1 + * } + * And an update message: + * f { + * b { + * d : 10 + * } + * } + * then if the field mask is: + * paths: "f.b" + * then the result will be: + * f { + * b { + * d : 10 + * } + * c : 1 + * } + * However, if the update mask was: + * paths: "f.b.d" + * then the result would be: + * f { + * b { + * d : 10 + * x : 2 + * } + * c : 1 + * } + * In order to reset a field's value to the default, the field must + * be in the mask and set to the default value in the provided resource. + * Hence, in order to reset all fields of a resource, provide a default + * instance of the resource and set all fields in the mask, or do + * not provide a mask as described below. + * If a field mask is not present on update, the operation applies to + * all fields (as if a field mask of all fields has been specified). + * Note that in the presence of schema evolution, this may mean that + * fields the client does not know and has therefore not filled into + * the request will be reset to their default. If this is unwanted + * behavior, a specific service may require a client to always specify + * a field mask, producing an error if not. + * As with get operations, the location of the resource which + * describes the updated values in the request message depends on the + * operation kind. In any case, the effect of the field mask is + * required to be honored by the API. + * ## Considerations for HTTP REST + * The HTTP kind of an update operation which uses a field mask must + * be set to PATCH instead of PUT in order to satisfy HTTP semantics + * (PUT must only be used for full updates). + * # JSON Encoding of Field Masks + * In JSON, a field mask is encoded as a single string where paths are + * separated by a comma. Fields name in each path are converted + * to/from lower-camel naming conventions. + * As an example, consider the following message declarations: + * message Profile { + * User user = 1; + * Photo photo = 2; + * } + * message User { + * string display_name = 1; + * string address = 2; + * } + * In proto a field mask for `Profile` may look as such: + * mask { + * paths: "user.display_name" + * paths: "photo" + * } + * In JSON, the same mask is represented as below: + * { + * mask: "user.displayName,photo" + * } + * # Field Masks and Oneof Fields + * Field masks treat fields in oneofs just as regular fields. Consider the + * following message: + * message SampleMessage { + * oneof test_oneof { + * string name = 4; + * SubMessage sub_message = 9; + * } + * } + * The field mask can be: + * mask { + * paths: "name" + * } + * Or: + * mask { + * paths: "sub_message" + * } + * Note that oneof type names ("test_oneof" in this case) cannot be used in + * paths. + * + * Generated from protobuf message <code>google.protobuf.FieldMask</code> + */ +class FieldMask extends \Google\Protobuf\Internal\Message +{ + /** + * The set of field mask paths. + * + * Generated from protobuf field <code>repeated string paths = 1;</code> + */ + private $paths; + + public function __construct() { + \GPBMetadata\Google\Protobuf\FieldMask::initOnce(); + parent::__construct(); + } + + /** + * The set of field mask paths. + * + * Generated from protobuf field <code>repeated string paths = 1;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getPaths() + { + return $this->paths; + } + + /** + * The set of field mask paths. + * + * Generated from protobuf field <code>repeated string paths = 1;</code> + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setPaths($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->paths = $arr; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Field_Cardinality.php b/php/src/Google/Protobuf/Field_Cardinality.php new file mode 100644 index 00000000..422587ca --- /dev/null +++ b/php/src/Google/Protobuf/Field_Cardinality.php @@ -0,0 +1,39 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/type.proto + +namespace Google\Protobuf; + +/** + * Whether a field is optional, required, or repeated. + * + * Protobuf enum <code>Google\Protobuf\Field\Cardinality</code> + */ +class Field_Cardinality +{ + /** + * For fields with unknown cardinality. + * + * Generated from protobuf enum <code>CARDINALITY_UNKNOWN = 0;</code> + */ + const CARDINALITY_UNKNOWN = 0; + /** + * For optional fields. + * + * Generated from protobuf enum <code>CARDINALITY_OPTIONAL = 1;</code> + */ + const CARDINALITY_OPTIONAL = 1; + /** + * For required fields. Proto2 syntax only. + * + * Generated from protobuf enum <code>CARDINALITY_REQUIRED = 2;</code> + */ + const CARDINALITY_REQUIRED = 2; + /** + * For repeated fields. + * + * Generated from protobuf enum <code>CARDINALITY_REPEATED = 3;</code> + */ + const CARDINALITY_REPEATED = 3; +} + diff --git a/php/src/Google/Protobuf/Field_Kind.php b/php/src/Google/Protobuf/Field_Kind.php new file mode 100644 index 00000000..d0774970 --- /dev/null +++ b/php/src/Google/Protobuf/Field_Kind.php @@ -0,0 +1,129 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/type.proto + +namespace Google\Protobuf; + +/** + * Basic field types. + * + * Protobuf enum <code>Google\Protobuf\Field\Kind</code> + */ +class Field_Kind +{ + /** + * Field type unknown. + * + * Generated from protobuf enum <code>TYPE_UNKNOWN = 0;</code> + */ + const TYPE_UNKNOWN = 0; + /** + * Field type double. + * + * Generated from protobuf enum <code>TYPE_DOUBLE = 1;</code> + */ + const TYPE_DOUBLE = 1; + /** + * Field type float. + * + * Generated from protobuf enum <code>TYPE_FLOAT = 2;</code> + */ + const TYPE_FLOAT = 2; + /** + * Field type int64. + * + * Generated from protobuf enum <code>TYPE_INT64 = 3;</code> + */ + const TYPE_INT64 = 3; + /** + * Field type uint64. + * + * Generated from protobuf enum <code>TYPE_UINT64 = 4;</code> + */ + const TYPE_UINT64 = 4; + /** + * Field type int32. + * + * Generated from protobuf enum <code>TYPE_INT32 = 5;</code> + */ + const TYPE_INT32 = 5; + /** + * Field type fixed64. + * + * Generated from protobuf enum <code>TYPE_FIXED64 = 6;</code> + */ + const TYPE_FIXED64 = 6; + /** + * Field type fixed32. + * + * Generated from protobuf enum <code>TYPE_FIXED32 = 7;</code> + */ + const TYPE_FIXED32 = 7; + /** + * Field type bool. + * + * Generated from protobuf enum <code>TYPE_BOOL = 8;</code> + */ + const TYPE_BOOL = 8; + /** + * Field type string. + * + * Generated from protobuf enum <code>TYPE_STRING = 9;</code> + */ + const TYPE_STRING = 9; + /** + * Field type group. Proto2 syntax only, and deprecated. + * + * Generated from protobuf enum <code>TYPE_GROUP = 10;</code> + */ + const TYPE_GROUP = 10; + /** + * Field type message. + * + * Generated from protobuf enum <code>TYPE_MESSAGE = 11;</code> + */ + const TYPE_MESSAGE = 11; + /** + * Field type bytes. + * + * Generated from protobuf enum <code>TYPE_BYTES = 12;</code> + */ + const TYPE_BYTES = 12; + /** + * Field type uint32. + * + * Generated from protobuf enum <code>TYPE_UINT32 = 13;</code> + */ + const TYPE_UINT32 = 13; + /** + * Field type enum. + * + * Generated from protobuf enum <code>TYPE_ENUM = 14;</code> + */ + const TYPE_ENUM = 14; + /** + * Field type sfixed32. + * + * Generated from protobuf enum <code>TYPE_SFIXED32 = 15;</code> + */ + const TYPE_SFIXED32 = 15; + /** + * Field type sfixed64. + * + * Generated from protobuf enum <code>TYPE_SFIXED64 = 16;</code> + */ + const TYPE_SFIXED64 = 16; + /** + * Field type sint32. + * + * Generated from protobuf enum <code>TYPE_SINT32 = 17;</code> + */ + const TYPE_SINT32 = 17; + /** + * Field type sint64. + * + * Generated from protobuf enum <code>TYPE_SINT64 = 18;</code> + */ + const TYPE_SINT64 = 18; +} + diff --git a/php/src/Google/Protobuf/FloatValue.php b/php/src/Google/Protobuf/FloatValue.php new file mode 100644 index 00000000..68787ef9 --- /dev/null +++ b/php/src/Google/Protobuf/FloatValue.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `float`. + * The JSON representation for `FloatValue` is JSON number. + * + * Generated from protobuf message <code>google.protobuf.FloatValue</code> + */ +class FloatValue extends \Google\Protobuf\Internal\Message +{ + /** + * The float value. + * + * Generated from protobuf field <code>float value = 1;</code> + */ + private $value = 0.0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The float value. + * + * Generated from protobuf field <code>float value = 1;</code> + * @return float + */ + public function getValue() + { + return $this->value; + } + + /** + * The float value. + * + * Generated from protobuf field <code>float value = 1;</code> + * @param float $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkFloat($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/GPBEmpty.php b/php/src/Google/Protobuf/GPBEmpty.php new file mode 100644 index 00000000..24a93f96 --- /dev/null +++ b/php/src/Google/Protobuf/GPBEmpty.php @@ -0,0 +1,31 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/empty.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * A generic empty message that you can re-use to avoid defining duplicated + * empty messages in your APIs. A typical example is to use it as the request + * or the response type of an API method. For instance: + * service Foo { + * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); + * } + * The JSON representation for `Empty` is empty JSON object `{}`. + * + * Generated from protobuf message <code>google.protobuf.Empty</code> + */ +class GPBEmpty extends \Google\Protobuf\Internal\Message +{ + + public function __construct() { + \GPBMetadata\Google\Protobuf\GPBEmpty::initOnce(); + parent::__construct(); + } + +} + diff --git a/php/src/Google/Protobuf/Int32Value.php b/php/src/Google/Protobuf/Int32Value.php new file mode 100644 index 00000000..d48aff1b --- /dev/null +++ b/php/src/Google/Protobuf/Int32Value.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `int32`. + * The JSON representation for `Int32Value` is JSON number. + * + * Generated from protobuf message <code>google.protobuf.Int32Value</code> + */ +class Int32Value extends \Google\Protobuf\Internal\Message +{ + /** + * The int32 value. + * + * Generated from protobuf field <code>int32 value = 1;</code> + */ + private $value = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The int32 value. + * + * Generated from protobuf field <code>int32 value = 1;</code> + * @return int + */ + public function getValue() + { + return $this->value; + } + + /** + * The int32 value. + * + * Generated from protobuf field <code>int32 value = 1;</code> + * @param int $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkInt32($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Int64Value.php b/php/src/Google/Protobuf/Int64Value.php new file mode 100644 index 00000000..a6fb9c5d --- /dev/null +++ b/php/src/Google/Protobuf/Int64Value.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `int64`. + * The JSON representation for `Int64Value` is JSON string. + * + * Generated from protobuf message <code>google.protobuf.Int64Value</code> + */ +class Int64Value extends \Google\Protobuf\Internal\Message +{ + /** + * The int64 value. + * + * Generated from protobuf field <code>int64 value = 1;</code> + */ + private $value = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The int64 value. + * + * Generated from protobuf field <code>int64 value = 1;</code> + * @return int|string + */ + public function getValue() + { + return $this->value; + } + + /** + * The int64 value. + * + * Generated from protobuf field <code>int64 value = 1;</code> + * @param int|string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkInt64($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Internal/CodedInputStream.php b/php/src/Google/Protobuf/Internal/CodedInputStream.php index 6131d5d1..b612da5b 100644 --- a/php/src/Google/Protobuf/Internal/CodedInputStream.php +++ b/php/src/Google/Protobuf/Internal/CodedInputStream.php @@ -78,13 +78,18 @@ class CodedInputStream return $this->buffer_end - $this->current; } - private function current() + public function current() { return $this->total_bytes_read - ($this->buffer_end - $this->current + $this->buffer_size_after_limit); } + public function substr($start, $end) + { + return substr($this->buffer, $start, $end - $start); + } + private function recomputeBufferLimits() { $this->buffer_end += $this->buffer_size_after_limit; diff --git a/php/src/Google/Protobuf/Internal/CodedOutputStream.php b/php/src/Google/Protobuf/Internal/CodedOutputStream.php index 4525d8dd..f75e9c66 100644 --- a/php/src/Google/Protobuf/Internal/CodedOutputStream.php +++ b/php/src/Google/Protobuf/Internal/CodedOutputStream.php @@ -101,7 +101,7 @@ class CodedOutputStream return true; } - private static function writeVarintToArray($value, &$buffer, $trim = false) + public static function writeVarintToArray($value, &$buffer, $trim = false) { $current = 0; diff --git a/php/src/Google/Protobuf/Internal/DescriptorPool.php b/php/src/Google/Protobuf/Internal/DescriptorPool.php index 65d1a884..304c1615 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorPool.php +++ b/php/src/Google/Protobuf/Internal/DescriptorPool.php @@ -109,18 +109,30 @@ class DescriptorPool public function getDescriptorByClassName($klass) { - return $this->class_to_desc[$klass]; + if (isset($this->class_to_desc[$klass])) { + return $this->class_to_desc[$klass]; + } else { + return null; + } } public function getEnumDescriptorByClassName($klass) { - return $this->class_to_enum_desc[$klass]; + if (isset($this->class_to_enum_desc[$klass])) { + return $this->class_to_enum_desc[$klass]; + } else { + return null; + } } public function getDescriptorByProtoName($proto) { - $klass = $this->proto_to_class[$proto]; - return $this->class_to_desc[$klass]; + if (isset($this->proto_to_class[$proto])) { + $klass = $this->proto_to_class[$proto]; + return $this->class_to_desc[$klass]; + } else { + return null; + } } public function getEnumDescriptorByProtoName($proto) diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php index 816fbae5..930f26ef 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php @@ -32,6 +32,23 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message */ private $options = null; private $has_options = false; + /** + * Range of reserved numeric values. Reserved numeric values may not be used + * by enum values in the same enum declaration. Reserved ranges may not + * overlap. + * + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4;</code> + */ + private $reserved_range; + private $has_reserved_range = false; + /** + * Reserved enum value names, which may not be reused. A given name may only + * be reserved once. + * + * Generated from protobuf field <code>repeated string reserved_name = 5;</code> + */ + private $reserved_name; + private $has_reserved_name = false; public function __construct() { \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); @@ -122,5 +139,75 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message return $this->has_options; } + /** + * Range of reserved numeric values. Reserved numeric values may not be used + * by enum values in the same enum declaration. Reserved ranges may not + * overlap. + * + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getReservedRange() + { + return $this->reserved_range; + } + + /** + * Range of reserved numeric values. Reserved numeric values may not be used + * by enum values in the same enum declaration. Reserved ranges may not + * overlap. + * + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4;</code> + * @param \Google\Protobuf\Internal\EnumDescriptorProto_EnumReservedRange[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setReservedRange($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto_EnumReservedRange::class); + $this->reserved_range = $arr; + $this->has_reserved_range = true; + + return $this; + } + + public function hasReservedRange() + { + return $this->has_reserved_range; + } + + /** + * Reserved enum value names, which may not be reused. A given name may only + * be reserved once. + * + * Generated from protobuf field <code>repeated string reserved_name = 5;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getReservedName() + { + return $this->reserved_name; + } + + /** + * Reserved enum value names, which may not be reused. A given name may only + * be reserved once. + * + * Generated from protobuf field <code>repeated string reserved_name = 5;</code> + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setReservedName($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->reserved_name = $arr; + $this->has_reserved_name = true; + + return $this; + } + + public function hasReservedName() + { + return $this->has_reserved_name; + } + } diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php new file mode 100644 index 00000000..6b2449fa --- /dev/null +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php @@ -0,0 +1,109 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/descriptor.proto + +namespace Google\Protobuf\Internal; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\GPBWire; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\InputStream; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Range of reserved numeric values. Reserved values may not be used by + * entries in the same enum. Reserved ranges may not overlap. + * Note that this is distinct from DescriptorProto.ReservedRange in that it + * is inclusive such that it can appropriately represent the entire int32 + * domain. + * + * Generated from protobuf message <code>google.protobuf.EnumDescriptorProto.EnumReservedRange</code> + */ +class EnumDescriptorProto_EnumReservedRange extends \Google\Protobuf\Internal\Message +{ + /** + * Inclusive. + * + * Generated from protobuf field <code>optional int32 start = 1;</code> + */ + private $start = 0; + private $has_start = false; + /** + * Inclusive. + * + * Generated from protobuf field <code>optional int32 end = 2;</code> + */ + private $end = 0; + private $has_end = false; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct(); + } + + /** + * Inclusive. + * + * Generated from protobuf field <code>optional int32 start = 1;</code> + * @return int + */ + public function getStart() + { + return $this->start; + } + + /** + * Inclusive. + * + * Generated from protobuf field <code>optional int32 start = 1;</code> + * @param int $var + * @return $this + */ + public function setStart($var) + { + GPBUtil::checkInt32($var); + $this->start = $var; + $this->has_start = true; + + return $this; + } + + public function hasStart() + { + return $this->has_start; + } + + /** + * Inclusive. + * + * Generated from protobuf field <code>optional int32 end = 2;</code> + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Inclusive. + * + * Generated from protobuf field <code>optional int32 end = 2;</code> + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + +} + diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptor.php b/php/src/Google/Protobuf/Internal/FieldDescriptor.php index 1443c6fd..6644a2e0 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptor.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptor.php @@ -181,6 +181,12 @@ class FieldDescriptor $this->getMessageType()->getOptions()->getMapEntry(); } + public function isTimestamp() + { + return $this->getType() == GPBType::MESSAGE && + $this->getMessageType()->getClass() === "Google\Protobuf\Timestamp"; + } + private static function isTypePackable($field_type) { return ($field_type !== GPBType::STRING && diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 964d4f68..7fa4a673 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -38,6 +38,9 @@ use Google\Protobuf\Internal\MapField; class GPBUtil { + const NANOS_PER_MILLISECOND = 1000000; + const NANOS_PER_MICROSECOND = 1000; + public static function divideInt64ToInt32($value, &$high, &$low, $trim = false) { $isNeg = (bccomp($value, 0) < 0); @@ -355,4 +358,81 @@ class GPBUtil } return $result; } + + public static function parseTimestamp($timestamp) + { + // prevent parsing timestamps containing with the non-existant year "0000" + // DateTime::createFromFormat parses without failing but as a nonsensical date + if (substr($timestamp, 0, 4) === "0000") { + throw new \Exception("Year cannot be zero."); + } + // prevent parsing timestamps ending with a lowercase z + if (substr($timestamp, -1, 1) === "z") { + throw new \Exception("Timezone cannot be a lowercase z."); + } + + $nanoseconds = 0; + $periodIndex = strpos($timestamp, "."); + if ($periodIndex !== false) { + $nanosecondsLength = 0; + // find the next non-numeric character in the timestamp to calculate + // the length of the nanoseconds text + for ($i = $periodIndex + 1, $length = strlen($timestamp); $i < $length; $i++) { + if (!is_numeric($timestamp[$i])) { + $nanosecondsLength = $i - ($periodIndex + 1); + break; + } + } + if ($nanosecondsLength % 3 !== 0) { + throw new \Exception("Nanoseconds must be disible by 3."); + } + if ($nanosecondsLength > 9) { + throw new \Exception("Nanoseconds must be in the range of 0 to 999,999,999 nanoseconds."); + } + if ($nanosecondsLength > 0) { + $nanoseconds = substr($timestamp, $periodIndex + 1, $nanosecondsLength); + $nanoseconds = intval($nanoseconds); + + // remove the nanoseconds and preceding period from the timestamp + $date = substr($timestamp, 0, $periodIndex - 1); + $timezone = substr($timestamp, $periodIndex + $nanosecondsLength); + $timestamp = $date.$timezone; + } + } + + $date = \DateTime::createFromFormat(\DateTime::RFC3339, $timestamp, new \DateTimeZone("UTC")); + if ($date === false) { + throw new \Exception("Invalid RFC 3339 timestamp."); + } + + $value = new \Google\Protobuf\Timestamp(); + $seconds = $date->format("U"); + $value->setSeconds($seconds); + $value->setNanos($nanoseconds); + return $value; + } + + public static function formatTimestamp($value) + { + $nanoseconds = static::getNanosecondsForTimestamp($value->getNanos()); + if (!empty($nanoseconds)) { + $nanoseconds = ".".$nanoseconds; + } + $date = new \DateTime('@'.$value->getSeconds(), new \DateTimeZone("UTC")); + return $date->format("Y-m-d\TH:i:s".$nanoseconds."\Z"); + } + + public static function getNanosecondsForTimestamp($nanoseconds) + { + if ($nanoseconds == 0) { + return ''; + } + if ($nanoseconds % static::NANOS_PER_MILLISECOND == 0) { + return sprintf('%03d', $nanoseconds / static::NANOS_PER_MILLISECOND); + } + if ($nanoseconds % static::NANOS_PER_MICROSECOND == 0) { + return sprintf('%06d', $nanoseconds / static::NANOS_PER_MICROSECOND); + } + return sprintf('%09d', $nanoseconds); + } } diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 8886e61a..b3c4e6f1 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -57,6 +57,7 @@ class Message * @ignore */ private $desc; + private $unknown = ""; /** * @ignore @@ -226,13 +227,14 @@ class Message /** * @ignore */ - private static function skipField($input, $tag) + private function skipField($input, $tag) { $number = GPBWire::getTagFieldNumber($tag); if ($number === 0) { throw new GPBDecodeException("Illegal field number zero."); } + $start = $input->current(); switch (GPBWire::getTagWireType($tag)) { case GPBWireType::VARINT: $uint64 = 0; @@ -240,21 +242,21 @@ class Message throw new GPBDecodeException( "Unexpected EOF inside varint."); } - return; + break; case GPBWireType::FIXED64: $uint64 = 0; if (!$input->readLittleEndian64($uint64)) { throw new GPBDecodeException( "Unexpected EOF inside fixed64."); } - return; + break; case GPBWireType::FIXED32: $uint32 = 0; if (!$input->readLittleEndian32($uint32)) { throw new GPBDecodeException( "Unexpected EOF inside fixed32."); } - return; + break; case GPBWireType::LENGTH_DELIMITED: $length = 0; if (!$input->readVarint32($length)) { @@ -266,13 +268,18 @@ class Message throw new GPBDecodeException( "Unexpected EOF inside length delimited data."); } - return; + break; case GPBWireType::START_GROUP: case GPBWireType::END_GROUP: throw new GPBDecodeException("Unexpected wire type."); default: throw new GPBDecodeException("Unexpected wire type."); } + $end = $input->current(); + + $bytes = str_repeat(chr(0), CodedOutputStream::MAX_VARINT64_BYTES); + $size = CodedOutputStream::writeVarintToArray($tag, $bytes, true); + $this->unknown .= substr($bytes, 0, $size) . $input->substr($start, $end); } /** @@ -423,7 +430,7 @@ class Message } if ($value_format === GPBWire::UNKNOWN) { - self::skipField($input, $tag); + $this->skipField($input, $tag); return; } elseif ($value_format === GPBWire::NORMAL_FORMAT) { self::parseFieldFromStreamNoTag($input, $field, $value); @@ -461,6 +468,7 @@ class Message */ public function clear() { + $this->unknown = ""; foreach ($this->desc->getField() as $field) { $setter = $field->getSetter(); if ($field->isMap()) { @@ -699,12 +707,25 @@ class Message switch ($field->getType()) { case GPBType::MESSAGE: $klass = $field->getMessageType()->getClass(); - if (!is_object($value) && !is_array($value)) { - throw new \Exception("Expect message."); - } $submsg = new $klass; - if (!is_null($value) && - $klass !== "Google\Protobuf\Any") { + + if ($field->isTimestamp()) { + if (!is_string($value)) { + throw new GPBDecodeException("Expect string."); + } + try { + $timestamp = GPBUtil::parseTimestamp($value); + } catch (\Exception $e) { + throw new GPBDecodeException("Invalid RFC 3339 timestamp: ".$e->getMessage()); + } + + $submsg->setSeconds($timestamp->getSeconds()); + $submsg->setNanos($timestamp->getNanos()); + } else if ($klass !== "Google\Protobuf\Any") { + if (!is_object($value) && !is_array($value)) { + throw new GPBDecodeException("Expect message."); + } + $submsg->mergeFromJsonArray($value); } return $submsg; @@ -1030,6 +1051,7 @@ class Message return false; } } + $output->writeRaw($this->unknown, strlen($this->unknown)); return true; } @@ -1038,22 +1060,28 @@ class Message */ public function serializeToJsonStream(&$output) { - $output->writeRaw("{", 1); - $fields = $this->desc->getField(); - $first = true; - foreach ($fields as $field) { - if ($this->existField($field)) { - if ($first) { - $first = false; - } else { - $output->writeRaw(",", 1); - } - if (!$this->serializeFieldToJsonStream($output, $field)) { - return false; + if (get_class($this) === 'Google\Protobuf\Timestamp') { + $timestamp = GPBUtil::formatTimestamp($this); + $timestamp = json_encode($timestamp); + $output->writeRaw($timestamp, strlen($timestamp)); + } else { + $output->writeRaw("{", 1); + $fields = $this->desc->getField(); + $first = true; + foreach ($fields as $field) { + if ($this->existField($field)) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if (!$this->serializeFieldToJsonStream($output, $field)) { + return false; + } } } + $output->writeRaw("}", 1); } - $output->writeRaw("}", 1); return true; } @@ -1341,6 +1369,7 @@ class Message private function fieldJsonByteSize($field) { $size = 0; + if ($field->isMap()) { $getter = $field->getGetter(); $values = $this->$getter(); @@ -1408,6 +1437,7 @@ class Message foreach ($fields as $field) { $size += $this->fieldByteSize($field); } + $size += strlen($this->unknown); return $size; } @@ -1443,21 +1473,26 @@ class Message public function jsonByteSize() { $size = 0; - - // Size for "{}". - $size += 2; - - $fields = $this->desc->getField(); - $count = 0; - foreach ($fields as $field) { - $field_size = $this->fieldJsonByteSize($field); - $size += $field_size; - if ($field_size != 0) { - $count++; + if (get_class($this) === 'Google\Protobuf\Timestamp') { + $timestamp = GPBUtil::formatTimestamp($this); + $timestamp = json_encode($timestamp); + $size += strlen($timestamp); + } else { + // Size for "{}". + $size += 2; + + $fields = $this->desc->getField(); + $count = 0; + foreach ($fields as $field) { + $field_size = $this->fieldJsonByteSize($field); + $size += $field_size; + if ($field_size != 0) { + $count++; + } } + // size for comma + $size += $count > 0 ? ($count - 1) : 0; } - // size for comma - $size += $count > 0 ? ($count - 1) : 0; return $size; } } diff --git a/php/src/Google/Protobuf/ListValue.php b/php/src/Google/Protobuf/ListValue.php new file mode 100644 index 00000000..12552ef4 --- /dev/null +++ b/php/src/Google/Protobuf/ListValue.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/struct.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * `ListValue` is a wrapper around a repeated field of values. + * The JSON representation for `ListValue` is JSON array. + * + * Generated from protobuf message <code>google.protobuf.ListValue</code> + */ +class ListValue extends \Google\Protobuf\Internal\Message +{ + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field <code>repeated .google.protobuf.Value values = 1;</code> + */ + private $values; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct(); + } + + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field <code>repeated .google.protobuf.Value values = 1;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getValues() + { + return $this->values; + } + + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field <code>repeated .google.protobuf.Value values = 1;</code> + * @param \Google\Protobuf\Value[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setValues($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Value::class); + $this->values = $arr; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Method.php b/php/src/Google/Protobuf/Method.php new file mode 100644 index 00000000..f55cb764 --- /dev/null +++ b/php/src/Google/Protobuf/Method.php @@ -0,0 +1,249 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/api.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Method represents a method of an API interface. + * + * Generated from protobuf message <code>google.protobuf.Method</code> + */ +class Method extends \Google\Protobuf\Internal\Message +{ + /** + * The simple name of this method. + * + * Generated from protobuf field <code>string name = 1;</code> + */ + private $name = ''; + /** + * A URL of the input message type. + * + * Generated from protobuf field <code>string request_type_url = 2;</code> + */ + private $request_type_url = ''; + /** + * If true, the request is streamed. + * + * Generated from protobuf field <code>bool request_streaming = 3;</code> + */ + private $request_streaming = false; + /** + * The URL of the output message type. + * + * Generated from protobuf field <code>string response_type_url = 4;</code> + */ + private $response_type_url = ''; + /** + * If true, the response is streamed. + * + * Generated from protobuf field <code>bool response_streaming = 5;</code> + */ + private $response_streaming = false; + /** + * Any metadata attached to the method. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 6;</code> + */ + private $options; + /** + * The source syntax of this method. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code> + */ + private $syntax = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Api::initOnce(); + parent::__construct(); + } + + /** + * The simple name of this method. + * + * Generated from protobuf field <code>string name = 1;</code> + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The simple name of this method. + * + * Generated from protobuf field <code>string name = 1;</code> + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * A URL of the input message type. + * + * Generated from protobuf field <code>string request_type_url = 2;</code> + * @return string + */ + public function getRequestTypeUrl() + { + return $this->request_type_url; + } + + /** + * A URL of the input message type. + * + * Generated from protobuf field <code>string request_type_url = 2;</code> + * @param string $var + * @return $this + */ + public function setRequestTypeUrl($var) + { + GPBUtil::checkString($var, True); + $this->request_type_url = $var; + + return $this; + } + + /** + * If true, the request is streamed. + * + * Generated from protobuf field <code>bool request_streaming = 3;</code> + * @return bool + */ + public function getRequestStreaming() + { + return $this->request_streaming; + } + + /** + * If true, the request is streamed. + * + * Generated from protobuf field <code>bool request_streaming = 3;</code> + * @param bool $var + * @return $this + */ + public function setRequestStreaming($var) + { + GPBUtil::checkBool($var); + $this->request_streaming = $var; + + return $this; + } + + /** + * The URL of the output message type. + * + * Generated from protobuf field <code>string response_type_url = 4;</code> + * @return string + */ + public function getResponseTypeUrl() + { + return $this->response_type_url; + } + + /** + * The URL of the output message type. + * + * Generated from protobuf field <code>string response_type_url = 4;</code> + * @param string $var + * @return $this + */ + public function setResponseTypeUrl($var) + { + GPBUtil::checkString($var, True); + $this->response_type_url = $var; + + return $this; + } + + /** + * If true, the response is streamed. + * + * Generated from protobuf field <code>bool response_streaming = 5;</code> + * @return bool + */ + public function getResponseStreaming() + { + return $this->response_streaming; + } + + /** + * If true, the response is streamed. + * + * Generated from protobuf field <code>bool response_streaming = 5;</code> + * @param bool $var + * @return $this + */ + public function setResponseStreaming($var) + { + GPBUtil::checkBool($var); + $this->response_streaming = $var; + + return $this; + } + + /** + * Any metadata attached to the method. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 6;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Any metadata attached to the method. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 6;</code> + * @param \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOptions($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class); + $this->options = $arr; + + return $this; + } + + /** + * The source syntax of this method. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code> + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax of this method. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code> + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Mixin.php b/php/src/Google/Protobuf/Mixin.php new file mode 100644 index 00000000..eb5117e0 --- /dev/null +++ b/php/src/Google/Protobuf/Mixin.php @@ -0,0 +1,153 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/api.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Declares an API Interface to be included in this interface. The including + * interface must redeclare all the methods from the included interface, but + * documentation and options are inherited as follows: + * - If after comment and whitespace stripping, the documentation + * string of the redeclared method is empty, it will be inherited + * from the original method. + * - Each annotation belonging to the service config (http, + * visibility) which is not set in the redeclared method will be + * inherited. + * - If an http annotation is inherited, the path pattern will be + * modified as follows. Any version prefix will be replaced by the + * version of the including interface plus the [root][] path if + * specified. + * Example of a simple mixin: + * package google.acl.v1; + * service AccessControl { + * // Get the underlying ACL object. + * rpc GetAcl(GetAclRequest) returns (Acl) { + * option (google.api.http).get = "/v1/{resource=**}:getAcl"; + * } + * } + * package google.storage.v2; + * service Storage { + * rpc GetAcl(GetAclRequest) returns (Acl); + * // Get a data record. + * rpc GetData(GetDataRequest) returns (Data) { + * option (google.api.http).get = "/v2/{resource=**}"; + * } + * } + * Example of a mixin configuration: + * apis: + * - name: google.storage.v2.Storage + * mixins: + * - name: google.acl.v1.AccessControl + * The mixin construct implies that all methods in `AccessControl` are + * also declared with same name and request/response types in + * `Storage`. A documentation generator or annotation processor will + * see the effective `Storage.GetAcl` method after inherting + * documentation and annotations as follows: + * service Storage { + * // Get the underlying ACL object. + * rpc GetAcl(GetAclRequest) returns (Acl) { + * option (google.api.http).get = "/v2/{resource=**}:getAcl"; + * } + * ... + * } + * Note how the version in the path pattern changed from `v1` to `v2`. + * If the `root` field in the mixin is specified, it should be a + * relative path under which inherited HTTP paths are placed. Example: + * apis: + * - name: google.storage.v2.Storage + * mixins: + * - name: google.acl.v1.AccessControl + * root: acls + * This implies the following inherited HTTP annotation: + * service Storage { + * // Get the underlying ACL object. + * rpc GetAcl(GetAclRequest) returns (Acl) { + * option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; + * } + * ... + * } + * + * Generated from protobuf message <code>google.protobuf.Mixin</code> + */ +class Mixin extends \Google\Protobuf\Internal\Message +{ + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field <code>string name = 1;</code> + */ + private $name = ''; + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field <code>string root = 2;</code> + */ + private $root = ''; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Api::initOnce(); + parent::__construct(); + } + + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field <code>string name = 1;</code> + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field <code>string name = 1;</code> + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field <code>string root = 2;</code> + * @return string + */ + public function getRoot() + { + return $this->root; + } + + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field <code>string root = 2;</code> + * @param string $var + * @return $this + */ + public function setRoot($var) + { + GPBUtil::checkString($var, True); + $this->root = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/NullValue.php b/php/src/Google/Protobuf/NullValue.php new file mode 100644 index 00000000..d4022ccc --- /dev/null +++ b/php/src/Google/Protobuf/NullValue.php @@ -0,0 +1,23 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/struct.proto + +namespace Google\Protobuf; + +/** + * `NullValue` is a singleton enumeration to represent the null value for the + * `Value` type union. + * The JSON representation for `NullValue` is JSON `null`. + * + * Protobuf enum <code>Google\Protobuf\NullValue</code> + */ +class NullValue +{ + /** + * Null value. + * + * Generated from protobuf enum <code>NULL_VALUE = 0;</code> + */ + const NULL_VALUE = 0; +} + diff --git a/php/src/Google/Protobuf/Option.php b/php/src/Google/Protobuf/Option.php new file mode 100644 index 00000000..f8038681 --- /dev/null +++ b/php/src/Google/Protobuf/Option.php @@ -0,0 +1,108 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/type.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * A protocol buffer option, which can be attached to a message, field, + * enumeration, etc. + * + * Generated from protobuf message <code>google.protobuf.Option</code> + */ +class Option extends \Google\Protobuf\Internal\Message +{ + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field <code>string name = 1;</code> + */ + private $name = ''; + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field <code>.google.protobuf.Any value = 2;</code> + */ + private $value = null; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Type::initOnce(); + parent::__construct(); + } + + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field <code>string name = 1;</code> + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field <code>string name = 1;</code> + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field <code>.google.protobuf.Any value = 2;</code> + * @return \Google\Protobuf\Any + */ + public function getValue() + { + return $this->value; + } + + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field <code>.google.protobuf.Any value = 2;</code> + * @param \Google\Protobuf\Any $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Any::class); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/SourceContext.php b/php/src/Google/Protobuf/SourceContext.php new file mode 100644 index 00000000..07d90c68 --- /dev/null +++ b/php/src/Google/Protobuf/SourceContext.php @@ -0,0 +1,61 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/source_context.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * `SourceContext` represents information about the source of a + * protobuf element, like the file in which it is defined. + * + * Generated from protobuf message <code>google.protobuf.SourceContext</code> + */ +class SourceContext extends \Google\Protobuf\Internal\Message +{ + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field <code>string file_name = 1;</code> + */ + private $file_name = ''; + + public function __construct() { + \GPBMetadata\Google\Protobuf\SourceContext::initOnce(); + parent::__construct(); + } + + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field <code>string file_name = 1;</code> + * @return string + */ + public function getFileName() + { + return $this->file_name; + } + + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field <code>string file_name = 1;</code> + * @param string $var + * @return $this + */ + public function setFileName($var) + { + GPBUtil::checkString($var, True); + $this->file_name = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/StringValue.php b/php/src/Google/Protobuf/StringValue.php new file mode 100644 index 00000000..f6bcc48a --- /dev/null +++ b/php/src/Google/Protobuf/StringValue.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `string`. + * The JSON representation for `StringValue` is JSON string. + * + * Generated from protobuf message <code>google.protobuf.StringValue</code> + */ +class StringValue extends \Google\Protobuf\Internal\Message +{ + /** + * The string value. + * + * Generated from protobuf field <code>string value = 1;</code> + */ + private $value = ''; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The string value. + * + * Generated from protobuf field <code>string value = 1;</code> + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * The string value. + * + * Generated from protobuf field <code>string value = 1;</code> + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, True); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Struct.php b/php/src/Google/Protobuf/Struct.php new file mode 100644 index 00000000..721e991c --- /dev/null +++ b/php/src/Google/Protobuf/Struct.php @@ -0,0 +1,63 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/struct.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * `Struct` represents a structured data value, consisting of fields + * which map to dynamically typed values. In some languages, `Struct` + * might be supported by a native representation. For example, in + * scripting languages like JS a struct is represented as an + * object. The details of that representation are described together + * with the proto support for the language. + * The JSON representation for `Struct` is JSON object. + * + * Generated from protobuf message <code>google.protobuf.Struct</code> + */ +class Struct extends \Google\Protobuf\Internal\Message +{ + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field <code>map<string, .google.protobuf.Value> fields = 1;</code> + */ + private $fields; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct(); + } + + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field <code>map<string, .google.protobuf.Value> fields = 1;</code> + * @return \Google\Protobuf\Internal\MapField + */ + public function getFields() + { + return $this->fields; + } + + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field <code>map<string, .google.protobuf.Value> fields = 1;</code> + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setFields($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Value::class); + $this->fields = $arr; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Syntax.php b/php/src/Google/Protobuf/Syntax.php new file mode 100644 index 00000000..bb7b7896 --- /dev/null +++ b/php/src/Google/Protobuf/Syntax.php @@ -0,0 +1,27 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/type.proto + +namespace Google\Protobuf; + +/** + * The syntax in which a protocol buffer element is defined. + * + * Protobuf enum <code>Google\Protobuf\Syntax</code> + */ +class Syntax +{ + /** + * Syntax `proto2`. + * + * Generated from protobuf enum <code>SYNTAX_PROTO2 = 0;</code> + */ + const SYNTAX_PROTO2 = 0; + /** + * Syntax `proto3`. + * + * Generated from protobuf enum <code>SYNTAX_PROTO3 = 1;</code> + */ + const SYNTAX_PROTO3 = 1; +} + diff --git a/php/src/Google/Protobuf/Timestamp.php b/php/src/Google/Protobuf/Timestamp.php new file mode 100644 index 00000000..d139da99 --- /dev/null +++ b/php/src/Google/Protobuf/Timestamp.php @@ -0,0 +1,184 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/timestamp.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * A Timestamp represents a point in time independent of any time zone + * or calendar, represented as seconds and fractions of seconds at + * nanosecond resolution in UTC Epoch time. It is encoded using the + * Proleptic Gregorian Calendar which extends the Gregorian calendar + * backwards to year one. It is encoded assuming all minutes are 60 + * seconds long, i.e. leap seconds are "smeared" so that no leap second + * table is needed for interpretation. Range is from + * 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. + * By restricting to that range, we ensure that we can convert to + * and from RFC 3339 date strings. + * See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). + * # Examples + * Example 1: Compute Timestamp from POSIX `time()`. + * Timestamp timestamp; + * timestamp.set_seconds(time(NULL)); + * timestamp.set_nanos(0); + * Example 2: Compute Timestamp from POSIX `gettimeofday()`. + * struct timeval tv; + * gettimeofday(&tv, NULL); + * Timestamp timestamp; + * timestamp.set_seconds(tv.tv_sec); + * timestamp.set_nanos(tv.tv_usec * 1000); + * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. + * FILETIME ft; + * GetSystemTimeAsFileTime(&ft); + * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z + * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. + * Timestamp timestamp; + * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); + * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); + * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. + * long millis = System.currentTimeMillis(); + * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) + * .setNanos((int) ((millis % 1000) * 1000000)).build(); + * Example 5: Compute Timestamp from current time in Python. + * timestamp = Timestamp() + * timestamp.GetCurrentTime() + * # JSON Mapping + * In JSON format, the Timestamp type is encoded as a string in the + * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the + * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" + * where {year} is always expressed using four digits while {month}, {day}, + * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional + * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), + * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone + * is required, though only UTC (as indicated by "Z") is presently supported. + * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past + * 01:30 UTC on January 15, 2017. + * In JavaScript, one can convert a Date object to this format using the + * standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString] + * method. In Python, a standard `datetime.datetime` object can be converted + * to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) + * with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one + * can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( + * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()) + * to obtain a formatter capable of generating timestamps in this format. + * + * Generated from protobuf message <code>google.protobuf.Timestamp</code> + */ +class Timestamp extends \Google\Protobuf\Internal\Message +{ + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field <code>int64 seconds = 1;</code> + */ + private $seconds = 0; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field <code>int32 nanos = 2;</code> + */ + private $nanos = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Timestamp::initOnce(); + parent::__construct(); + } + + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field <code>int64 seconds = 1;</code> + * @return int|string + */ + public function getSeconds() + { + return $this->seconds; + } + + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field <code>int64 seconds = 1;</code> + * @param int|string $var + * @return $this + */ + public function setSeconds($var) + { + GPBUtil::checkInt64($var); + $this->seconds = $var; + + return $this; + } + + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field <code>int32 nanos = 2;</code> + * @return int + */ + public function getNanos() + { + return $this->nanos; + } + + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field <code>int32 nanos = 2;</code> + * @param int $var + * @return $this + */ + public function setNanos($var) + { + GPBUtil::checkInt32($var); + $this->nanos = $var; + + return $this; + } + + /** + * Converts PHP DateTime to Timestamp. + * + * @param DateTime $datetime + */ + public function fromDateTime($datetime) + { + if (get_class($datetime) !== \DateTime::class) { + trigger_error("Given parameter is not a DateTime.", + E_USER_ERROR); + } + $this->seconds = $datetime->format('U'); + $this->nanos = 0; + } + + /** + * Converts Timestamp to PHP DateTime. Nano second is ignored. + * + * @return DateTime $datetime + */ + public function toDateTime() + { + return \DateTime::createFromFormat('U', $this->seconds); + } +} + diff --git a/php/src/Google/Protobuf/Type.php b/php/src/Google/Protobuf/Type.php new file mode 100644 index 00000000..7dbe2cab --- /dev/null +++ b/php/src/Google/Protobuf/Type.php @@ -0,0 +1,217 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/type.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * A protocol buffer message type. + * + * Generated from protobuf message <code>google.protobuf.Type</code> + */ +class Type extends \Google\Protobuf\Internal\Message +{ + /** + * The fully qualified message name. + * + * Generated from protobuf field <code>string name = 1;</code> + */ + private $name = ''; + /** + * The list of fields. + * + * Generated from protobuf field <code>repeated .google.protobuf.Field fields = 2;</code> + */ + private $fields; + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field <code>repeated string oneofs = 3;</code> + */ + private $oneofs; + /** + * The protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 4;</code> + */ + private $options; + /** + * The source context. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code> + */ + private $source_context = null; + /** + * The source syntax. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 6;</code> + */ + private $syntax = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Type::initOnce(); + parent::__construct(); + } + + /** + * The fully qualified message name. + * + * Generated from protobuf field <code>string name = 1;</code> + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The fully qualified message name. + * + * Generated from protobuf field <code>string name = 1;</code> + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The list of fields. + * + * Generated from protobuf field <code>repeated .google.protobuf.Field fields = 2;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFields() + { + return $this->fields; + } + + /** + * The list of fields. + * + * Generated from protobuf field <code>repeated .google.protobuf.Field fields = 2;</code> + * @param \Google\Protobuf\Field[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setFields($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Field::class); + $this->fields = $arr; + + return $this; + } + + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field <code>repeated string oneofs = 3;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOneofs() + { + return $this->oneofs; + } + + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field <code>repeated string oneofs = 3;</code> + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOneofs($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->oneofs = $arr; + + return $this; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 4;</code> + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field <code>repeated .google.protobuf.Option options = 4;</code> + * @param \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOptions($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class); + $this->options = $arr; + + return $this; + } + + /** + * The source context. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code> + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * The source context. + * + * Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code> + * @param \Google\Protobuf\SourceContext $var + * @return $this + */ + public function setSourceContext($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\SourceContext::class); + $this->source_context = $var; + + return $this; + } + + /** + * The source syntax. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 6;</code> + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax. + * + * Generated from protobuf field <code>.google.protobuf.Syntax syntax = 6;</code> + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/UInt32Value.php b/php/src/Google/Protobuf/UInt32Value.php new file mode 100644 index 00000000..61a3ddf1 --- /dev/null +++ b/php/src/Google/Protobuf/UInt32Value.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `uint32`. + * The JSON representation for `UInt32Value` is JSON number. + * + * Generated from protobuf message <code>google.protobuf.UInt32Value</code> + */ +class UInt32Value extends \Google\Protobuf\Internal\Message +{ + /** + * The uint32 value. + * + * Generated from protobuf field <code>uint32 value = 1;</code> + */ + private $value = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The uint32 value. + * + * Generated from protobuf field <code>uint32 value = 1;</code> + * @return int + */ + public function getValue() + { + return $this->value; + } + + /** + * The uint32 value. + * + * Generated from protobuf field <code>uint32 value = 1;</code> + * @param int $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkUint32($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/UInt64Value.php b/php/src/Google/Protobuf/UInt64Value.php new file mode 100644 index 00000000..69f7eb8e --- /dev/null +++ b/php/src/Google/Protobuf/UInt64Value.php @@ -0,0 +1,58 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/wrappers.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * Wrapper message for `uint64`. + * The JSON representation for `UInt64Value` is JSON string. + * + * Generated from protobuf message <code>google.protobuf.UInt64Value</code> + */ +class UInt64Value extends \Google\Protobuf\Internal\Message +{ + /** + * The uint64 value. + * + * Generated from protobuf field <code>uint64 value = 1;</code> + */ + private $value = 0; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct(); + } + + /** + * The uint64 value. + * + * Generated from protobuf field <code>uint64 value = 1;</code> + * @return int|string + */ + public function getValue() + { + return $this->value; + } + + /** + * The uint64 value. + * + * Generated from protobuf field <code>uint64 value = 1;</code> + * @param int|string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkUint64($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/php/src/Google/Protobuf/Value.php b/php/src/Google/Protobuf/Value.php new file mode 100644 index 00000000..052a3779 --- /dev/null +++ b/php/src/Google/Protobuf/Value.php @@ -0,0 +1,194 @@ +<?php +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/protobuf/struct.proto + +namespace Google\Protobuf; + +use Google\Protobuf\Internal\GPBType; +use Google\Protobuf\Internal\RepeatedField; +use Google\Protobuf\Internal\GPBUtil; + +/** + * `Value` represents a dynamically typed value which can be either + * null, a number, a string, a boolean, a recursive struct value, or a + * list of values. A producer of value is expected to set one of that + * variants, absence of any variant indicates an error. + * The JSON representation for `Value` is JSON value. + * + * Generated from protobuf message <code>google.protobuf.Value</code> + */ +class Value extends \Google\Protobuf\Internal\Message +{ + protected $kind; + + public function __construct() { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct(); + } + + /** + * Represents a null value. + * + * Generated from protobuf field <code>.google.protobuf.NullValue null_value = 1;</code> + * @return int + */ + public function getNullValue() + { + return $this->readOneof(1); + } + + /** + * Represents a null value. + * + * Generated from protobuf field <code>.google.protobuf.NullValue null_value = 1;</code> + * @param int $var + * @return $this + */ + public function setNullValue($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\NullValue::class); + $this->writeOneof(1, $var); + + return $this; + } + + /** + * Represents a double value. + * + * Generated from protobuf field <code>double number_value = 2;</code> + * @return float + */ + public function getNumberValue() + { + return $this->readOneof(2); + } + + /** + * Represents a double value. + * + * Generated from protobuf field <code>double number_value = 2;</code> + * @param float $var + * @return $this + */ + public function setNumberValue($var) + { + GPBUtil::checkDouble($var); + $this->writeOneof(2, $var); + + return $this; + } + + /** + * Represents a string value. + * + * Generated from protobuf field <code>string string_value = 3;</code> + * @return string + */ + public function getStringValue() + { + return $this->readOneof(3); + } + + /** + * Represents a string value. + * + * Generated from protobuf field <code>string string_value = 3;</code> + * @param string $var + * @return $this + */ + public function setStringValue($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(3, $var); + + return $this; + } + + /** + * Represents a boolean value. + * + * Generated from protobuf field <code>bool bool_value = 4;</code> + * @return bool + */ + public function getBoolValue() + { + return $this->readOneof(4); + } + + /** + * Represents a boolean value. + * + * Generated from protobuf field <code>bool bool_value = 4;</code> + * @param bool $var + * @return $this + */ + public function setBoolValue($var) + { + GPBUtil::checkBool($var); + $this->writeOneof(4, $var); + + return $this; + } + + /** + * Represents a structured value. + * + * Generated from protobuf field <code>.google.protobuf.Struct struct_value = 5;</code> + * @return \Google\Protobuf\Struct + */ + public function getStructValue() + { + return $this->readOneof(5); + } + + /** + * Represents a structured value. + * + * Generated from protobuf field <code>.google.protobuf.Struct struct_value = 5;</code> + * @param \Google\Protobuf\Struct $var + * @return $this + */ + public function setStructValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Struct::class); + $this->writeOneof(5, $var); + + return $this; + } + + /** + * Represents a repeated `Value`. + * + * Generated from protobuf field <code>.google.protobuf.ListValue list_value = 6;</code> + * @return \Google\Protobuf\ListValue + */ + public function getListValue() + { + return $this->readOneof(6); + } + + /** + * Represents a repeated `Value`. + * + * Generated from protobuf field <code>.google.protobuf.ListValue list_value = 6;</code> + * @param \Google\Protobuf\ListValue $var + * @return $this + */ + public function setListValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\ListValue::class); + $this->writeOneof(6, $var); + + return $this; + } + + /** + * @return string + */ + public function getKind() + { + return $this->whichOneof("kind"); + } + +} + |