diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 16:26:16 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 16:26:16 -0700 |
commit | 3af881c7e2db0553207876acbdb91c6e77974e44 (patch) | |
tree | 35e2a96cce802d4235bd29afa396e28ead892fa2 /php/src | |
parent | 86975301f1876ce1934612777b8ca6c76520f5cc (diff) | |
parent | 942a29cecd36f2a4b22fdd2179635cd548e6bd27 (diff) |
Merge master into 3.4.x
Diffstat (limited to 'php/src')
51 files changed, 3293 insertions, 1865 deletions
diff --git a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php index 0b7698e3..60722d00 100644 --- a/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php +++ b/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php @@ -144,12 +144,14 @@ class Descriptor ->optional('cc_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 16) ->optional('java_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 17) ->optional('py_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 18) + ->optional('php_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 19) ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 23) ->optional('cc_enable_arenas', \Google\Protobuf\Internal\GPBType::BOOL, 31) ->optional('objc_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 36) ->optional('csharp_namespace', \Google\Protobuf\Internal\GPBType::STRING, 37) ->optional('swift_prefix', \Google\Protobuf\Internal\GPBType::STRING, 39) ->optional('php_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 40) + ->optional('php_namespace', \Google\Protobuf\Internal\GPBType::STRING, 41) ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption') ->finalizeToPool(); diff --git a/php/src/Google/Protobuf/Internal/InputStream.php b/php/src/Google/Protobuf/Internal/CodedInputStream.php index 8012a225..6131d5d1 100644 --- a/php/src/Google/Protobuf/Internal/InputStream.php +++ b/php/src/Google/Protobuf/Internal/CodedInputStream.php @@ -34,28 +34,7 @@ namespace Google\Protobuf\Internal; use Google\Protobuf\Internal\Uint64; -function combineInt32ToInt64($high, $low) -{ - $isNeg = $high < 0; - if ($isNeg) { - $high = ~$high; - $low = ~$low; - $low++; - if (!$low) { - $high++; - } - } - $result = bcadd(bcmul($high, 4294967296), $low); - if ($low < 0) { - $result = bcadd($result, 4294967296); - } - if ($isNeg) { - $result = bcsub(0, $result); - } - return $result; -} - -class InputStream +class CodedInputStream { private $buffer; @@ -94,7 +73,7 @@ class InputStream $this->current += $amount; } - private function bufferSize() + public function bufferSize() { return $this->buffer_end - $this->current; } @@ -192,7 +171,10 @@ class InputStream $count += 1; } while ($b & 0x80); - $var = combineInt32ToInt64($high, $low); + $var = GPBUtil::combineInt32ToInt64($high, $low); + if (bccomp($var, 0) < 0) { + $var = bcadd($var, "18446744073709551616"); + } } else { $result = 0; $shift = 0; @@ -265,7 +247,7 @@ class InputStream } $high = unpack('V', $data)[1]; if (PHP_INT_SIZE == 4) { - $var = combineInt32ToInt64($high, $low); + $var = GPBUtil::combineInt32ToInt64($high, $low); } else { $var = ($high << 32) | $low; } diff --git a/php/src/Google/Protobuf/Internal/OutputStream.php b/php/src/Google/Protobuf/Internal/CodedOutputStream.php index 8c6d9b68..4525d8dd 100644 --- a/php/src/Google/Protobuf/Internal/OutputStream.php +++ b/php/src/Google/Protobuf/Internal/CodedOutputStream.php @@ -32,7 +32,7 @@ namespace Google\Protobuf\Internal; -class OutputStream +class CodedOutputStream { private $buffer; @@ -53,10 +53,10 @@ class OutputStream return $this->buffer; } - public function writeVarint32($value) + public function writeVarint32($value, $trim) { $bytes = str_repeat(chr(0), self::MAX_VARINT64_BYTES); - $size = self::writeVarintToArray($value, $bytes); + $size = self::writeVarintToArray($value, $bytes, $trim); return $this->writeRaw($bytes, $size); } @@ -83,7 +83,7 @@ class OutputStream public function writeTag($tag) { - return $this->writeVarint32($tag); + return $this->writeVarint32($tag, true); } public function writeRaw($data, $size) @@ -101,19 +101,19 @@ class OutputStream return true; } - private static function writeVarintToArray($value, &$buffer) + private static function writeVarintToArray($value, &$buffer, $trim = false) { $current = 0; $high = 0; $low = 0; if (PHP_INT_SIZE == 4) { - GPBUtil::divideInt64ToInt32($value, $high, $low); + GPBUtil::divideInt64ToInt32($value, $high, $low, $trim); } else { $low = $value; } - while ($low >= 0x80 || $low < 0) { + while (($low >= 0x80 || $low < 0) || $high != 0) { $buffer[$current] = chr($low | 0x80); $value = ($value >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7)); $carry = ($high & 0x7F) << ((PHP_INT_SIZE << 3) - 7); diff --git a/php/src/Google/Protobuf/Internal/Descriptor.php b/php/src/Google/Protobuf/Internal/Descriptor.php new file mode 100644 index 00000000..44225ad2 --- /dev/null +++ b/php/src/Google/Protobuf/Internal/Descriptor.php @@ -0,0 +1,189 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Google\Protobuf\Internal; + +class Descriptor +{ + + private $full_name; + private $field = []; + private $json_to_field = []; + private $name_to_field = []; + private $nested_type = []; + private $enum_type = []; + private $klass; + private $options; + private $oneof_decl = []; + + public function addOneofDecl($oneof) + { + $this->oneof_decl[] = $oneof; + } + + public function getOneofDecl() + { + return $this->oneof_decl; + } + + public function setFullName($full_name) + { + $this->full_name = $full_name; + } + + public function getFullName() + { + return $this->full_name; + } + + public function addField($field) + { + $this->field[$field->getNumber()] = $field; + $this->json_to_field[$field->getJsonName()] = $field; + $this->name_to_field[$field->getName()] = $field; + } + + public function getField() + { + return $this->field; + } + + public function addNestedType($desc) + { + $this->nested_type[] = $desc; + } + + public function getNestedType() + { + return $this->nested_type; + } + + public function addEnumType($desc) + { + $this->enum_type[] = $desc; + } + + public function getEnumType() + { + return $this->enum_type; + } + + public function getFieldByNumber($number) + { + if (!isset($this->field[$number])) { + return NULL; + } else { + return $this->field[$number]; + } + } + + public function getFieldByJsonName($json_name) + { + if (!isset($this->json_to_field[$json_name])) { + return NULL; + } else { + return $this->json_to_field[$json_name]; + } + } + + public function getFieldByName($name) + { + if (!isset($this->name_to_field[$name])) { + return NULL; + } else { + return $this->name_to_field[$name]; + } + } + + public function setClass($klass) + { + $this->klass = $klass; + } + + public function getClass() + { + return $this->klass; + } + + public function setOptions($options) + { + $this->options = $options; + } + + public function getOptions() + { + return $this->options; + } + + public static function buildFromProto($proto, $file_proto, $containing) + { + $desc = new Descriptor(); + + $message_name_without_package = ""; + $classname = ""; + $fullname = ""; + GPBUtil::getFullClassName( + $proto, + $containing, + $file_proto, + $message_name_without_package, + $classname, + $fullname); + $desc->setFullName($fullname); + $desc->setClass($classname); + $desc->setOptions($proto->getOptions()); + + foreach ($proto->getField() as $field_proto) { + $desc->addField(FieldDescriptor::buildFromProto($field_proto)); + } + + // Handle nested types. + foreach ($proto->getNestedType() as $nested_proto) { + $desc->addNestedType(Descriptor::buildFromProto( + $nested_proto, $file_proto, $message_name_without_package)); + } + + // Handle nested enum. + foreach ($proto->getEnumType() as $enum_proto) { + $desc->addEnumType(EnumDescriptor::buildFromProto( + $enum_proto, $file_proto, $message_name_without_package)); + } + + // Handle oneof fields. + foreach ($proto->getOneofDecl() as $oneof_proto) { + $desc->addOneofDecl( + OneofDescriptor::buildFromProto($oneof_proto, $desc)); + } + + return $desc; + } +} diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto.php b/php/src/Google/Protobuf/Internal/DescriptorProto.php index 948c5876..1d6959b7 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto.php @@ -8,70 +8,65 @@ 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; /** - * <pre> * Describes a message type. - * </pre> * - * Protobuf type <code>google.protobuf.DescriptorProto</code> + * Generated from protobuf message <code>google.protobuf.DescriptorProto</code> */ class DescriptorProto extends \Google\Protobuf\Internal\Message { /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> */ private $name = ''; private $has_name = false; /** - * <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code> */ private $field; private $has_field = false; /** - * <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code> */ private $extension; private $has_extension = false; /** - * <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code> */ private $nested_type; private $has_nested_type = false; /** - * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code> */ private $enum_type; private $has_enum_type = false; /** - * <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code> */ private $extension_range; private $has_extension_range = false; /** - * <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code> + * Generated from protobuf field <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code> */ private $oneof_decl; private $has_oneof_decl = false; /** - * <code>optional .google.protobuf.MessageOptions options = 7;</code> + * Generated from protobuf field <code>optional .google.protobuf.MessageOptions options = 7;</code> */ private $options = null; private $has_options = false; /** - * <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code> */ private $reserved_range; private $has_reserved_range = false; /** - * <pre> * Reserved field names, which may not be used by fields in the same message. * A given name may only be reserved once. - * </pre> * - * <code>repeated string reserved_name = 10;</code> + * Generated from protobuf field <code>repeated string reserved_name = 10;</code> */ private $reserved_name; private $has_reserved_name = false; @@ -82,7 +77,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @return string */ public function getName() { @@ -90,13 +86,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @param string $var + * @return $this */ public function setName($var) { GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -105,7 +105,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getField() { @@ -113,13 +114,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code> + * @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setField(&$var) + public function setField($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->field = $arr; $this->has_field = true; + + return $this; } public function hasField() @@ -128,7 +133,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getExtension() { @@ -136,13 +142,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code> + * @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setExtension(&$var) + public function setExtension($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->extension = $arr; $this->has_extension = true; + + return $this; } public function hasExtension() @@ -151,7 +161,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getNestedType() { @@ -159,13 +170,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code> + * @param \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setNestedType(&$var) + public function setNestedType($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class); $this->nested_type = $arr; $this->has_nested_type = true; + + return $this; } public function hasNestedType() @@ -174,7 +189,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getEnumType() { @@ -182,13 +198,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code> + * @param \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setEnumType(&$var) + public function setEnumType($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class); $this->enum_type = $arr; $this->has_enum_type = true; + + return $this; } public function hasEnumType() @@ -197,7 +217,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getExtensionRange() { @@ -205,13 +226,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code> + * @param \Google\Protobuf\Internal\DescriptorProto_ExtensionRange[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setExtensionRange(&$var) + public function setExtensionRange($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class); $this->extension_range = $arr; $this->has_extension_range = true; + + return $this; } public function hasExtensionRange() @@ -220,7 +245,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code> + * Generated from protobuf field <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getOneofDecl() { @@ -228,13 +254,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code> + * Generated from protobuf field <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code> + * @param \Google\Protobuf\Internal\OneofDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setOneofDecl(&$var) + public function setOneofDecl($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\OneofDescriptorProto::class); $this->oneof_decl = $arr; $this->has_oneof_decl = true; + + return $this; } public function hasOneofDecl() @@ -243,7 +273,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.MessageOptions options = 7;</code> + * Generated from protobuf field <code>optional .google.protobuf.MessageOptions options = 7;</code> + * @return \Google\Protobuf\Internal\MessageOptions */ public function getOptions() { @@ -251,13 +282,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.MessageOptions options = 7;</code> + * Generated from protobuf field <code>optional .google.protobuf.MessageOptions options = 7;</code> + * @param \Google\Protobuf\Internal\MessageOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() @@ -266,7 +301,8 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getReservedRange() { @@ -274,13 +310,17 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code> + * @param \Google\Protobuf\Internal\DescriptorProto_ReservedRange[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setReservedRange(&$var) + public function setReservedRange($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class); $this->reserved_range = $arr; $this->has_reserved_range = true; + + return $this; } public function hasReservedRange() @@ -289,12 +329,11 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Reserved field names, which may not be used by fields in the same message. * A given name may only be reserved once. - * </pre> * - * <code>repeated string reserved_name = 10;</code> + * Generated from protobuf field <code>repeated string reserved_name = 10;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getReservedName() { @@ -302,18 +341,20 @@ class DescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Reserved field names, which may not be used by fields in the same message. * A given name may only be reserved once. - * </pre> * - * <code>repeated string reserved_name = 10;</code> + * Generated from protobuf field <code>repeated string reserved_name = 10;</code> + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setReservedName(&$var) + 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() diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php index b68ded5d..1d455995 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php @@ -8,26 +8,25 @@ 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; /** - * Protobuf type <code>google.protobuf.DescriptorProto.ExtensionRange</code> + * Generated from protobuf message <code>google.protobuf.DescriptorProto.ExtensionRange</code> */ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message { /** - * <code>optional int32 start = 1;</code> + * Generated from protobuf field <code>optional int32 start = 1;</code> */ private $start = 0; private $has_start = false; /** - * <code>optional int32 end = 2;</code> + * Generated from protobuf field <code>optional int32 end = 2;</code> */ private $end = 0; private $has_end = false; /** - * <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code> */ private $options = null; private $has_options = false; @@ -38,7 +37,8 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message } /** - * <code>optional int32 start = 1;</code> + * Generated from protobuf field <code>optional int32 start = 1;</code> + * @return int */ public function getStart() { @@ -46,13 +46,17 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message } /** - * <code>optional int32 start = 1;</code> + * 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() @@ -61,7 +65,8 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message } /** - * <code>optional int32 end = 2;</code> + * Generated from protobuf field <code>optional int32 end = 2;</code> + * @return int */ public function getEnd() { @@ -69,13 +74,17 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message } /** - * <code>optional int32 end = 2;</code> + * 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() @@ -84,7 +93,8 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code> + * @return \Google\Protobuf\Internal\ExtensionRangeOptions */ public function getOptions() { @@ -92,13 +102,17 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code> + * @param \Google\Protobuf\Internal\ExtensionRangeOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ExtensionRangeOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php b/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php index be36b8aa..b1022d61 100644 --- a/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php +++ b/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php @@ -8,35 +8,28 @@ 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; /** - * <pre> * Range of reserved tag numbers. Reserved tag numbers may not be used by * fields or extension ranges in the same message. Reserved ranges may * not overlap. - * </pre> * - * Protobuf type <code>google.protobuf.DescriptorProto.ReservedRange</code> + * Generated from protobuf message <code>google.protobuf.DescriptorProto.ReservedRange</code> */ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message { /** - * <pre> * Inclusive. - * </pre> * - * <code>optional int32 start = 1;</code> + * Generated from protobuf field <code>optional int32 start = 1;</code> */ private $start = 0; private $has_start = false; /** - * <pre> * Exclusive. - * </pre> * - * <code>optional int32 end = 2;</code> + * Generated from protobuf field <code>optional int32 end = 2;</code> */ private $end = 0; private $has_end = false; @@ -47,11 +40,10 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message } /** - * <pre> * Inclusive. - * </pre> * - * <code>optional int32 start = 1;</code> + * Generated from protobuf field <code>optional int32 start = 1;</code> + * @return int */ public function getStart() { @@ -59,17 +51,19 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message } /** - * <pre> * Inclusive. - * </pre> * - * <code>optional int32 start = 1;</code> + * 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() @@ -78,11 +72,10 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message } /** - * <pre> * Exclusive. - * </pre> * - * <code>optional int32 end = 2;</code> + * Generated from protobuf field <code>optional int32 end = 2;</code> + * @return int */ public function getEnd() { @@ -90,17 +83,19 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message } /** - * <pre> * Exclusive. - * </pre> * - * <code>optional int32 end = 2;</code> + * 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() diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptor.php b/php/src/Google/Protobuf/Internal/EnumDescriptor.php new file mode 100644 index 00000000..33a55a4a --- /dev/null +++ b/php/src/Google/Protobuf/Internal/EnumDescriptor.php @@ -0,0 +1,72 @@ +<?php + +namespace Google\Protobuf\Internal; + +class EnumDescriptor +{ + + private $klass; + private $full_name; + private $value; + private $name_to_value; + + public function setFullName($full_name) + { + $this->full_name = $full_name; + } + + public function getFullName() + { + return $this->full_name; + } + + public function addValue($number, $value) + { + $this->value[$number] = $value; + $this->name_to_value[$value->getName()] = $value; + } + + public function getValueByNumber($number) + { + return $this->value[$number]; + } + + public function getValueByName($name) + { + return $this->name_to_value[$name]; + } + + public function setClass($klass) + { + $this->klass = $klass; + } + + public function getClass() + { + return $this->klass; + } + + public static function buildFromProto($proto, $file_proto, $containing) + { + $desc = new EnumDescriptor(); + + $enum_name_without_package = ""; + $classname = ""; + $fullname = ""; + GPBUtil::getFullClassName( + $proto, + $containing, + $file_proto, + $enum_name_without_package, + $classname, + $fullname); + $desc->setFullName($fullname); + $desc->setClass($classname); + $values = $proto->getValue(); + foreach ($values as $value) { + $desc->addValue($value->getNumber(), $value); + } + + return $desc; + } +} diff --git a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php index 73f6edbd..816fbae5 100644 --- a/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php @@ -8,30 +8,27 @@ 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; /** - * <pre> * Describes an enum type. - * </pre> * - * Protobuf type <code>google.protobuf.EnumDescriptorProto</code> + * Generated from protobuf message <code>google.protobuf.EnumDescriptorProto</code> */ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message { /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> */ private $name = ''; private $has_name = false; /** - * <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code> */ private $value; private $has_value = false; /** - * <code>optional .google.protobuf.EnumOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code> */ private $options = null; private $has_options = false; @@ -42,7 +39,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @return string */ public function getName() { @@ -50,13 +48,17 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @param string $var + * @return $this */ public function setName($var) { GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -65,7 +67,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getValue() { @@ -73,13 +76,17 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code> + * @param \Google\Protobuf\Internal\EnumValueDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setValue(&$var) + public function setValue($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class); $this->value = $arr; $this->has_value = true; + + return $this; } public function hasValue() @@ -88,7 +95,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.EnumOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code> + * @return \Google\Protobuf\Internal\EnumOptions */ public function getOptions() { @@ -96,13 +104,17 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.EnumOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code> + * @param \Google\Protobuf\Internal\EnumOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/EnumOptions.php b/php/src/Google/Protobuf/Internal/EnumOptions.php index 4fa0bce7..3f598a41 100644 --- a/php/src/Google/Protobuf/Internal/EnumOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumOptions.php @@ -8,42 +8,35 @@ 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; /** - * Protobuf type <code>google.protobuf.EnumOptions</code> + * Generated from protobuf message <code>google.protobuf.EnumOptions</code> */ class EnumOptions extends \Google\Protobuf\Internal\Message { /** - * <pre> * Set this option to true to allow mapping different tag names to the same * value. - * </pre> * - * <code>optional bool allow_alias = 2;</code> + * Generated from protobuf field <code>optional bool allow_alias = 2;</code> */ private $allow_alias = false; private $has_allow_alias = false; /** - * <pre> * Is this enum deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the enum, or it will be completely ignored; in the very least, this * is a formalization for deprecating enums. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> */ private $deprecated = false; private $has_deprecated = false; /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ private $uninterpreted_option; private $has_uninterpreted_option = false; @@ -54,12 +47,11 @@ class EnumOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Set this option to true to allow mapping different tag names to the same * value. - * </pre> * - * <code>optional bool allow_alias = 2;</code> + * Generated from protobuf field <code>optional bool allow_alias = 2;</code> + * @return bool */ public function getAllowAlias() { @@ -67,18 +59,20 @@ class EnumOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Set this option to true to allow mapping different tag names to the same * value. - * </pre> * - * <code>optional bool allow_alias = 2;</code> + * Generated from protobuf field <code>optional bool allow_alias = 2;</code> + * @param bool $var + * @return $this */ public function setAllowAlias($var) { GPBUtil::checkBool($var); $this->allow_alias = $var; $this->has_allow_alias = true; + + return $this; } public function hasAllowAlias() @@ -87,14 +81,13 @@ class EnumOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this enum deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the enum, or it will be completely ignored; in the very least, this * is a formalization for deprecating enums. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> + * @return bool */ public function getDeprecated() { @@ -102,20 +95,22 @@ class EnumOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this enum deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the enum, or it will be completely ignored; in the very least, this * is a formalization for deprecating enums. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> + * @param bool $var + * @return $this */ public function setDeprecated($var) { GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -124,11 +119,10 @@ class EnumOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getUninterpretedOption() { @@ -136,17 +130,19 @@ class EnumOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/EnumValueDescriptor.php b/php/src/Google/Protobuf/Internal/EnumValueDescriptor.php new file mode 100644 index 00000000..549766e3 --- /dev/null +++ b/php/src/Google/Protobuf/Internal/EnumValueDescriptor.php @@ -0,0 +1,59 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Google\Protobuf\Internal; + +class EnumValueDescriptor +{ + private $name; + private $number; + + public function setName($name) + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function setNumber($number) + { + $this->number = $number; + } + + public function getNumber() + { + return $this->number; + } +} diff --git a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php index 94dc36ec..e363220f 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php @@ -8,30 +8,27 @@ 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; /** - * <pre> * Describes a value within an enum. - * </pre> * - * Protobuf type <code>google.protobuf.EnumValueDescriptorProto</code> + * Generated from protobuf message <code>google.protobuf.EnumValueDescriptorProto</code> */ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message { /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> */ private $name = ''; private $has_name = false; /** - * <code>optional int32 number = 2;</code> + * Generated from protobuf field <code>optional int32 number = 2;</code> */ private $number = 0; private $has_number = false; /** - * <code>optional .google.protobuf.EnumValueOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code> */ private $options = null; private $has_options = false; @@ -42,7 +39,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @return string */ public function getName() { @@ -50,13 +48,17 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @param string $var + * @return $this */ public function setName($var) { GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -65,7 +67,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional int32 number = 2;</code> + * Generated from protobuf field <code>optional int32 number = 2;</code> + * @return int */ public function getNumber() { @@ -73,13 +76,17 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional int32 number = 2;</code> + * Generated from protobuf field <code>optional int32 number = 2;</code> + * @param int $var + * @return $this */ public function setNumber($var) { GPBUtil::checkInt32($var); $this->number = $var; $this->has_number = true; + + return $this; } public function hasNumber() @@ -88,7 +95,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.EnumValueOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code> + * @return \Google\Protobuf\Internal\EnumValueOptions */ public function getOptions() { @@ -96,13 +104,17 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.EnumValueOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code> + * @param \Google\Protobuf\Internal\EnumValueOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/EnumValueOptions.php b/php/src/Google/Protobuf/Internal/EnumValueOptions.php index 232a6738..db8de174 100644 --- a/php/src/Google/Protobuf/Internal/EnumValueOptions.php +++ b/php/src/Google/Protobuf/Internal/EnumValueOptions.php @@ -8,32 +8,27 @@ 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; /** - * Protobuf type <code>google.protobuf.EnumValueOptions</code> + * Generated from protobuf message <code>google.protobuf.EnumValueOptions</code> */ class EnumValueOptions extends \Google\Protobuf\Internal\Message { /** - * <pre> * Is this enum value deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the enum value, or it will be completely ignored; in the very least, * this is a formalization for deprecating enum values. - * </pre> * - * <code>optional bool deprecated = 1 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code> */ private $deprecated = false; private $has_deprecated = false; /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ private $uninterpreted_option; private $has_uninterpreted_option = false; @@ -44,14 +39,13 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this enum value deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the enum value, or it will be completely ignored; in the very least, * this is a formalization for deprecating enum values. - * </pre> * - * <code>optional bool deprecated = 1 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code> + * @return bool */ public function getDeprecated() { @@ -59,20 +53,22 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this enum value deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the enum value, or it will be completely ignored; in the very least, * this is a formalization for deprecating enum values. - * </pre> * - * <code>optional bool deprecated = 1 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code> + * @param bool $var + * @return $this */ public function setDeprecated($var) { GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -81,11 +77,10 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getUninterpretedOption() { @@ -93,17 +88,19 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptor.php b/php/src/Google/Protobuf/Internal/FieldDescriptor.php new file mode 100644 index 00000000..f18bf810 --- /dev/null +++ b/php/src/Google/Protobuf/Internal/FieldDescriptor.php @@ -0,0 +1,253 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Google\Protobuf\Internal; + +class FieldDescriptor +{ + + private $name; + private $json_name; + private $setter; + private $getter; + private $number; + private $label; + private $type; + private $message_type; + private $enum_type; + private $packed; + private $is_map; + private $oneof_index = -1; + + public function setOneofIndex($index) + { + $this->oneof_index = $index; + } + + public function getOneofIndex() + { + return $this->oneof_index; + } + + public function setName($name) + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function setJsonName($json_name) + { + $this->json_name = $json_name; + } + + public function getJsonName() + { + return $this->json_name; + } + + public function setSetter($setter) + { + $this->setter = $setter; + } + + public function getSetter() + { + return $this->setter; + } + + public function setGetter($getter) + { + $this->getter = $getter; + } + + public function getGetter() + { + return $this->getter; + } + + public function setNumber($number) + { + $this->number = $number; + } + + public function getNumber() + { + return $this->number; + } + + public function setLabel($label) + { + $this->label = $label; + } + + public function getLabel() + { + return $this->label; + } + + public function isRepeated() + { + return $this->label === GPBLabel::REPEATED; + } + + public function setType($type) + { + $this->type = $type; + } + + public function getType() + { + return $this->type; + } + + public function setMessageType($message_type) + { + $this->message_type = $message_type; + } + + public function getMessageType() + { + return $this->message_type; + } + + public function setEnumType($enum_type) + { + $this->enum_type = $enum_type; + } + + public function getEnumType() + { + return $this->enum_type; + } + + public function setPacked($packed) + { + $this->packed = $packed; + } + + public function getPacked() + { + return $this->packed; + } + + public function isPackable() + { + return $this->isRepeated() && self::isTypePackable($this->type); + } + + public function isMap() + { + return $this->getType() == GPBType::MESSAGE && + !is_null($this->getMessageType()->getOptions()) && + $this->getMessageType()->getOptions()->getMapEntry(); + } + + private static function isTypePackable($field_type) + { + return ($field_type !== GPBType::STRING && + $field_type !== GPBType::GROUP && + $field_type !== GPBType::MESSAGE && + $field_type !== GPBType::BYTES); + } + + public static function getFieldDescriptor($proto) + { + $type_name = null; + $type = $proto->getType(); + switch ($type) { + case GPBType::MESSAGE: + case GPBType::GROUP: + case GPBType::ENUM: + $type_name = $proto->getTypeName(); + break; + default: + break; + } + + $oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1; + $packed = false; + $options = $proto->getOptions(); + if ($options !== null) { + $packed = $options->getPacked(); + } + + $field = new FieldDescriptor(); + $field->setName($proto->getName()); + + $json_name = $proto->hasJsonName() ? $proto->getJsonName() : + lcfirst(implode('', array_map('ucwords', explode('_', $proto->getName())))); + if ($proto->hasJsonName()) { + $json_name = $proto->getJsonName(); + } else { + $proto_name = $proto->getName(); + $json_name = implode('', array_map('ucwords', explode('_', $proto_name))); + if ($proto_name[0] !== "_" && !ctype_upper($proto_name[0])) { + $json_name = lcfirst($json_name); + } + } + $field->setJsonName($json_name); + + $camel_name = implode('', array_map('ucwords', explode('_', $proto->getName()))); + $field->setGetter('get' . $camel_name); + $field->setSetter('set' . $camel_name); + $field->setType($proto->getType()); + $field->setNumber($proto->getNumber()); + $field->setLabel($proto->getLabel()); + $field->setPacked($packed); + $field->setOneofIndex($oneof_index); + + // At this time, the message/enum type may have not been added to pool. + // So we use the type name as place holder and will replace it with the + // actual descriptor in cross building. + switch ($type) { + case GPBType::MESSAGE: + $field->setMessageType($type_name); + break; + case GPBType::ENUM: + $field->setEnumType($type_name); + break; + default: + break; + } + + return $field; + } + + public static function buildFromProto($proto) + { + return FieldDescriptor::getFieldDescriptor($proto); + } +} diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php index 6ae2cd41..10c27593 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php @@ -8,103 +8,88 @@ 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; /** - * <pre> * Describes a field within a message. - * </pre> * - * Protobuf type <code>google.protobuf.FieldDescriptorProto</code> + * Generated from protobuf message <code>google.protobuf.FieldDescriptorProto</code> */ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message { /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> */ private $name = ''; private $has_name = false; /** - * <code>optional int32 number = 3;</code> + * Generated from protobuf field <code>optional int32 number = 3;</code> */ private $number = 0; private $has_number = false; /** - * <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code> */ private $label = 0; private $has_label = false; /** - * <pre> * If type_name is set, this need not be set. If both this and type_name * are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. - * </pre> * - * <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code> */ private $type = 0; private $has_type = false; /** - * <pre> * For message and enum types, this is the name of the type. If the name * starts with a '.', it is fully-qualified. Otherwise, C++-like scoping * rules are used to find the type (i.e. first the nested types within this * message are searched, then within the parent, on up to the root * namespace). - * </pre> * - * <code>optional string type_name = 6;</code> + * Generated from protobuf field <code>optional string type_name = 6;</code> */ private $type_name = ''; private $has_type_name = false; /** - * <pre> * For extensions, this is the name of the type being extended. It is * resolved in the same manner as type_name. - * </pre> * - * <code>optional string extendee = 2;</code> + * Generated from protobuf field <code>optional string extendee = 2;</code> */ private $extendee = ''; private $has_extendee = false; /** - * <pre> * For numeric types, contains the original text representation of the value. * For booleans, "true" or "false". * For strings, contains the default text contents (not escaped in any way). - * For bytes, contains the C escaped value. All bytes >= 128 are escaped. + * For bytes, contains the C escaped value. All bytes >= 128 are escaped. * TODO(kenton): Base-64 encode? - * </pre> * - * <code>optional string default_value = 7;</code> + * Generated from protobuf field <code>optional string default_value = 7;</code> */ private $default_value = ''; private $has_default_value = false; /** - * <pre> * If set, gives the index of a oneof in the containing type's oneof_decl * list. This field is a member of that oneof. - * </pre> * - * <code>optional int32 oneof_index = 9;</code> + * Generated from protobuf field <code>optional int32 oneof_index = 9;</code> */ private $oneof_index = 0; private $has_oneof_index = false; /** - * <pre> * JSON name of this field. The value is set by protocol compiler. If the * user has set a "json_name" option on this field, that option's value * will be used. Otherwise, it's deduced from the field's name by converting * it to camelCase. - * </pre> * - * <code>optional string json_name = 10;</code> + * Generated from protobuf field <code>optional string json_name = 10;</code> */ private $json_name = ''; private $has_json_name = false; /** - * <code>optional .google.protobuf.FieldOptions options = 8;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code> */ private $options = null; private $has_options = false; @@ -115,7 +100,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @return string */ public function getName() { @@ -123,13 +109,17 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @param string $var + * @return $this */ public function setName($var) { GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -138,7 +128,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional int32 number = 3;</code> + * Generated from protobuf field <code>optional int32 number = 3;</code> + * @return int */ public function getNumber() { @@ -146,13 +137,17 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional int32 number = 3;</code> + * Generated from protobuf field <code>optional int32 number = 3;</code> + * @param int $var + * @return $this */ public function setNumber($var) { GPBUtil::checkInt32($var); $this->number = $var; $this->has_number = true; + + return $this; } public function hasNumber() @@ -161,7 +156,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code> + * @return int */ public function getLabel() { @@ -169,13 +165,17 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code> + * @param int $var + * @return $this */ public function setLabel($var) { GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Label::class); $this->label = $var; $this->has_label = true; + + return $this; } public function hasLabel() @@ -184,12 +184,11 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * If type_name is set, this need not be set. If both this and type_name * are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. - * </pre> * - * <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code> + * @return int */ public function getType() { @@ -197,18 +196,20 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * If type_name is set, this need not be set. If both this and type_name * are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. - * </pre> * - * <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code> + * @param int $var + * @return $this */ public function setType($var) { GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Type::class); $this->type = $var; $this->has_type = true; + + return $this; } public function hasType() @@ -217,15 +218,14 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * For message and enum types, this is the name of the type. If the name * starts with a '.', it is fully-qualified. Otherwise, C++-like scoping * rules are used to find the type (i.e. first the nested types within this * message are searched, then within the parent, on up to the root * namespace). - * </pre> * - * <code>optional string type_name = 6;</code> + * Generated from protobuf field <code>optional string type_name = 6;</code> + * @return string */ public function getTypeName() { @@ -233,21 +233,23 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * For message and enum types, this is the name of the type. If the name * starts with a '.', it is fully-qualified. Otherwise, C++-like scoping * rules are used to find the type (i.e. first the nested types within this * message are searched, then within the parent, on up to the root * namespace). - * </pre> * - * <code>optional string type_name = 6;</code> + * Generated from protobuf field <code>optional string type_name = 6;</code> + * @param string $var + * @return $this */ public function setTypeName($var) { GPBUtil::checkString($var, True); $this->type_name = $var; $this->has_type_name = true; + + return $this; } public function hasTypeName() @@ -256,12 +258,11 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * For extensions, this is the name of the type being extended. It is * resolved in the same manner as type_name. - * </pre> * - * <code>optional string extendee = 2;</code> + * Generated from protobuf field <code>optional string extendee = 2;</code> + * @return string */ public function getExtendee() { @@ -269,18 +270,20 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * For extensions, this is the name of the type being extended. It is * resolved in the same manner as type_name. - * </pre> * - * <code>optional string extendee = 2;</code> + * Generated from protobuf field <code>optional string extendee = 2;</code> + * @param string $var + * @return $this */ public function setExtendee($var) { GPBUtil::checkString($var, True); $this->extendee = $var; $this->has_extendee = true; + + return $this; } public function hasExtendee() @@ -289,15 +292,14 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * For numeric types, contains the original text representation of the value. * For booleans, "true" or "false". * For strings, contains the default text contents (not escaped in any way). - * For bytes, contains the C escaped value. All bytes >= 128 are escaped. + * For bytes, contains the C escaped value. All bytes >= 128 are escaped. * TODO(kenton): Base-64 encode? - * </pre> * - * <code>optional string default_value = 7;</code> + * Generated from protobuf field <code>optional string default_value = 7;</code> + * @return string */ public function getDefaultValue() { @@ -305,21 +307,23 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * For numeric types, contains the original text representation of the value. * For booleans, "true" or "false". * For strings, contains the default text contents (not escaped in any way). - * For bytes, contains the C escaped value. All bytes >= 128 are escaped. + * For bytes, contains the C escaped value. All bytes >= 128 are escaped. * TODO(kenton): Base-64 encode? - * </pre> * - * <code>optional string default_value = 7;</code> + * Generated from protobuf field <code>optional string default_value = 7;</code> + * @param string $var + * @return $this */ public function setDefaultValue($var) { GPBUtil::checkString($var, True); $this->default_value = $var; $this->has_default_value = true; + + return $this; } public function hasDefaultValue() @@ -328,12 +332,11 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * If set, gives the index of a oneof in the containing type's oneof_decl * list. This field is a member of that oneof. - * </pre> * - * <code>optional int32 oneof_index = 9;</code> + * Generated from protobuf field <code>optional int32 oneof_index = 9;</code> + * @return int */ public function getOneofIndex() { @@ -341,18 +344,20 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * If set, gives the index of a oneof in the containing type's oneof_decl * list. This field is a member of that oneof. - * </pre> * - * <code>optional int32 oneof_index = 9;</code> + * Generated from protobuf field <code>optional int32 oneof_index = 9;</code> + * @param int $var + * @return $this */ public function setOneofIndex($var) { GPBUtil::checkInt32($var); $this->oneof_index = $var; $this->has_oneof_index = true; + + return $this; } public function hasOneofIndex() @@ -361,14 +366,13 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * JSON name of this field. The value is set by protocol compiler. If the * user has set a "json_name" option on this field, that option's value * will be used. Otherwise, it's deduced from the field's name by converting * it to camelCase. - * </pre> * - * <code>optional string json_name = 10;</code> + * Generated from protobuf field <code>optional string json_name = 10;</code> + * @return string */ public function getJsonName() { @@ -376,20 +380,22 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * JSON name of this field. The value is set by protocol compiler. If the * user has set a "json_name" option on this field, that option's value * will be used. Otherwise, it's deduced from the field's name by converting * it to camelCase. - * </pre> * - * <code>optional string json_name = 10;</code> + * Generated from protobuf field <code>optional string json_name = 10;</code> + * @param string $var + * @return $this */ public function setJsonName($var) { GPBUtil::checkString($var, True); $this->json_name = $var; $this->has_json_name = true; + + return $this; } public function hasJsonName() @@ -398,7 +404,8 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.FieldOptions options = 8;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code> + * @return \Google\Protobuf\Internal\FieldOptions */ public function getOptions() { @@ -406,13 +413,17 @@ class FieldDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.FieldOptions options = 8;</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code> + * @param \Google\Protobuf\Internal\FieldOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php index a3cd8ef9..f2a32fdf 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php @@ -5,24 +5,22 @@ namespace Google\Protobuf\Internal; /** - * Protobuf enum <code>google.protobuf.FieldDescriptorProto.Label</code> + * Protobuf enum <code>Google\Protobuf\Internal</code> */ class FieldDescriptorProto_Label { /** - * <pre> * 0 is reserved for errors - * </pre> * - * <code>LABEL_OPTIONAL = 1;</code> + * Generated from protobuf enum <code>LABEL_OPTIONAL = 1;</code> */ const LABEL_OPTIONAL = 1; /** - * <code>LABEL_REQUIRED = 2;</code> + * Generated from protobuf enum <code>LABEL_REQUIRED = 2;</code> */ const LABEL_REQUIRED = 2; /** - * <code>LABEL_REPEATED = 3;</code> + * Generated from protobuf enum <code>LABEL_REPEATED = 3;</code> */ const LABEL_REPEATED = 3; } diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php index 8335f9b1..1b022deb 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php @@ -5,118 +5,102 @@ namespace Google\Protobuf\Internal; /** - * Protobuf enum <code>google.protobuf.FieldDescriptorProto.Type</code> + * Protobuf enum <code>Google\Protobuf\Internal</code> */ class FieldDescriptorProto_Type { /** - * <pre> * 0 is reserved for errors. * Order is weird for historical reasons. - * </pre> * - * <code>TYPE_DOUBLE = 1;</code> + * Generated from protobuf enum <code>TYPE_DOUBLE = 1;</code> */ const TYPE_DOUBLE = 1; /** - * <code>TYPE_FLOAT = 2;</code> + * Generated from protobuf enum <code>TYPE_FLOAT = 2;</code> */ const TYPE_FLOAT = 2; /** - * <pre> * Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if * negative values are likely. - * </pre> * - * <code>TYPE_INT64 = 3;</code> + * Generated from protobuf enum <code>TYPE_INT64 = 3;</code> */ const TYPE_INT64 = 3; /** - * <code>TYPE_UINT64 = 4;</code> + * Generated from protobuf enum <code>TYPE_UINT64 = 4;</code> */ const TYPE_UINT64 = 4; /** - * <pre> * Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if * negative values are likely. - * </pre> * - * <code>TYPE_INT32 = 5;</code> + * Generated from protobuf enum <code>TYPE_INT32 = 5;</code> */ const TYPE_INT32 = 5; /** - * <code>TYPE_FIXED64 = 6;</code> + * Generated from protobuf enum <code>TYPE_FIXED64 = 6;</code> */ const TYPE_FIXED64 = 6; /** - * <code>TYPE_FIXED32 = 7;</code> + * Generated from protobuf enum <code>TYPE_FIXED32 = 7;</code> */ const TYPE_FIXED32 = 7; /** - * <code>TYPE_BOOL = 8;</code> + * Generated from protobuf enum <code>TYPE_BOOL = 8;</code> */ const TYPE_BOOL = 8; /** - * <code>TYPE_STRING = 9;</code> + * Generated from protobuf enum <code>TYPE_STRING = 9;</code> */ const TYPE_STRING = 9; /** - * <pre> * Tag-delimited aggregate. * Group type is deprecated and not supported in proto3. However, Proto3 * implementations should still be able to parse the group wire format and * treat group fields as unknown fields. - * </pre> * - * <code>TYPE_GROUP = 10;</code> + * Generated from protobuf enum <code>TYPE_GROUP = 10;</code> */ const TYPE_GROUP = 10; /** - * <pre> * Length-delimited aggregate. - * </pre> * - * <code>TYPE_MESSAGE = 11;</code> + * Generated from protobuf enum <code>TYPE_MESSAGE = 11;</code> */ const TYPE_MESSAGE = 11; /** - * <pre> * New in version 2. - * </pre> * - * <code>TYPE_BYTES = 12;</code> + * Generated from protobuf enum <code>TYPE_BYTES = 12;</code> */ const TYPE_BYTES = 12; /** - * <code>TYPE_UINT32 = 13;</code> + * Generated from protobuf enum <code>TYPE_UINT32 = 13;</code> */ const TYPE_UINT32 = 13; /** - * <code>TYPE_ENUM = 14;</code> + * Generated from protobuf enum <code>TYPE_ENUM = 14;</code> */ const TYPE_ENUM = 14; /** - * <code>TYPE_SFIXED32 = 15;</code> + * Generated from protobuf enum <code>TYPE_SFIXED32 = 15;</code> */ const TYPE_SFIXED32 = 15; /** - * <code>TYPE_SFIXED64 = 16;</code> + * Generated from protobuf enum <code>TYPE_SFIXED64 = 16;</code> */ const TYPE_SFIXED64 = 16; /** - * <pre> * Uses ZigZag encoding. - * </pre> * - * <code>TYPE_SINT32 = 17;</code> + * Generated from protobuf enum <code>TYPE_SINT32 = 17;</code> */ const TYPE_SINT32 = 17; /** - * <pre> * Uses ZigZag encoding. - * </pre> * - * <code>TYPE_SINT64 = 18;</code> + * Generated from protobuf enum <code>TYPE_SINT64 = 18;</code> */ const TYPE_SINT64 = 18; } diff --git a/php/src/Google/Protobuf/Internal/FieldOptions.php b/php/src/Google/Protobuf/Internal/FieldOptions.php index 94c4418f..169f860b 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions.php @@ -8,41 +8,35 @@ 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; /** - * Protobuf type <code>google.protobuf.FieldOptions</code> + * Generated from protobuf message <code>google.protobuf.FieldOptions</code> */ class FieldOptions extends \Google\Protobuf\Internal\Message { /** - * <pre> * The ctype option instructs the C++ code generator to use a different * representation of the field than it normally would. See the specific * options below. This option is not yet implemented in the open source * release -- sorry, we'll try to include it in a future version! - * </pre> * - * <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code> */ private $ctype = 0; private $has_ctype = false; /** - * <pre> * The packed option can be enabled for repeated primitive fields to enable * a more efficient representation on the wire. Rather than repeatedly * writing the tag and type for each element, the entire array is encoded as * a single length-delimited blob. In proto3, only explicit setting it to * false will avoid using packed encoding. - * </pre> * - * <code>optional bool packed = 2;</code> + * Generated from protobuf field <code>optional bool packed = 2;</code> */ private $packed = false; private $has_packed = false; /** - * <pre> * The jstype option determines the JavaScript type used for values of the * field. The option is permitted only for 64 bit integral and fixed types * (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING @@ -53,14 +47,12 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * JS_NORMAL is implementation dependent. * This option is an enum to permit additional types to be added, e.g. * goog.math.Integer. - * </pre> * - * <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code> */ private $jstype = 0; private $has_jstype = false; /** - * <pre> * Should this field be parsed lazily? Lazy applies only to message-type * fields. It means that when the outer message is initially parsed, the * inner message's contents will not be parsed but instead stored in encoded @@ -85,39 +77,32 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * implementation must either *always* check its required fields, or *never* * check its required fields, regardless of whether or not the message has * been parsed. - * </pre> * - * <code>optional bool lazy = 5 [default = false];</code> + * Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code> */ private $lazy = false; private $has_lazy = false; /** - * <pre> * Is this field deprecated? * Depending on the target platform, this can emit Deprecated annotations * for accessors, or it will be completely ignored; in the very least, this * is a formalization for deprecating fields. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> */ private $deprecated = false; private $has_deprecated = false; /** - * <pre> * For Google-internal migration only. Do not use. - * </pre> * - * <code>optional bool weak = 10 [default = false];</code> + * Generated from protobuf field <code>optional bool weak = 10 [default = false];</code> */ private $weak = false; private $has_weak = false; /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ private $uninterpreted_option; private $has_uninterpreted_option = false; @@ -128,14 +113,13 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The ctype option instructs the C++ code generator to use a different * representation of the field than it normally would. See the specific * options below. This option is not yet implemented in the open source * release -- sorry, we'll try to include it in a future version! - * </pre> * - * <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code> + * @return int */ public function getCtype() { @@ -143,20 +127,22 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The ctype option instructs the C++ code generator to use a different * representation of the field than it normally would. See the specific * options below. This option is not yet implemented in the open source * release -- sorry, we'll try to include it in a future version! - * </pre> * - * <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code> + * @param int $var + * @return $this */ public function setCtype($var) { GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_CType::class); $this->ctype = $var; $this->has_ctype = true; + + return $this; } public function hasCtype() @@ -165,15 +151,14 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The packed option can be enabled for repeated primitive fields to enable * a more efficient representation on the wire. Rather than repeatedly * writing the tag and type for each element, the entire array is encoded as * a single length-delimited blob. In proto3, only explicit setting it to * false will avoid using packed encoding. - * </pre> * - * <code>optional bool packed = 2;</code> + * Generated from protobuf field <code>optional bool packed = 2;</code> + * @return bool */ public function getPacked() { @@ -181,21 +166,23 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The packed option can be enabled for repeated primitive fields to enable * a more efficient representation on the wire. Rather than repeatedly * writing the tag and type for each element, the entire array is encoded as * a single length-delimited blob. In proto3, only explicit setting it to * false will avoid using packed encoding. - * </pre> * - * <code>optional bool packed = 2;</code> + * Generated from protobuf field <code>optional bool packed = 2;</code> + * @param bool $var + * @return $this */ public function setPacked($var) { GPBUtil::checkBool($var); $this->packed = $var; $this->has_packed = true; + + return $this; } public function hasPacked() @@ -204,7 +191,6 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The jstype option determines the JavaScript type used for values of the * field. The option is permitted only for 64 bit integral and fixed types * (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING @@ -215,9 +201,9 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * JS_NORMAL is implementation dependent. * This option is an enum to permit additional types to be added, e.g. * goog.math.Integer. - * </pre> * - * <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code> + * @return int */ public function getJstype() { @@ -225,7 +211,6 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The jstype option determines the JavaScript type used for values of the * field. The option is permitted only for 64 bit integral and fixed types * (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING @@ -236,15 +221,18 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * JS_NORMAL is implementation dependent. * This option is an enum to permit additional types to be added, e.g. * goog.math.Integer. - * </pre> * - * <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code> + * Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code> + * @param int $var + * @return $this */ public function setJstype($var) { GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_JSType::class); $this->jstype = $var; $this->has_jstype = true; + + return $this; } public function hasJstype() @@ -253,7 +241,6 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Should this field be parsed lazily? Lazy applies only to message-type * fields. It means that when the outer message is initially parsed, the * inner message's contents will not be parsed but instead stored in encoded @@ -278,9 +265,9 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * implementation must either *always* check its required fields, or *never* * check its required fields, regardless of whether or not the message has * been parsed. - * </pre> * - * <code>optional bool lazy = 5 [default = false];</code> + * Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code> + * @return bool */ public function getLazy() { @@ -288,7 +275,6 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Should this field be parsed lazily? Lazy applies only to message-type * fields. It means that when the outer message is initially parsed, the * inner message's contents will not be parsed but instead stored in encoded @@ -313,15 +299,18 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * implementation must either *always* check its required fields, or *never* * check its required fields, regardless of whether or not the message has * been parsed. - * </pre> * - * <code>optional bool lazy = 5 [default = false];</code> + * Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code> + * @param bool $var + * @return $this */ public function setLazy($var) { GPBUtil::checkBool($var); $this->lazy = $var; $this->has_lazy = true; + + return $this; } public function hasLazy() @@ -330,14 +319,13 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this field deprecated? * Depending on the target platform, this can emit Deprecated annotations * for accessors, or it will be completely ignored; in the very least, this * is a formalization for deprecating fields. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> + * @return bool */ public function getDeprecated() { @@ -345,20 +333,22 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this field deprecated? * Depending on the target platform, this can emit Deprecated annotations * for accessors, or it will be completely ignored; in the very least, this * is a formalization for deprecating fields. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> + * @param bool $var + * @return $this */ public function setDeprecated($var) { GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -367,11 +357,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * For Google-internal migration only. Do not use. - * </pre> * - * <code>optional bool weak = 10 [default = false];</code> + * Generated from protobuf field <code>optional bool weak = 10 [default = false];</code> + * @return bool */ public function getWeak() { @@ -379,17 +368,19 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * For Google-internal migration only. Do not use. - * </pre> * - * <code>optional bool weak = 10 [default = false];</code> + * Generated from protobuf field <code>optional bool weak = 10 [default = false];</code> + * @param bool $var + * @return $this */ public function setWeak($var) { GPBUtil::checkBool($var); $this->weak = $var; $this->has_weak = true; + + return $this; } public function hasWeak() @@ -398,11 +389,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getUninterpretedOption() { @@ -410,17 +400,19 @@ class FieldOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/FieldOptions_CType.php b/php/src/Google/Protobuf/Internal/FieldOptions_CType.php index f59f20be..0f33072d 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions_CType.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions_CType.php @@ -5,24 +5,22 @@ namespace Google\Protobuf\Internal; /** - * Protobuf enum <code>google.protobuf.FieldOptions.CType</code> + * Protobuf enum <code>Google\Protobuf\Internal</code> */ class FieldOptions_CType { /** - * <pre> * Default mode. - * </pre> * - * <code>STRING = 0;</code> + * Generated from protobuf enum <code>STRING = 0;</code> */ const STRING = 0; /** - * <code>CORD = 1;</code> + * Generated from protobuf enum <code>CORD = 1;</code> */ const CORD = 1; /** - * <code>STRING_PIECE = 2;</code> + * Generated from protobuf enum <code>STRING_PIECE = 2;</code> */ const STRING_PIECE = 2; } diff --git a/php/src/Google/Protobuf/Internal/FieldOptions_JSType.php b/php/src/Google/Protobuf/Internal/FieldOptions_JSType.php index 0c6995b7..73bdf3f2 100644 --- a/php/src/Google/Protobuf/Internal/FieldOptions_JSType.php +++ b/php/src/Google/Protobuf/Internal/FieldOptions_JSType.php @@ -5,32 +5,26 @@ namespace Google\Protobuf\Internal; /** - * Protobuf enum <code>google.protobuf.FieldOptions.JSType</code> + * Protobuf enum <code>Google\Protobuf\Internal</code> */ class FieldOptions_JSType { /** - * <pre> * Use the default type. - * </pre> * - * <code>JS_NORMAL = 0;</code> + * Generated from protobuf enum <code>JS_NORMAL = 0;</code> */ const JS_NORMAL = 0; /** - * <pre> * Use JavaScript strings. - * </pre> * - * <code>JS_STRING = 1;</code> + * Generated from protobuf enum <code>JS_STRING = 1;</code> */ const JS_STRING = 1; /** - * <pre> * Use JavaScript numbers. - * </pre> * - * <code>JS_NUMBER = 2;</code> + * Generated from protobuf enum <code>JS_NUMBER = 2;</code> */ const JS_NUMBER = 2; } diff --git a/php/src/Google/Protobuf/Internal/FileDescriptor.php b/php/src/Google/Protobuf/Internal/FileDescriptor.php new file mode 100644 index 00000000..038da38c --- /dev/null +++ b/php/src/Google/Protobuf/Internal/FileDescriptor.php @@ -0,0 +1,89 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Google\Protobuf\Internal; + +class FileDescriptor +{ + + private $package; + private $message_type = []; + private $enum_type = []; + + public function setPackage($package) + { + $this->package = $package; + } + + public function getPackage() + { + return $this->package; + } + + public function getMessageType() + { + return $this->message_type; + } + + public function addMessageType($desc) + { + $this->message_type[] = $desc; + } + + public function getEnumType() + { + return $this->enum_type; + } + + public function addEnumType($desc) + { + $this->enum_type[]= $desc; + } + + public static function buildFromProto($proto) + { + $file = new FileDescriptor(); + $file->setPackage($proto->getPackage()); + foreach ($proto->getMessageType() as $message_proto) { + $file->addMessageType(Descriptor::buildFromProto( + $message_proto, $proto, "")); + } + foreach ($proto->getEnumType() as $enum_proto) { + $file->addEnumType( + EnumDescriptor::buildFromProto( + $enum_proto, + $proto, + "")); + } + return $file; + } +} diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php index 0363d9e9..9ee222d1 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorProto.php @@ -8,112 +8,93 @@ 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; /** - * <pre> * Describes a complete .proto file. - * </pre> * - * Protobuf type <code>google.protobuf.FileDescriptorProto</code> + * Generated from protobuf message <code>google.protobuf.FileDescriptorProto</code> */ class FileDescriptorProto extends \Google\Protobuf\Internal\Message { /** - * <pre> * file name, relative to root of source tree - * </pre> * - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> */ private $name = ''; private $has_name = false; /** - * <pre> * e.g. "foo", "foo.bar", etc. - * </pre> * - * <code>optional string package = 2;</code> + * Generated from protobuf field <code>optional string package = 2;</code> */ private $package = ''; private $has_package = false; /** - * <pre> * Names of files imported by this file. - * </pre> * - * <code>repeated string dependency = 3;</code> + * Generated from protobuf field <code>repeated string dependency = 3;</code> */ private $dependency; private $has_dependency = false; /** - * <pre> * Indexes of the public imported files in the dependency list above. - * </pre> * - * <code>repeated int32 public_dependency = 10;</code> + * Generated from protobuf field <code>repeated int32 public_dependency = 10;</code> */ private $public_dependency; private $has_public_dependency = false; /** - * <pre> * Indexes of the weak imported files in the dependency list. * For Google-internal migration only. Do not use. - * </pre> * - * <code>repeated int32 weak_dependency = 11;</code> + * Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code> */ private $weak_dependency; private $has_weak_dependency = false; /** - * <pre> * All top-level definitions in this file. - * </pre> * - * <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code> */ private $message_type; private $has_message_type = false; /** - * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code> */ private $enum_type; private $has_enum_type = false; /** - * <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code> + * Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code> */ private $service; private $has_service = false; /** - * <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code> */ private $extension; private $has_extension = false; /** - * <code>optional .google.protobuf.FileOptions options = 8;</code> + * Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code> */ private $options = null; private $has_options = false; /** - * <pre> * This field contains optional information about the original source code. * You may safely remove this entire field without harming runtime * functionality of the descriptors -- the information is needed only by * development tools. - * </pre> * - * <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code> + * Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code> */ private $source_code_info = null; private $has_source_code_info = false; /** - * <pre> * The syntax of the proto file. * The supported values are "proto2" and "proto3". - * </pre> * - * <code>optional string syntax = 12;</code> + * Generated from protobuf field <code>optional string syntax = 12;</code> */ private $syntax = ''; private $has_syntax = false; @@ -124,11 +105,10 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * file name, relative to root of source tree - * </pre> * - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @return string */ public function getName() { @@ -136,17 +116,19 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * file name, relative to root of source tree - * </pre> * - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @param string $var + * @return $this */ public function setName($var) { GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -155,11 +137,10 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * e.g. "foo", "foo.bar", etc. - * </pre> * - * <code>optional string package = 2;</code> + * Generated from protobuf field <code>optional string package = 2;</code> + * @return string */ public function getPackage() { @@ -167,17 +148,19 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * e.g. "foo", "foo.bar", etc. - * </pre> * - * <code>optional string package = 2;</code> + * Generated from protobuf field <code>optional string package = 2;</code> + * @param string $var + * @return $this */ public function setPackage($var) { GPBUtil::checkString($var, True); $this->package = $var; $this->has_package = true; + + return $this; } public function hasPackage() @@ -186,11 +169,10 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Names of files imported by this file. - * </pre> * - * <code>repeated string dependency = 3;</code> + * Generated from protobuf field <code>repeated string dependency = 3;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getDependency() { @@ -198,17 +180,19 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Names of files imported by this file. - * </pre> * - * <code>repeated string dependency = 3;</code> + * Generated from protobuf field <code>repeated string dependency = 3;</code> + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setDependency(&$var) + public function setDependency($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $this->dependency = $arr; $this->has_dependency = true; + + return $this; } public function hasDependency() @@ -217,11 +201,10 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Indexes of the public imported files in the dependency list above. - * </pre> * - * <code>repeated int32 public_dependency = 10;</code> + * Generated from protobuf field <code>repeated int32 public_dependency = 10;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getPublicDependency() { @@ -229,17 +212,19 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Indexes of the public imported files in the dependency list above. - * </pre> * - * <code>repeated int32 public_dependency = 10;</code> + * Generated from protobuf field <code>repeated int32 public_dependency = 10;</code> + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setPublicDependency(&$var) + public function setPublicDependency($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->public_dependency = $arr; $this->has_public_dependency = true; + + return $this; } public function hasPublicDependency() @@ -248,12 +233,11 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Indexes of the weak imported files in the dependency list. * For Google-internal migration only. Do not use. - * </pre> * - * <code>repeated int32 weak_dependency = 11;</code> + * Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getWeakDependency() { @@ -261,18 +245,20 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Indexes of the weak imported files in the dependency list. * For Google-internal migration only. Do not use. - * </pre> * - * <code>repeated int32 weak_dependency = 11;</code> + * Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code> + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setWeakDependency(&$var) + public function setWeakDependency($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->weak_dependency = $arr; $this->has_weak_dependency = true; + + return $this; } public function hasWeakDependency() @@ -281,11 +267,10 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * All top-level definitions in this file. - * </pre> * - * <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getMessageType() { @@ -293,17 +278,19 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * All top-level definitions in this file. - * </pre> * - * <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code> + * Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code> + * @param \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setMessageType(&$var) + public function setMessageType($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class); $this->message_type = $arr; $this->has_message_type = true; + + return $this; } public function hasMessageType() @@ -312,7 +299,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getEnumType() { @@ -320,13 +308,17 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code> + * Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code> + * @param \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setEnumType(&$var) + public function setEnumType($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class); $this->enum_type = $arr; $this->has_enum_type = true; + + return $this; } public function hasEnumType() @@ -335,7 +327,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code> + * Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getService() { @@ -343,13 +336,17 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code> + * Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code> + * @param \Google\Protobuf\Internal\ServiceDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setService(&$var) + public function setService($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class); $this->service = $arr; $this->has_service = true; + + return $this; } public function hasService() @@ -358,7 +355,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getExtension() { @@ -366,13 +364,17 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code> + * @param \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setExtension(&$var) + public function setExtension($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class); $this->extension = $arr; $this->has_extension = true; + + return $this; } public function hasExtension() @@ -381,7 +383,8 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.FileOptions options = 8;</code> + * Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code> + * @return \Google\Protobuf\Internal\FileOptions */ public function getOptions() { @@ -389,13 +392,17 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.FileOptions options = 8;</code> + * Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code> + * @param \Google\Protobuf\Internal\FileOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() @@ -404,14 +411,13 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * This field contains optional information about the original source code. * You may safely remove this entire field without harming runtime * functionality of the descriptors -- the information is needed only by * development tools. - * </pre> * - * <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code> + * Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code> + * @return \Google\Protobuf\Internal\SourceCodeInfo */ public function getSourceCodeInfo() { @@ -419,20 +425,22 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * This field contains optional information about the original source code. * You may safely remove this entire field without harming runtime * functionality of the descriptors -- the information is needed only by * development tools. - * </pre> * - * <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code> + * Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code> + * @param \Google\Protobuf\Internal\SourceCodeInfo $var + * @return $this */ - public function setSourceCodeInfo(&$var) + public function setSourceCodeInfo($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\SourceCodeInfo::class); $this->source_code_info = $var; $this->has_source_code_info = true; + + return $this; } public function hasSourceCodeInfo() @@ -441,12 +449,11 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * The syntax of the proto file. * The supported values are "proto2" and "proto3". - * </pre> * - * <code>optional string syntax = 12;</code> + * Generated from protobuf field <code>optional string syntax = 12;</code> + * @return string */ public function getSyntax() { @@ -454,18 +461,20 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * The syntax of the proto file. * The supported values are "proto2" and "proto3". - * </pre> * - * <code>optional string syntax = 12;</code> + * Generated from protobuf field <code>optional string syntax = 12;</code> + * @param string $var + * @return $this */ public function setSyntax($var) { GPBUtil::checkString($var, True); $this->syntax = $var; $this->has_syntax = true; + + return $this; } public function hasSyntax() diff --git a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php index 0bcc8051..0b2cf957 100644 --- a/php/src/Google/Protobuf/Internal/FileDescriptorSet.php +++ b/php/src/Google/Protobuf/Internal/FileDescriptorSet.php @@ -8,21 +8,18 @@ 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; /** - * <pre> * The protocol compiler can output a FileDescriptorSet containing the .proto * files it parses. - * </pre> * - * Protobuf type <code>google.protobuf.FileDescriptorSet</code> + * Generated from protobuf message <code>google.protobuf.FileDescriptorSet</code> */ class FileDescriptorSet extends \Google\Protobuf\Internal\Message { /** - * <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code> */ private $file; private $has_file = false; @@ -33,7 +30,8 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getFile() { @@ -41,13 +39,17 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code> + * @param \Google\Protobuf\Internal\FileDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setFile(&$var) + public function setFile($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class); $this->file = $arr; $this->has_file = true; + + return $this; } public function hasFile() diff --git a/php/src/Google/Protobuf/Internal/FileOptions.php b/php/src/Google/Protobuf/Internal/FileOptions.php index 22653a4f..c2dd5e08 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions.php +++ b/php/src/Google/Protobuf/Internal/FileOptions.php @@ -8,96 +8,82 @@ 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; /** - * Protobuf type <code>google.protobuf.FileOptions</code> + * Generated from protobuf message <code>google.protobuf.FileOptions</code> */ class FileOptions extends \Google\Protobuf\Internal\Message { /** - * <pre> * Sets the Java package where classes generated from this .proto will be * placed. By default, the proto package is used, but this is often * inappropriate because proto packages do not normally start with backwards * domain names. - * </pre> * - * <code>optional string java_package = 1;</code> + * Generated from protobuf field <code>optional string java_package = 1;</code> */ private $java_package = ''; private $has_java_package = false; /** - * <pre> * If set, all the classes from the .proto file are wrapped in a single * outer class with the given name. This applies to both Proto1 * (equivalent to the old "--one_java_file" option) and Proto2 (where * a .proto always translates to a single class, but you may want to * explicitly choose the class name). - * </pre> * - * <code>optional string java_outer_classname = 8;</code> + * Generated from protobuf field <code>optional string java_outer_classname = 8;</code> */ private $java_outer_classname = ''; private $has_java_outer_classname = false; /** - * <pre> * If set true, then the Java code generator will generate a separate .java * file for each top-level message, enum, and service defined in the .proto * file. Thus, these types will *not* be nested inside the outer class * named by java_outer_classname. However, the outer class will still be * generated to contain the file's getDescriptor() method as well as any * top-level extensions defined in the file. - * </pre> * - * <code>optional bool java_multiple_files = 10 [default = false];</code> + * Generated from protobuf field <code>optional bool java_multiple_files = 10 [default = false];</code> */ private $java_multiple_files = false; private $has_java_multiple_files = false; /** - * <pre> * This option does nothing. - * </pre> * - * <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code> + * Generated from protobuf field <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code> */ private $java_generate_equals_and_hash = false; private $has_java_generate_equals_and_hash = false; /** - * <pre> * If set true, then the Java2 code generator will generate code that * throws an exception whenever an attempt is made to assign a non-UTF-8 * byte sequence to a string field. * Message reflection will do the same. * However, an extension field still accepts non-UTF-8 byte sequences. * This option has no effect on when used with the lite runtime. - * </pre> * - * <code>optional bool java_string_check_utf8 = 27 [default = false];</code> + * Generated from protobuf field <code>optional bool java_string_check_utf8 = 27 [default = false];</code> */ private $java_string_check_utf8 = false; private $has_java_string_check_utf8 = false; /** - * <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code> + * Generated from protobuf field <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code> */ private $optimize_for = 0; private $has_optimize_for = false; /** - * <pre> * Sets the Go package where structs generated from this .proto will be * placed. If omitted, the Go package will be derived from the following: * - The basename of the package import path, if provided. * - Otherwise, the package statement in the .proto file, if present. * - Otherwise, the basename of the .proto file, without extension. - * </pre> * - * <code>optional string go_package = 11;</code> + * Generated from protobuf field <code>optional string go_package = 11;</code> */ private $go_package = ''; private $has_go_package = false; /** - * <pre> * Should generic services be generated in each language? "Generic" services * are not specific to any particular RPC system. They are generated by the * main code generators in each language (without additional plugins). @@ -107,91 +93,90 @@ class FileOptions extends \Google\Protobuf\Internal\Message * that generate code specific to your particular RPC system. Therefore, * these default to false. Old code which depends on generic services should * explicitly set them to true. - * </pre> * - * <code>optional bool cc_generic_services = 16 [default = false];</code> + * Generated from protobuf field <code>optional bool cc_generic_services = 16 [default = false];</code> */ private $cc_generic_services = false; private $has_cc_generic_services = false; /** - * <code>optional bool java_generic_services = 17 [default = false];</code> + * Generated from protobuf field <code>optional bool java_generic_services = 17 [default = false];</code> */ private $java_generic_services = false; private $has_java_generic_services = false; /** - * <code>optional bool py_generic_services = 18 [default = false];</code> + * Generated from protobuf field <code>optional bool py_generic_services = 18 [default = false];</code> */ private $py_generic_services = false; private $has_py_generic_services = false; /** - * <pre> + * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code> + */ + private $php_generic_services = false; + private $has_php_generic_services = false; + /** * Is this file deprecated? * Depending on the target platform, this can emit Deprecated annotations * for everything in the file, or it will be completely ignored; in the very * least, this is a formalization for deprecating files. - * </pre> * - * <code>optional bool deprecated = 23 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 23 [default = false];</code> */ private $deprecated = false; private $has_deprecated = false; /** - * <pre> * Enables the use of arenas for the proto messages in this file. This applies * only to generated classes for C++. - * </pre> * - * <code>optional bool cc_enable_arenas = 31 [default = false];</code> + * Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = false];</code> */ private $cc_enable_arenas = false; private $has_cc_enable_arenas = false; /** - * <pre> * Sets the objective c class prefix which is prepended to all objective c * generated classes from this .proto. There is no default. - * </pre> * - * <code>optional string objc_class_prefix = 36;</code> + * Generated from protobuf field <code>optional string objc_class_prefix = 36;</code> */ private $objc_class_prefix = ''; private $has_objc_class_prefix = false; /** - * <pre> * Namespace for generated classes; defaults to the package. - * </pre> * - * <code>optional string csharp_namespace = 37;</code> + * Generated from protobuf field <code>optional string csharp_namespace = 37;</code> */ private $csharp_namespace = ''; private $has_csharp_namespace = false; /** - * <pre> * By default Swift generators will take the proto package and CamelCase it * replacing '.' with underscore and use that to prefix the types/symbols * defined. When this options is provided, they will use this value instead * to prefix the types/symbols defined. - * </pre> * - * <code>optional string swift_prefix = 39;</code> + * Generated from protobuf field <code>optional string swift_prefix = 39;</code> */ private $swift_prefix = ''; private $has_swift_prefix = false; /** - * <pre> * Sets the php class prefix which is prepended to all php generated classes * from this .proto. Default is empty. - * </pre> * - * <code>optional string php_class_prefix = 40;</code> + * Generated from protobuf field <code>optional string php_class_prefix = 40;</code> */ private $php_class_prefix = ''; private $has_php_class_prefix = false; /** - * <pre> + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field <code>optional string php_namespace = 41;</code> + */ + private $php_namespace = ''; + private $has_php_namespace = false; + /** * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ private $uninterpreted_option; private $has_uninterpreted_option = false; @@ -202,14 +187,13 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Sets the Java package where classes generated from this .proto will be * placed. By default, the proto package is used, but this is often * inappropriate because proto packages do not normally start with backwards * domain names. - * </pre> * - * <code>optional string java_package = 1;</code> + * Generated from protobuf field <code>optional string java_package = 1;</code> + * @return string */ public function getJavaPackage() { @@ -217,20 +201,22 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Sets the Java package where classes generated from this .proto will be * placed. By default, the proto package is used, but this is often * inappropriate because proto packages do not normally start with backwards * domain names. - * </pre> * - * <code>optional string java_package = 1;</code> + * Generated from protobuf field <code>optional string java_package = 1;</code> + * @param string $var + * @return $this */ public function setJavaPackage($var) { GPBUtil::checkString($var, True); $this->java_package = $var; $this->has_java_package = true; + + return $this; } public function hasJavaPackage() @@ -239,15 +225,14 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * If set, all the classes from the .proto file are wrapped in a single * outer class with the given name. This applies to both Proto1 * (equivalent to the old "--one_java_file" option) and Proto2 (where * a .proto always translates to a single class, but you may want to * explicitly choose the class name). - * </pre> * - * <code>optional string java_outer_classname = 8;</code> + * Generated from protobuf field <code>optional string java_outer_classname = 8;</code> + * @return string */ public function getJavaOuterClassname() { @@ -255,21 +240,23 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * If set, all the classes from the .proto file are wrapped in a single * outer class with the given name. This applies to both Proto1 * (equivalent to the old "--one_java_file" option) and Proto2 (where * a .proto always translates to a single class, but you may want to * explicitly choose the class name). - * </pre> * - * <code>optional string java_outer_classname = 8;</code> + * Generated from protobuf field <code>optional string java_outer_classname = 8;</code> + * @param string $var + * @return $this */ public function setJavaOuterClassname($var) { GPBUtil::checkString($var, True); $this->java_outer_classname = $var; $this->has_java_outer_classname = true; + + return $this; } public function hasJavaOuterClassname() @@ -278,16 +265,15 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * If set true, then the Java code generator will generate a separate .java * file for each top-level message, enum, and service defined in the .proto * file. Thus, these types will *not* be nested inside the outer class * named by java_outer_classname. However, the outer class will still be * generated to contain the file's getDescriptor() method as well as any * top-level extensions defined in the file. - * </pre> * - * <code>optional bool java_multiple_files = 10 [default = false];</code> + * Generated from protobuf field <code>optional bool java_multiple_files = 10 [default = false];</code> + * @return bool */ public function getJavaMultipleFiles() { @@ -295,22 +281,24 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * If set true, then the Java code generator will generate a separate .java * file for each top-level message, enum, and service defined in the .proto * file. Thus, these types will *not* be nested inside the outer class * named by java_outer_classname. However, the outer class will still be * generated to contain the file's getDescriptor() method as well as any * top-level extensions defined in the file. - * </pre> * - * <code>optional bool java_multiple_files = 10 [default = false];</code> + * Generated from protobuf field <code>optional bool java_multiple_files = 10 [default = false];</code> + * @param bool $var + * @return $this */ public function setJavaMultipleFiles($var) { GPBUtil::checkBool($var); $this->java_multiple_files = $var; $this->has_java_multiple_files = true; + + return $this; } public function hasJavaMultipleFiles() @@ -319,11 +307,10 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * This option does nothing. - * </pre> * - * <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code> + * Generated from protobuf field <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code> + * @return bool */ public function getJavaGenerateEqualsAndHash() { @@ -331,17 +318,19 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * This option does nothing. - * </pre> * - * <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code> + * Generated from protobuf field <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code> + * @param bool $var + * @return $this */ public function setJavaGenerateEqualsAndHash($var) { GPBUtil::checkBool($var); $this->java_generate_equals_and_hash = $var; $this->has_java_generate_equals_and_hash = true; + + return $this; } public function hasJavaGenerateEqualsAndHash() @@ -350,16 +339,15 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * If set true, then the Java2 code generator will generate code that * throws an exception whenever an attempt is made to assign a non-UTF-8 * byte sequence to a string field. * Message reflection will do the same. * However, an extension field still accepts non-UTF-8 byte sequences. * This option has no effect on when used with the lite runtime. - * </pre> * - * <code>optional bool java_string_check_utf8 = 27 [default = false];</code> + * Generated from protobuf field <code>optional bool java_string_check_utf8 = 27 [default = false];</code> + * @return bool */ public function getJavaStringCheckUtf8() { @@ -367,22 +355,24 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * If set true, then the Java2 code generator will generate code that * throws an exception whenever an attempt is made to assign a non-UTF-8 * byte sequence to a string field. * Message reflection will do the same. * However, an extension field still accepts non-UTF-8 byte sequences. * This option has no effect on when used with the lite runtime. - * </pre> * - * <code>optional bool java_string_check_utf8 = 27 [default = false];</code> + * Generated from protobuf field <code>optional bool java_string_check_utf8 = 27 [default = false];</code> + * @param bool $var + * @return $this */ public function setJavaStringCheckUtf8($var) { GPBUtil::checkBool($var); $this->java_string_check_utf8 = $var; $this->has_java_string_check_utf8 = true; + + return $this; } public function hasJavaStringCheckUtf8() @@ -391,7 +381,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code> + * Generated from protobuf field <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code> + * @return int */ public function getOptimizeFor() { @@ -399,13 +390,17 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code> + * Generated from protobuf field <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code> + * @param int $var + * @return $this */ public function setOptimizeFor($var) { GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FileOptions_OptimizeMode::class); $this->optimize_for = $var; $this->has_optimize_for = true; + + return $this; } public function hasOptimizeFor() @@ -414,15 +409,14 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Sets the Go package where structs generated from this .proto will be * placed. If omitted, the Go package will be derived from the following: * - The basename of the package import path, if provided. * - Otherwise, the package statement in the .proto file, if present. * - Otherwise, the basename of the .proto file, without extension. - * </pre> * - * <code>optional string go_package = 11;</code> + * Generated from protobuf field <code>optional string go_package = 11;</code> + * @return string */ public function getGoPackage() { @@ -430,21 +424,23 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Sets the Go package where structs generated from this .proto will be * placed. If omitted, the Go package will be derived from the following: * - The basename of the package import path, if provided. * - Otherwise, the package statement in the .proto file, if present. * - Otherwise, the basename of the .proto file, without extension. - * </pre> * - * <code>optional string go_package = 11;</code> + * Generated from protobuf field <code>optional string go_package = 11;</code> + * @param string $var + * @return $this */ public function setGoPackage($var) { GPBUtil::checkString($var, True); $this->go_package = $var; $this->has_go_package = true; + + return $this; } public function hasGoPackage() @@ -453,7 +449,6 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Should generic services be generated in each language? "Generic" services * are not specific to any particular RPC system. They are generated by the * main code generators in each language (without additional plugins). @@ -463,9 +458,9 @@ class FileOptions extends \Google\Protobuf\Internal\Message * that generate code specific to your particular RPC system. Therefore, * these default to false. Old code which depends on generic services should * explicitly set them to true. - * </pre> * - * <code>optional bool cc_generic_services = 16 [default = false];</code> + * Generated from protobuf field <code>optional bool cc_generic_services = 16 [default = false];</code> + * @return bool */ public function getCcGenericServices() { @@ -473,7 +468,6 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Should generic services be generated in each language? "Generic" services * are not specific to any particular RPC system. They are generated by the * main code generators in each language (without additional plugins). @@ -483,15 +477,18 @@ class FileOptions extends \Google\Protobuf\Internal\Message * that generate code specific to your particular RPC system. Therefore, * these default to false. Old code which depends on generic services should * explicitly set them to true. - * </pre> * - * <code>optional bool cc_generic_services = 16 [default = false];</code> + * Generated from protobuf field <code>optional bool cc_generic_services = 16 [default = false];</code> + * @param bool $var + * @return $this */ public function setCcGenericServices($var) { GPBUtil::checkBool($var); $this->cc_generic_services = $var; $this->has_cc_generic_services = true; + + return $this; } public function hasCcGenericServices() @@ -500,7 +497,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <code>optional bool java_generic_services = 17 [default = false];</code> + * Generated from protobuf field <code>optional bool java_generic_services = 17 [default = false];</code> + * @return bool */ public function getJavaGenericServices() { @@ -508,13 +506,17 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <code>optional bool java_generic_services = 17 [default = false];</code> + * Generated from protobuf field <code>optional bool java_generic_services = 17 [default = false];</code> + * @param bool $var + * @return $this */ public function setJavaGenericServices($var) { GPBUtil::checkBool($var); $this->java_generic_services = $var; $this->has_java_generic_services = true; + + return $this; } public function hasJavaGenericServices() @@ -523,7 +525,8 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <code>optional bool py_generic_services = 18 [default = false];</code> + * Generated from protobuf field <code>optional bool py_generic_services = 18 [default = false];</code> + * @return bool */ public function getPyGenericServices() { @@ -531,13 +534,17 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <code>optional bool py_generic_services = 18 [default = false];</code> + * Generated from protobuf field <code>optional bool py_generic_services = 18 [default = false];</code> + * @param bool $var + * @return $this */ public function setPyGenericServices($var) { GPBUtil::checkBool($var); $this->py_generic_services = $var; $this->has_py_generic_services = true; + + return $this; } public function hasPyGenericServices() @@ -546,14 +553,41 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> + * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code> + * @return bool + */ + public function getPhpGenericServices() + { + return $this->php_generic_services; + } + + /** + * Generated from protobuf field <code>optional bool php_generic_services = 19 [default = false];</code> + * @param bool $var + * @return $this + */ + public function setPhpGenericServices($var) + { + GPBUtil::checkBool($var); + $this->php_generic_services = $var; + $this->has_php_generic_services = true; + + return $this; + } + + public function hasPhpGenericServices() + { + return $this->has_php_generic_services; + } + + /** * Is this file deprecated? * Depending on the target platform, this can emit Deprecated annotations * for everything in the file, or it will be completely ignored; in the very * least, this is a formalization for deprecating files. - * </pre> * - * <code>optional bool deprecated = 23 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 23 [default = false];</code> + * @return bool */ public function getDeprecated() { @@ -561,20 +595,22 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this file deprecated? * Depending on the target platform, this can emit Deprecated annotations * for everything in the file, or it will be completely ignored; in the very * least, this is a formalization for deprecating files. - * </pre> * - * <code>optional bool deprecated = 23 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 23 [default = false];</code> + * @param bool $var + * @return $this */ public function setDeprecated($var) { GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -583,12 +619,11 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Enables the use of arenas for the proto messages in this file. This applies * only to generated classes for C++. - * </pre> * - * <code>optional bool cc_enable_arenas = 31 [default = false];</code> + * Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = false];</code> + * @return bool */ public function getCcEnableArenas() { @@ -596,18 +631,20 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Enables the use of arenas for the proto messages in this file. This applies * only to generated classes for C++. - * </pre> * - * <code>optional bool cc_enable_arenas = 31 [default = false];</code> + * Generated from protobuf field <code>optional bool cc_enable_arenas = 31 [default = false];</code> + * @param bool $var + * @return $this */ public function setCcEnableArenas($var) { GPBUtil::checkBool($var); $this->cc_enable_arenas = $var; $this->has_cc_enable_arenas = true; + + return $this; } public function hasCcEnableArenas() @@ -616,12 +653,11 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Sets the objective c class prefix which is prepended to all objective c * generated classes from this .proto. There is no default. - * </pre> * - * <code>optional string objc_class_prefix = 36;</code> + * Generated from protobuf field <code>optional string objc_class_prefix = 36;</code> + * @return string */ public function getObjcClassPrefix() { @@ -629,18 +665,20 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Sets the objective c class prefix which is prepended to all objective c * generated classes from this .proto. There is no default. - * </pre> * - * <code>optional string objc_class_prefix = 36;</code> + * Generated from protobuf field <code>optional string objc_class_prefix = 36;</code> + * @param string $var + * @return $this */ public function setObjcClassPrefix($var) { GPBUtil::checkString($var, True); $this->objc_class_prefix = $var; $this->has_objc_class_prefix = true; + + return $this; } public function hasObjcClassPrefix() @@ -649,11 +687,10 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Namespace for generated classes; defaults to the package. - * </pre> * - * <code>optional string csharp_namespace = 37;</code> + * Generated from protobuf field <code>optional string csharp_namespace = 37;</code> + * @return string */ public function getCsharpNamespace() { @@ -661,17 +698,19 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Namespace for generated classes; defaults to the package. - * </pre> * - * <code>optional string csharp_namespace = 37;</code> + * Generated from protobuf field <code>optional string csharp_namespace = 37;</code> + * @param string $var + * @return $this */ public function setCsharpNamespace($var) { GPBUtil::checkString($var, True); $this->csharp_namespace = $var; $this->has_csharp_namespace = true; + + return $this; } public function hasCsharpNamespace() @@ -680,14 +719,13 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * By default Swift generators will take the proto package and CamelCase it * replacing '.' with underscore and use that to prefix the types/symbols * defined. When this options is provided, they will use this value instead * to prefix the types/symbols defined. - * </pre> * - * <code>optional string swift_prefix = 39;</code> + * Generated from protobuf field <code>optional string swift_prefix = 39;</code> + * @return string */ public function getSwiftPrefix() { @@ -695,20 +733,22 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * By default Swift generators will take the proto package and CamelCase it * replacing '.' with underscore and use that to prefix the types/symbols * defined. When this options is provided, they will use this value instead * to prefix the types/symbols defined. - * </pre> * - * <code>optional string swift_prefix = 39;</code> + * Generated from protobuf field <code>optional string swift_prefix = 39;</code> + * @param string $var + * @return $this */ public function setSwiftPrefix($var) { GPBUtil::checkString($var, True); $this->swift_prefix = $var; $this->has_swift_prefix = true; + + return $this; } public function hasSwiftPrefix() @@ -717,12 +757,11 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Sets the php class prefix which is prepended to all php generated classes * from this .proto. Default is empty. - * </pre> * - * <code>optional string php_class_prefix = 40;</code> + * Generated from protobuf field <code>optional string php_class_prefix = 40;</code> + * @return string */ public function getPhpClassPrefix() { @@ -730,18 +769,20 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Sets the php class prefix which is prepended to all php generated classes * from this .proto. Default is empty. - * </pre> * - * <code>optional string php_class_prefix = 40;</code> + * Generated from protobuf field <code>optional string php_class_prefix = 40;</code> + * @param string $var + * @return $this */ public function setPhpClassPrefix($var) { GPBUtil::checkString($var, True); $this->php_class_prefix = $var; $this->has_php_class_prefix = true; + + return $this; } public function hasPhpClassPrefix() @@ -750,11 +791,46 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field <code>optional string php_namespace = 41;</code> + * @return string + */ + public function getPhpNamespace() + { + return $this->php_namespace; + } + + /** + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field <code>optional string php_namespace = 41;</code> + * @param string $var + * @return $this + */ + public function setPhpNamespace($var) + { + GPBUtil::checkString($var, True); + $this->php_namespace = $var; + $this->has_php_namespace = true; + + return $this; + } + + public function hasPhpNamespace() + { + return $this->has_php_namespace; + } + + /** * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getUninterpretedOption() { @@ -762,17 +838,19 @@ class FileOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php b/php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php index b550e7f1..4dd56ef8 100644 --- a/php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php +++ b/php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php @@ -5,36 +5,28 @@ namespace Google\Protobuf\Internal; /** - * <pre> * Generated classes can be optimized for speed or code size. - * </pre> * - * Protobuf enum <code>google.protobuf.FileOptions.OptimizeMode</code> + * Protobuf enum <code>Google\Protobuf\Internal</code> */ class FileOptions_OptimizeMode { /** - * <pre> * Generate complete code for parsing, serialization, - * </pre> * - * <code>SPEED = 1;</code> + * Generated from protobuf enum <code>SPEED = 1;</code> */ const SPEED = 1; /** - * <pre> * etc. - * </pre> * - * <code>CODE_SIZE = 2;</code> + * Generated from protobuf enum <code>CODE_SIZE = 2;</code> */ const CODE_SIZE = 2; /** - * <pre> * Generate code using MessageLite and the lite runtime. - * </pre> * - * <code>LITE_RUNTIME = 3;</code> + * Generated from protobuf enum <code>LITE_RUNTIME = 3;</code> */ const LITE_RUNTIME = 3; } diff --git a/php/src/Google/Protobuf/Internal/GPBJsonWire.php b/php/src/Google/Protobuf/Internal/GPBJsonWire.php new file mode 100644 index 00000000..97789356 --- /dev/null +++ b/php/src/Google/Protobuf/Internal/GPBJsonWire.php @@ -0,0 +1,285 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Google\Protobuf\Internal; + +class GPBJsonWire +{ + + public static function serializeFieldToStream( + $value, + $field, + &$output) + { + $output->writeRaw("\"", 1); + $field_name = GPBJsonWire::formatFieldName($field); + $output->writeRaw($field_name, strlen($field_name)); + $output->writeRaw("\":", 2); + return static::serializeFieldValueToStream($value, $field, $output); + } + + private static function serializeFieldValueToStream( + $values, + $field, + &$output) + { + if ($field->isMap()) { + $output->writeRaw("{", 1); + $first = true; + $map_entry = $field->getMessageType(); + $key_field = $map_entry->getFieldByNumber(1); + $value_field = $map_entry->getFieldByNumber(2); + + switch ($key_field->getType()) { + case GPBType::STRING: + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + case GPBType::FIXED64: + case GPBType::UINT64: + $additional_quote = false; + break; + default: + $additional_quote = true; + } + + foreach ($values as $key => $value) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if ($additional_quote) { + $output->writeRaw("\"", 1); + } + if (!static::serializeSingularFieldValueToStream( + $key, + $key_field, + $output)) { + return false; + } + if ($additional_quote) { + $output->writeRaw("\"", 1); + } + $output->writeRaw(":", 1); + if (!static::serializeSingularFieldValueToStream( + $value, + $value_field, + $output)) { + return false; + } + } + $output->writeRaw("}", 1); + return true; + } elseif ($field->isRepeated()) { + $output->writeRaw("[", 1); + $first = true; + foreach ($values as $value) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if (!static::serializeSingularFieldValueToStream( + $value, + $field, + $output)) { + return false; + } + } + $output->writeRaw("]", 1); + return true; + } else { + return static::serializeSingularFieldValueToStream( + $values, + $field, + $output); + } + } + + private static function serializeSingularFieldValueToStream( + $value, + $field, + &$output) + { + switch ($field->getType()) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + if ($value < 0) { + $value = bcadd($value, "4294967296"); + } + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + if ($value < 0) { + $value = bcadd($value, "18446744073709551616"); + } + // Intentional fall through. + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + $output->writeRaw("\"", 1); + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + $output->writeRaw("\"", 1); + break; + case GPBType::FLOAT: + if (is_nan($value)) { + $str_value = "\"NaN\""; + } elseif ($value === INF) { + $str_value = "\"Infinity\""; + } elseif ($value === -INF) { + $str_value = "\"-Infinity\""; + } else { + $str_value = sprintf("%.8g", $value); + } + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::DOUBLE: + if (is_nan($value)) { + $str_value = "\"NaN\""; + } elseif ($value === INF) { + $str_value = "\"Infinity\""; + } elseif ($value === -INF) { + $str_value = "\"-Infinity\""; + } else { + $str_value = sprintf("%.17g", $value); + } + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::ENUM: + $enum_desc = $field->getEnumType(); + $enum_value_desc = $enum_desc->getValueByNumber($value); + if (!is_null($enum_value_desc)) { + $str_value = $enum_value_desc->getName(); + $output->writeRaw("\"", 1); + $output->writeRaw($str_value, strlen($str_value)); + $output->writeRaw("\"", 1); + } else { + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + } + break; + case GPBType::BOOL: + if ($value) { + $output->writeRaw("true", 4); + } else { + $output->writeRaw("false", 5); + } + break; + case GPBType::BYTES: + $value = base64_encode($value); + case GPBType::STRING: + $value = json_encode($value); + $output->writeRaw($value, strlen($value)); + break; + // case GPBType::GROUP: + // echo "GROUP\xA"; + // trigger_error("Not implemented.", E_ERROR); + // break; + case GPBType::MESSAGE: + $value->serializeToJsonStream($output); + break; + default: + user_error("Unsupported type."); + return false; + } + return true; + } + + private static function formatFieldName($field) + { + return $field->getJsonName(); + } + + // Used for escaping control chars in strings. + private static $k_control_char_limit = 0x20; + + private static function jsonNiceEscape($c) + { + switch ($c) { + case '"': return "\\\""; + case '\\': return "\\\\"; + case '/': return "\\/"; + case '\b': return "\\b"; + case '\f': return "\\f"; + case '\n': return "\\n"; + case '\r': return "\\r"; + case '\t': return "\\t"; + default: return NULL; + } + } + + private static function isJsonEscaped($c) + { + // See RFC 4627. + return $c < chr($k_control_char_limit) || $c === "\"" || $c === "\\"; + } + + public static function escapedJson($value) + { + $escaped_value = ""; + $unescaped_run = ""; + for ($i = 0; $i < strlen($value); $i++) { + $c = $value[$i]; + // Handle escaping. + if (static::isJsonEscaped($c)) { + // Use a "nice" escape, like \n, if one exists for this + // character. + $escape = static::jsonNiceEscape($c); + if (is_null($escape)) { + $escape = "\\u00" . bin2hex($c); + } + if ($unescaped_run !== "") { + $escaped_value .= $unescaped_run; + $unescaped_run = ""; + } + $escaped_value .= $escape; + } else { + if ($unescaped_run === "") { + $unescaped_run .= $c; + } + } + } + $escaped_value .= $unescaped_run; + return $escaped_value; + } + +} diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 0e66ae6f..22ad27f9 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -45,8 +45,13 @@ class GPBUtil $value = bcsub(0, $value); } - $high = (int) bcdiv(bcadd($value, 1), 4294967296); + $high = bcdiv($value, 4294967296); $low = bcmod($value, 4294967296); + if (bccomp($high, 2147483647) > 0) { + $high = (int) bcsub($high, 4294967296); + } else { + $high = (int) $high; + } if (bccomp($low, 2147483647) > 0) { $low = (int) bcsub($low, 4294967296); } else { @@ -58,7 +63,7 @@ class GPBUtil $low = ~$low; $low++; if (!$low) { - $high++; + $high = (int)($high + 1); } } @@ -67,19 +72,16 @@ class GPBUtil } } - public static function checkString(&$var, $check_utf8) { if (is_array($var) || is_object($var)) { - trigger_error("Expect string.", E_USER_ERROR); - return; + throw new \InvalidArgumentException("Expect string."); } if (!is_string($var)) { $var = strval($var); } if ($check_utf8 && !preg_match('//u', $var)) { - trigger_error("Expect utf-8 encoding.", E_USER_ERROR); - return; + throw new \Exception("Expect utf-8 encoding."); } } @@ -93,7 +95,7 @@ class GPBUtil if (is_numeric($var)) { $var = intval($var); } else { - trigger_error("Expect integer.", E_USER_ERROR); + throw new \Exception("Expect integer."); } } @@ -110,7 +112,7 @@ class GPBUtil $var = (int) $var; } } else { - trigger_error("Expect integer.", E_USER_ERROR); + throw new \Exception("Expect integer."); } } @@ -120,10 +122,15 @@ class GPBUtil if (PHP_INT_SIZE == 8) { $var = intval($var); } else { - $var = bcdiv($var, 1, 0); + if (is_float($var) || + is_integer($var) || + (is_string($var) && + bccomp($var, "9223372036854774784") < 0)) { + $var = number_format($var, 0, ".", ""); + } } } else { - trigger_error("Expect integer.", E_USER_ERROR); + throw new \Exception("Expect integer."); } } @@ -133,10 +140,10 @@ class GPBUtil if (PHP_INT_SIZE == 8) { $var = intval($var); } else { - $var = bcdiv($var, 1, 0); + $var = number_format($var, 0, ".", ""); } } else { - trigger_error("Expect integer.", E_USER_ERROR); + throw new \Exception("Expect integer."); } } @@ -145,7 +152,7 @@ class GPBUtil if (is_float($var) || is_numeric($var)) { $var = floatval($var); } else { - trigger_error("Expect float.", E_USER_ERROR); + throw new \Exception("Expect float."); } } @@ -154,15 +161,14 @@ class GPBUtil if (is_float($var) || is_numeric($var)) { $var = floatval($var); } else { - trigger_error("Expect float.", E_USER_ERROR); + throw new \Exception("Expect float."); } } public static function checkBool(&$var) { if (is_array($var) || is_object($var)) { - trigger_error("Expect boolean.", E_USER_ERROR); - return; + throw new \Exception("Expect boolean."); } $var = boolval($var); } @@ -170,14 +176,14 @@ class GPBUtil public static function checkMessage(&$var, $klass) { if (!$var instanceof $klass && !is_null($var)) { - trigger_error("Expect message.", E_USER_ERROR); + throw new \Exception("Expect message."); } } public static function checkRepeatedField(&$var, $type, $klass = null) { if (!$var instanceof RepeatedField && !is_array($var)) { - trigger_error("Expect array.", E_USER_ERROR); + throw new \Exception("Expect array."); } if (is_array($var)) { $tmp = new RepeatedField($type, $klass); @@ -187,15 +193,13 @@ class GPBUtil return $tmp; } else { if ($var->getType() != $type) { - trigger_error( - "Expect repeated field of different type.", - E_USER_ERROR); + throw new \Exception( + "Expect repeated field of different type."); } if ($var->getType() === GPBType::MESSAGE && $var->getClass() !== $klass) { - trigger_error( - "Expect repeated field of different message.", - E_USER_ERROR); + throw new \Exception( + "Expect repeated field of different message."); } return $var; } @@ -204,7 +208,7 @@ class GPBUtil public static function checkMapField(&$var, $key_type, $value_type, $klass = null) { if (!$var instanceof MapField && !is_array($var)) { - trigger_error("Expect dict.", E_USER_ERROR); + throw new \Exception("Expect dict."); } if (is_array($var)) { $tmp = new MapField($key_type, $value_type, $klass); @@ -214,20 +218,15 @@ class GPBUtil return $tmp; } else { if ($var->getKeyType() != $key_type) { - trigger_error( - "Expect map field of key type.", - E_USER_ERROR); + throw new \Exception("Expect map field of key type."); } if ($var->getValueType() != $value_type) { - trigger_error( - "Expect map field of value type.", - E_USER_ERROR); + throw new \Exception("Expect map field of value type."); } if ($var->getValueType() === GPBType::MESSAGE && $var->getValueClass() !== $klass) { - trigger_error( - "Expect map field of different value message.", - E_USER_ERROR); + throw new \Exception( + "Expect map field of different value message."); } return $var; } @@ -242,4 +241,103 @@ class GPBUtil { return new Uint64($value); } + + public static function getClassNamePrefix( + $classname, + $file_proto) + { + $option = $file_proto->getOptions(); + $prefix = is_null($option) ? "" : $option->getPhpClassPrefix(); + if ($prefix !== "") { + return $prefix; + } + + $reserved_words = array("Empty", "ECHO", "ARRAY"); + foreach ($reserved_words as $reserved_word) { + if ($classname === $reserved_word) { + if ($file_proto->getPackage() === "google.protobuf") { + return "GPB"; + } else { + return "PB"; + } + } + } + + return ""; + } + + public static function getClassNameWithoutPackage( + $name, + $file_proto) + { + $classname = implode('_', array_map('ucwords', explode('.', $name))); + return static::getClassNamePrefix($classname, $file_proto) . $classname; + } + + public static function getFullClassName( + $proto, + $containing, + $file_proto, + &$message_name_without_package, + &$classname, + &$fullname) + { + // Full name needs to start with '.'. + $message_name_without_package = $proto->getName(); + if ($containing !== "") { + $message_name_without_package = + $containing . "." . $message_name_without_package; + } + + $package = $file_proto->getPackage(); + if ($package === "") { + $fullname = "." . $message_name_without_package; + } else { + $fullname = "." . $package . "." . $message_name_without_package; + } + + $class_name_without_package = + static::getClassNameWithoutPackage($message_name_without_package, $file_proto); + + $option = $file_proto->getOptions(); + if (!is_null($option) && $option->hasPhpNamespace()) { + $namespace = $option->getPhpNamespace(); + if ($namespace !== "") { + $classname = $namespace . "\\" . $class_name_without_package; + return; + } else { + $classname = $class_name_without_package; + return; + } + } + + if ($package === "") { + $classname = $class_name_without_package; + } else { + $classname = + implode('\\', array_map('ucwords', explode('.', $package))). + "\\".$class_name_without_package; + } + } + + public static function combineInt32ToInt64($high, $low) + { + $isNeg = $high < 0; + if ($isNeg) { + $high = ~$high; + $low = ~$low; + $low++; + if (!$low) { + $high = (int) ($high + 1); + } + } + $result = bcadd(bcmul($high, 4294967296), $low); + if ($low < 0) { + $result = bcadd($result, 4294967296); + } + if ($isNeg) { + $result = bcsub(0, $result); + } + return $result; + } } diff --git a/php/src/Google/Protobuf/Internal/GPBWire.php b/php/src/Google/Protobuf/Internal/GPBWire.php index 67eb1bee..e7eec552 100644 --- a/php/src/Google/Protobuf/Internal/GPBWire.php +++ b/php/src/Google/Protobuf/Internal/GPBWire.php @@ -117,19 +117,12 @@ class GPBWire // << decode << public static function zigZagEncode32($int32) { - // Fill high 32 bits. - if (PHP_INT_SIZE === 8) { - $int32 |= ((($int32 << 32) >> 31) & (0xFFFFFFFF << 32)); + if (PHP_INT_SIZE == 8) { + $trim_int32 = $int32 & 0xFFFFFFFF; + return (($trim_int32 << 1) ^ ($int32 << 32 >> 63)) & 0xFFFFFFFF; + } else { + return ($int32 << 1) ^ ($int32 >> 31); } - - $uint32 = ($int32 << 1) ^ ($int32 >> 31); - - // Fill high 32 bits. - if (PHP_INT_SIZE === 8) { - $uint32 |= ((($uint32 << 32) >> 31) & (0xFFFFFFFF << 32)); - } - - return $uint32; } public static function zigZagDecode32($uint32) @@ -177,7 +170,11 @@ class GPBWire public static function readInt64(&$input, &$value) { - return $input->readVarint64($value); + $success = $input->readVarint64($value); + if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $success; } public static function readUint32(&$input, &$value) @@ -231,7 +228,11 @@ class GPBWire public static function readSfixed64(&$input, &$value) { - return $input->readLittleEndian64($value); + $success = $input->readLittleEndian64($value); + if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $success; } public static function readFloat(&$input, &$value) @@ -298,7 +299,7 @@ class GPBWire public static function writeInt32(&$output, $value) { - return $output->writeVarint32($value); + return $output->writeVarint32($value, false); } public static function writeInt64(&$output, $value) @@ -308,7 +309,7 @@ class GPBWire public static function writeUint32(&$output, $value) { - return $output->writeVarint32($value); + return $output->writeVarint32($value, true); } public static function writeUint64(&$output, $value) @@ -319,7 +320,7 @@ class GPBWire public static function writeSint32(&$output, $value) { $value = GPBWire::zigZagEncode32($value); - return $output->writeVarint64($value); + return $output->writeVarint32($value, true); } public static function writeSint64(&$output, $value) @@ -351,9 +352,9 @@ class GPBWire public static function writeBool(&$output, $value) { if ($value) { - return $output->writeVarint32(1); + return $output->writeVarint32(1, true); } else { - return $output->writeVarint32(0); + return $output->writeVarint32(0, true); } } @@ -377,7 +378,7 @@ class GPBWire public static function writeBytes(&$output, $value) { $size = strlen($value); - if (!$output->writeVarint32($size)) { + if (!$output->writeVarint32($size, true)) { return false; } return $output->writeRaw($value, $size); @@ -386,7 +387,7 @@ class GPBWire public static function writeMessage(&$output, $value) { $size = $value->byteSize(); - if (!$output->writeVarint32($size)) { + if (!$output->writeVarint32($size, true)) { return false; } return $value->serializeToStream($output); @@ -442,7 +443,8 @@ class GPBWire public static function varint64Size($value) { if (PHP_INT_SIZE == 4) { - if (bccomp($value, 0) < 0) { + if (bccomp($value, 0) < 0 || + bccomp($value, "9223372036854775807") > 0) { return 10; } if (bccomp($value, 1 << 7) < 0) { @@ -578,6 +580,9 @@ class GPBWire } break; case GPBType::UINT32: + if (PHP_INT_SIZE === 8 && $value < 0) { + $value += 4294967296; + } if (!GPBWire::writeUint32($output, $value)) { return false; } diff --git a/php/src/Google/Protobuf/Internal/GPBWireType.php b/php/src/Google/Protobuf/Internal/GPBWireType.php new file mode 100644 index 00000000..c1ad370e --- /dev/null +++ b/php/src/Google/Protobuf/Internal/GPBWireType.php @@ -0,0 +1,43 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Google\Protobuf\Internal; + +class GPBWireType +{ + const VARINT = 0; + const FIXED64 = 1; + const LENGTH_DELIMITED = 2; + const START_GROUP = 3; + const END_GROUP = 4; + const FIXED32 = 5; +} diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php index 450854f1..ae2ad745 100644 --- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php +++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php @@ -8,27 +8,22 @@ 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; /** - * <pre> * Describes the relationship between generated code and its original source * file. A GeneratedCodeInfo message is associated with only one generated * source file, but may contain references to different source .proto files. - * </pre> * - * Protobuf type <code>google.protobuf.GeneratedCodeInfo</code> + * Generated from protobuf message <code>google.protobuf.GeneratedCodeInfo</code> */ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message { /** - * <pre> * An Annotation connects some span of text in generated code to an element * of its generating .proto file. - * </pre> * - * <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code> */ private $annotation; private $has_annotation = false; @@ -39,12 +34,11 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message } /** - * <pre> * An Annotation connects some span of text in generated code to an element * of its generating .proto file. - * </pre> * - * <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getAnnotation() { @@ -52,18 +46,20 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message } /** - * <pre> * An Annotation connects some span of text in generated code to an element * of its generating .proto file. - * </pre> * - * <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code> + * @param \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setAnnotation(&$var) + public function setAnnotation($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class); $this->annotation = $arr; $this->has_annotation = true; + + return $this; } public function hasAnnotation() diff --git a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php index ed22cc38..22ac2337 100644 --- a/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php +++ b/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php @@ -8,51 +8,42 @@ 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; /** - * Protobuf type <code>google.protobuf.GeneratedCodeInfo.Annotation</code> + * Generated from protobuf message <code>google.protobuf.GeneratedCodeInfo.Annotation</code> */ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message { /** - * <pre> * Identifies the element in the original source .proto file. This field * is formatted the same as SourceCodeInfo.Location.path. - * </pre> * - * <code>repeated int32 path = 1 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code> */ private $path; private $has_path = false; /** - * <pre> * Identifies the filesystem path to the original source .proto. - * </pre> * - * <code>optional string source_file = 2;</code> + * Generated from protobuf field <code>optional string source_file = 2;</code> */ private $source_file = ''; private $has_source_file = false; /** - * <pre> * Identifies the starting offset in bytes in the generated code * that relates to the identified object. - * </pre> * - * <code>optional int32 begin = 3;</code> + * Generated from protobuf field <code>optional int32 begin = 3;</code> */ private $begin = 0; private $has_begin = false; /** - * <pre> * Identifies the ending offset in bytes in the generated code that * relates to the identified offset. The end offset should be one past * the last relevant byte (so the length of the text = end - begin). - * </pre> * - * <code>optional int32 end = 4;</code> + * Generated from protobuf field <code>optional int32 end = 4;</code> */ private $end = 0; private $has_end = false; @@ -63,12 +54,11 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies the element in the original source .proto file. This field * is formatted the same as SourceCodeInfo.Location.path. - * </pre> * - * <code>repeated int32 path = 1 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getPath() { @@ -76,18 +66,20 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies the element in the original source .proto file. This field * is formatted the same as SourceCodeInfo.Location.path. - * </pre> * - * <code>repeated int32 path = 1 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code> + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setPath(&$var) + public function setPath($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->path = $arr; $this->has_path = true; + + return $this; } public function hasPath() @@ -96,11 +88,10 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies the filesystem path to the original source .proto. - * </pre> * - * <code>optional string source_file = 2;</code> + * Generated from protobuf field <code>optional string source_file = 2;</code> + * @return string */ public function getSourceFile() { @@ -108,17 +99,19 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies the filesystem path to the original source .proto. - * </pre> * - * <code>optional string source_file = 2;</code> + * Generated from protobuf field <code>optional string source_file = 2;</code> + * @param string $var + * @return $this */ public function setSourceFile($var) { GPBUtil::checkString($var, True); $this->source_file = $var; $this->has_source_file = true; + + return $this; } public function hasSourceFile() @@ -127,12 +120,11 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies the starting offset in bytes in the generated code * that relates to the identified object. - * </pre> * - * <code>optional int32 begin = 3;</code> + * Generated from protobuf field <code>optional int32 begin = 3;</code> + * @return int */ public function getBegin() { @@ -140,18 +132,20 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies the starting offset in bytes in the generated code * that relates to the identified object. - * </pre> * - * <code>optional int32 begin = 3;</code> + * Generated from protobuf field <code>optional int32 begin = 3;</code> + * @param int $var + * @return $this */ public function setBegin($var) { GPBUtil::checkInt32($var); $this->begin = $var; $this->has_begin = true; + + return $this; } public function hasBegin() @@ -160,13 +154,12 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies the ending offset in bytes in the generated code that * relates to the identified offset. The end offset should be one past * the last relevant byte (so the length of the text = end - begin). - * </pre> * - * <code>optional int32 end = 4;</code> + * Generated from protobuf field <code>optional int32 end = 4;</code> + * @return int */ public function getEnd() { @@ -174,19 +167,21 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies the ending offset in bytes in the generated code that * relates to the identified offset. The end offset should be one past * the last relevant byte (so the length of the text = end - begin). - * </pre> * - * <code>optional int32 end = 4;</code> + * Generated from protobuf field <code>optional int32 end = 4;</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() diff --git a/php/src/Google/Protobuf/Internal/MapField.php b/php/src/Google/Protobuf/Internal/MapField.php index 55cc12ce..38736dad 100644 --- a/php/src/Google/Protobuf/Internal/MapField.php +++ b/php/src/Google/Protobuf/Internal/MapField.php @@ -38,131 +38,6 @@ namespace Google\Protobuf\Internal; /** - * MapFieldIter is used to iterate MapField. It is also need for the foreach - * syntax. - */ -class MapFieldIter implements \Iterator -{ - - /** - * @ignore - */ - private $container; - - /** - * Create iterator instance for MapField. - * - * @param MapField The MapField instance for which this iterator is - * created. - * @ignore - */ - public function __construct($container) - { - $this->container = $container; - } - - /** - * Reset the status of the iterator - * - * @return void - */ - public function rewind() - { - return reset($this->container); - } - - /** - * Return the element at the current position. - * - * @return object The element at the current position. - */ - public function current() - { - return current($this->container); - } - - /** - * Return the current key. - * - * @return object The current key. - */ - public function key() - { - return key($this->container); - } - - /** - * Move to the next position. - * - * @return void - */ - public function next() - { - return next($this->container); - } - - /** - * Check whether there are more elements to iterate. - * - * @return bool True if there are more elements to iterate. - */ - public function valid() - { - return key($this->container) !== null; - } -} - -/** - * @ignore - */ -function checkKey($key_type, &$key) -{ - switch ($key_type) { - case GPBType::INT32: - GPBUtil::checkInt32($key); - break; - case GPBType::UINT32: - GPBUtil::checkUint32($key); - break; - case GPBType::INT64: - GPBUtil::checkInt64($key); - break; - case GPBType::UINT64: - GPBUtil::checkUint64($key); - break; - case GPBType::FIXED64: - GPBUtil::checkUint64($key); - break; - case GPBType::FIXED32: - GPBUtil::checkUint32($key); - break; - case GPBType::SFIXED64: - GPBUtil::checkInt64($key); - break; - case GPBType::SFIXED32: - GPBUtil::checkInt32($key); - break; - case GPBType::SINT64: - GPBUtil::checkInt64($key); - break; - case GPBType::SINT32: - GPBUtil::checkInt32($key); - break; - case GPBType::BOOL: - GPBUtil::checkBool($key); - break; - case GPBType::STRING: - GPBUtil::checkString($key, true); - break; - default: - trigger_error( - "Given type cannot be map key.", - E_USER_ERROR); - break; - } -} - -/** * MapField is used by generated protocol message classes to manipulate map * fields. It can be used like native PHP array. */ @@ -255,7 +130,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable */ public function offsetSet($key, $value) { - checkKey($this->key_type, $key); + $this->checkKey($this->key_type, $key); switch ($this->value_type) { case GPBType::INT32: @@ -306,7 +181,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable */ public function offsetUnset($key) { - checkKey($this->key_type, $key); + $this->checkKey($this->key_type, $key); unset($this->container[$key]); } @@ -321,7 +196,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable */ public function offsetExists($key) { - checkKey($this->key_type, $key); + $this->checkKey($this->key_type, $key); return isset($this->container[$key]); } @@ -330,7 +205,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable */ public function getIterator() { - return new MapFieldIter($this->container); + return new MapFieldIter($this->container, $this->key_type); } /** @@ -344,4 +219,54 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable { return count($this->container); } + + /** + * @ignore + */ + private function checkKey($key_type, &$key) + { + switch ($key_type) { + case GPBType::INT32: + GPBUtil::checkInt32($key); + break; + case GPBType::UINT32: + GPBUtil::checkUint32($key); + break; + case GPBType::INT64: + GPBUtil::checkInt64($key); + break; + case GPBType::UINT64: + GPBUtil::checkUint64($key); + break; + case GPBType::FIXED64: + GPBUtil::checkUint64($key); + break; + case GPBType::FIXED32: + GPBUtil::checkUint32($key); + break; + case GPBType::SFIXED64: + GPBUtil::checkInt64($key); + break; + case GPBType::SFIXED32: + GPBUtil::checkInt32($key); + break; + case GPBType::SINT64: + GPBUtil::checkInt64($key); + break; + case GPBType::SINT32: + GPBUtil::checkInt32($key); + break; + case GPBType::BOOL: + GPBUtil::checkBool($key); + break; + case GPBType::STRING: + GPBUtil::checkString($key, true); + break; + default: + trigger_error( + "Given type cannot be map key.", + E_USER_ERROR); + break; + } + } } diff --git a/php/src/Google/Protobuf/Internal/MapFieldIter.php b/php/src/Google/Protobuf/Internal/MapFieldIter.php new file mode 100644 index 00000000..88e6c8b2 --- /dev/null +++ b/php/src/Google/Protobuf/Internal/MapFieldIter.php @@ -0,0 +1,124 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** + * MapField and MapFieldIter are used by generated protocol message classes to + * manipulate map fields. + */ + +namespace Google\Protobuf\Internal; + +/** + * MapFieldIter is used to iterate MapField. It is also need for the foreach + * syntax. + */ +class MapFieldIter implements \Iterator +{ + + /** + * @ignore + */ + private $container; + + /** + * Create iterator instance for MapField. + * + * @param MapField The MapField instance for which this iterator is + * created. + * @param GPBType Map key type. + * @ignore + */ + public function __construct($container, $key_type) + { + $this->container = $container; + $this->key_type = $key_type; + } + + /** + * Reset the status of the iterator + * + * @return void + */ + public function rewind() + { + return reset($this->container); + } + + /** + * Return the element at the current position. + * + * @return object The element at the current position. + */ + public function current() + { + return current($this->container); + } + + /** + * Return the current key. + * + * @return object The current key. + */ + public function key() + { + $key = key($this->container); + if ($this->key_type === GPBType::BOOL) { + // PHP associative array stores bool as integer for key. + return boolval($key); + } elseif ($this->key_type === GPBType::STRING) { + // PHP associative array stores int string as int for key. + return strval($key); + } else { + return $key; + } + } + + /** + * Move to the next position. + * + * @return void + */ + public function next() + { + return next($this->container); + } + + /** + * Check whether there are more elements to iterate. + * + * @return bool True if there are more elements to iterate. + */ + public function valid() + { + return key($this->container) !== null; + } +} diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index cd15e0f0..1ecd4fa2 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -36,8 +36,8 @@ namespace Google\Protobuf\Internal; -use Google\Protobuf\Internal\InputStream; -use Google\Protobuf\Internal\OutputStream; +use Google\Protobuf\Internal\CodedInputStream; +use Google\Protobuf\Internal\CodedOutputStream; use Google\Protobuf\Internal\DescriptorPool; use Google\Protobuf\Internal\GPBLabel; use Google\Protobuf\Internal\GPBType; @@ -68,6 +68,10 @@ class Message // specific descriptor from the descriptor pool. if (get_class($this) === 'Google\Protobuf\Internal\MapEntry') { $this->desc = $desc; + foreach ($desc->getField() as $field) { + $setter = $field->getSetter(); + $this->$setter($this->defaultValue($field)); + } return; } $pool = DescriptorPool::getGeneratedPool(); @@ -219,6 +223,58 @@ class Message /** * @ignore */ + private static function skipField($input, $tag) + { + $number = GPBWire::getTagFieldNumber($tag); + if ($number === 0) { + throw new GPBDecodeException("Illegal field number zero."); + } + + switch (GPBWire::getTagWireType($tag)) { + case GPBWireType::VARINT: + $uint64 = 0; + if (!$input->readVarint64($uint64)) { + throw new GPBDecodeException( + "Unexpected EOF inside varint."); + } + return; + case GPBWireType::FIXED64: + $uint64 = 0; + if (!$input->readLittleEndian64($uint64)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed64."); + } + return; + case GPBWireType::FIXED32: + $uint32 = 0; + if (!$input->readLittleEndian32($uint32)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed32."); + } + return; + case GPBWireType::LENGTH_DELIMITED: + $length = 0; + if (!$input->readVarint32($length)) { + throw new GPBDecodeException( + "Unexpected EOF inside length."); + } + $data = NULL; + if (!$input->readRaw($length, $data)) { + throw new GPBDecodeException( + "Unexpected EOF inside length delimited data."); + } + return; + case GPBWireType::START_GROUP: + case GPBWireType::END_GROUP: + throw new GPBDecodeException("Unexpected wire type."); + default: + throw new GPBDecodeException("Unexpected wire type."); + } + } + + /** + * @ignore + */ private static function parseFieldFromStreamNoTag($input, $field, &$value) { switch ($field->getType()) { @@ -278,7 +334,6 @@ class Message } break; case GPBType::GROUP: - echo "GROUP\xA"; trigger_error("Not implemented.", E_ERROR); break; case GPBType::MESSAGE: @@ -349,19 +404,25 @@ class Message private function parseFieldFromStream($tag, $input, $field) { $value = null; - $field_type = $field->getType(); - $value_format = GPBWire::UNKNOWN; - if (GPBWire::getTagWireType($tag) === - GPBWire::getWireType($field_type)) { + if (is_null($field)) { + $value_format = GPBWire::UNKNOWN; + } elseif (GPBWire::getTagWireType($tag) === + GPBWire::getWireType($field->getType())) { $value_format = GPBWire::NORMAL_FORMAT; } elseif ($field->isPackable() && GPBWire::getTagWireType($tag) === GPBWire::WIRETYPE_LENGTH_DELIMITED) { $value_format = GPBWire::PACKED_FORMAT; + } else { + // the wire type doesn't match. Put it in our unknown field set. + $value_format = GPBWire::UNKNOWN; } - if ($value_format === GPBWire::NORMAL_FORMAT) { + if ($value_format === GPBWire::UNKNOWN) { + self::skipField($input, $tag); + return; + } elseif ($value_format === GPBWire::NORMAL_FORMAT) { self::parseFieldFromStreamNoTag($input, $field, $value); } elseif ($value_format === GPBWire::PACKED_FORMAT) { $length = 0; @@ -373,20 +434,18 @@ class Message $getter = $field->getGetter(); while ($input->bytesUntilLimit() > 0) { self::parseFieldFromStreamNoTag($input, $field, $value); - $this->$getter()[] = $value; + $this->appendHelper($field, $value); } $input->popLimit($limit); return; } else { - return false; + return; } if ($field->isMap()) { - $getter = $field->getGetter(); - $this->$getter()[$value->getKey()] = $value->getValue(); + $this->kvUpdateHelper($field, $value->getKey(), $value->getValue()); } else if ($field->isRepeated()) { - $getter = $field->getGetter(); - $this->$getter()[] = $value; + $this->appendHelper($field, $value); } else { $setter = $field->getSetter(); $this->$setter($value); @@ -533,9 +592,10 @@ class Message $klass = $value_field->getMessageType()->getClass(); $copy = new $klass; $copy->mergeFrom($value); - $this->$getter()[$key] = $copy; + + $this->kvUpdateHelper($field, $key, $copy); } else { - $this->$getter()[$key] = $value; + $this->kvUpdateHelper($field, $key, $value); } } } @@ -546,9 +606,9 @@ class Message $klass = $field->getMessageType()->getClass(); $copy = new $klass; $copy->mergeFrom($tmp); - $this->$getter()[] = $copy; + $this->appendHelper($field, $copy); } else { - $this->$getter()[] = $tmp; + $this->appendHelper($field, $tmp); } } } @@ -584,11 +644,29 @@ class Message */ public function mergeFromString($data) { - $input = new InputStream($data); + $input = new CodedInputStream($data); $this->parseFromStream($input); } /** + * Parses a json string to protobuf message. + * + * This function takes a string in the json wire format, matching the + * encoding output by serializeToJsonString(). + * See mergeFrom() for merging behavior, if the field is already set in the + * specified message. + * + * @param string $data Json protobuf data. + * @return null. + * @throws Exception Invalid data. + */ + public function mergeFromJsonString($data) + { + $input = new RawInputStream($data); + $this->parseFromJsonStream($input); + } + + /** * @ignore */ public function parseFromStream($input) @@ -603,12 +681,233 @@ class Message $number = GPBWire::getTagFieldNumber($tag); $field = $this->desc->getFieldByNumber($number); - // Check whether we retrieved a known field - if ($field === NULL) { - continue; + $this->parseFieldFromStream($tag, $input, $field); + } + } + + private function convertJsonValueToProtoValue( + $value, + $field, + $is_map_key = false) + { + if (is_null($value)) { + return $this->defaultValue($field); + } + 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") { + $submsg->mergeFromJsonArray($value); + } + return $submsg; + case GPBType::ENUM: + if (is_integer($value)) { + return $value; + } else { + $enum_value = + $field->getEnumType()->getValueByName($value); + } + if (!is_null($enum_value)) { + return $enum_value->getNumber(); + } + case GPBType::STRING: + if (!is_string($value)) { + throw new GPBDecodeException("Expect string"); + } + return $value; + case GPBType::BYTES: + if (!is_string($value)) { + throw new GPBDecodeException("Expect string"); + } + $proto_value = base64_decode($value, true); + if ($proto_value === false) { + throw new GPBDecodeException( + "Invalid base64 characters"); + } + return $proto_value; + case GPBType::BOOL: + if ($is_map_key) { + if ($value === "true") { + return true; + } + if ($value === "false") { + return false; + } + throw new GPBDecodeException( + "Bool field only accept bool value"); + } + if (!is_bool($value)) { + throw new GPBDecodeException( + "Bool field only accept bool value"); + } + return $value; + case GPBType::FLOAT: + if ($value === "Infinity") { + return INF; + } + if ($value === "-Infinity") { + return -INF; + } + if ($value === "NaN") { + return NAN; + } + return $value; + case GPBType::DOUBLE: + if ($value === "Infinity") { + return INF; + } + if ($value === "-Infinity") { + return -INF; + } + if ($value === "NaN") { + return NAN; + } + return $value; + case GPBType::INT32: + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int32 field"); + } + if (bccomp($value, "2147483647") > 0) { + throw new GPBDecodeException( + "Int32 too large"); + } + if (bccomp($value, "-2147483648") < 0) { + throw new GPBDecodeException( + "Int32 too small"); + } + return $value; + case GPBType::UINT32: + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for uint32 field"); + } + if (bccomp($value, 4294967295) > 0) { + throw new GPBDecodeException( + "Uint32 too large"); + } + return $value; + case GPBType::INT64: + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (bccomp($value, "9223372036854775807") > 0) { + throw new GPBDecodeException( + "Int64 too large"); + } + if (bccomp($value, "-9223372036854775808") < 0) { + throw new GPBDecodeException( + "Int64 too small"); + } + return $value; + case GPBType::UINT64: + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (bccomp($value, "18446744073709551615") > 0) { + throw new GPBDecodeException( + "Uint64 too large"); + } + if (bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $value; + case GPBType::FIXED64: + return $value; + default: + return $value; + } + } + + private function mergeFromJsonArray($array) + { + foreach ($array as $key => $value) { + $field = $this->desc->getFieldByJsonName($key); + if (is_null($field)) { + $field = $this->desc->getFieldByName($key); + if (is_null($field)) { + continue; + } } + $setter = $field->getSetter(); + if ($field->isMap()) { + if (is_null($value)) { + continue; + } + $getter = $field->getGetter(); + $key_field = $field->getMessageType()->getFieldByNumber(1); + $value_field = $field->getMessageType()->getFieldByNumber(2); + foreach ($value as $tmp_key => $tmp_value) { + if (is_null($tmp_value)) { + throw new \Exception( + "Map value field element cannot be null."); + } + $proto_key = + $this->convertJsonValueToProtoValue( + $tmp_key, + $key_field, + true); + $proto_value = + $this->convertJsonValueToProtoValue( + $tmp_value, + $value_field); + $this->$getter()[$proto_key] = $proto_value; + } + } else if ($field->isRepeated()) { + if (is_null($value)) { + continue; + } + $getter = $field->getGetter(); + foreach ($value as $tmp) { + if (is_null($tmp)) { + throw new \Exception( + "Repeated field elements cannot be null."); + } + $proto_value = + $this->convertJsonValueToProtoValue($tmp, $field); + $this->$getter()[] = $proto_value; + } + } else { + $setter = $field->getSetter(); + $proto_value = + $this->convertJsonValueToProtoValue($value, $field); + if ($field->getType() === GPBType::MESSAGE) { + if (is_null($proto_value)) { + continue; + } + $getter = $field->getGetter(); + $submsg = $this->$getter(); + if (!is_null($submsg)) { + $submsg->mergeFrom($proto_value); + continue; + } + } + $this->$setter($proto_value); + } + } + } - $this->parseFieldFromStream($tag, $input, $field); + /** + * @ignore + */ + public function parseFromJsonStream($input) + { + $array = json_decode($input->getData(), JSON_BIGINT_AS_STRING); + if (is_null($array)) { + throw new GPBDecodeException( + "Cannot decode json string."); + } + try { + $this->mergeFromJsonArray($array); + } catch (Exception $e) { + throw new GPBDecodeException($e->getMessage()); } } @@ -651,7 +950,7 @@ class Message foreach ($values as $value) { $size += $this->fieldDataOnlyByteSize($field, $value); } - if (!$output->writeVarint32($size)) { + if (!$output->writeVarint32($size, true)) { return false; } } @@ -712,6 +1011,16 @@ class Message /** * @ignore */ + private function serializeFieldToJsonStream(&$output, $field) + { + $getter = $field->getGetter(); + $values = $this->$getter(); + return GPBJsonWire::serializeFieldToStream($values, $field, $output); + } + + /** + * @ignore + */ public function serializeToStream(&$output) { $fields = $this->desc->getField(); @@ -724,24 +1033,72 @@ class Message } /** + * @ignore + */ + 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; + } + } + } + $output->writeRaw("}", 1); + return true; + } + + /** * Serialize the message to string. * @return string Serialized binary protobuf data. */ public function serializeToString() { - $output = new OutputStream($this->byteSize()); + $output = new CodedOutputStream($this->byteSize()); $this->serializeToStream($output); return $output->getData(); } /** + * Serialize the message to json string. + * @return string Serialized json protobuf data. + */ + public function serializeToJsonString() + { + $output = new CodedOutputStream($this->jsonByteSize()); + $this->serializeToJsonStream($output); + return $output->getData(); + } + + /** * @ignore */ private function existField($field) { + $oneof_index = $field->getOneofIndex(); + if ($oneof_index !== -1) { + $oneof = $this->desc->getOneofDecl()[$oneof_index]; + $oneof_name = $oneof->getName(); + return $this->$oneof_name->getNumber() === $field->getNumber(); + } + $getter = $field->getGetter(); - $value = $this->$getter(); - return $value !== $this->defaultValue($field); + $values = $this->$getter(); + if ($field->isMap()) { + return count($values) !== 0; + } elseif ($field->isRepeated()) { + return count($values) !== 0; + } else { + return $values !== $this->defaultValue($field); + } } /** @@ -824,6 +1181,101 @@ class Message /** * @ignore */ + private function fieldDataOnlyJsonByteSize($field, $value) + { + $size = 0; + + switch ($field->getType()) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + $size += strlen(strval($value)); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + if ($value < 0) { + $value = bcadd($value, "4294967296"); + } + $size += strlen(strval($value)); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + if ($value < 0) { + $value = bcadd($value, "18446744073709551616"); + } + // Intentional fall through. + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + $size += 2; // size for "" + $size += strlen(strval($value)); + break; + case GPBType::FLOAT: + if (is_nan($value)) { + $size += strlen("NaN") + 2; + } elseif ($value === INF) { + $size += strlen("Infinity") + 2; + } elseif ($value === -INF) { + $size += strlen("-Infinity") + 2; + } else { + $size += strlen(sprintf("%.8g", $value)); + } + break; + case GPBType::DOUBLE: + if (is_nan($value)) { + $size += strlen("NaN") + 2; + } elseif ($value === INF) { + $size += strlen("Infinity") + 2; + } elseif ($value === -INF) { + $size += strlen("-Infinity") + 2; + } else { + $size += strlen(sprintf("%.17g", $value)); + } + break; + case GPBType::ENUM: + $enum_desc = $field->getEnumType(); + $enum_value_desc = $enum_desc->getValueByNumber($value); + if (!is_null($enum_value_desc)) { + $size += 2; // size for "" + $size += strlen($enum_value_desc->getName()); + } else { + $str_value = strval($value); + $size += strlen($str_value); + } + break; + case GPBType::BOOL: + if ($value) { + $size += 4; + } else { + $size += 5; + } + break; + case GPBType::STRING: + $value = json_encode($value); + $size += strlen($value); + break; + case GPBType::BYTES: + $size += strlen(base64_encode($value)); + $size += 2; // size for \"\" + break; + case GPBType::MESSAGE: + $size += $value->jsonByteSize(); + break; +# case GPBType::GROUP: +# // TODO(teboring): Add support. +# user_error("Unsupported type."); +# break; + default: + user_error("Unsupported type " . $field->getType()); + return 0; + } + + return $size; + } + + /** + * @ignore + */ private function fieldByteSize($field) { $size = 0; @@ -838,12 +1290,18 @@ class Message $value_field = $message_type->getFieldByNumber(2); foreach ($values as $key => $value) { $data_size = 0; - $data_size += $this->fieldDataOnlyByteSize($key_field, $key); - $data_size += $this->fieldDataOnlyByteSize( - $value_field, - $value); - $data_size += GPBWire::tagSize($key_field); - $data_size += GPBWire::tagSize($value_field); + if ($key != $this->defaultValue($key_field)) { + $data_size += $this->fieldDataOnlyByteSize( + $key_field, + $key); + $data_size += GPBWire::tagSize($key_field); + } + if ($value != $this->defaultValue($value_field)) { + $data_size += $this->fieldDataOnlyByteSize( + $value_field, + $value); + $data_size += GPBWire::tagSize($value_field); + } $size += GPBWire::varint32Size($data_size) + $data_size; } } @@ -879,6 +1337,68 @@ class Message /** * @ignore */ + private function fieldJsonByteSize($field) + { + $size = 0; + if ($field->isMap()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + $size += 5; // size for "\"\":{}". + $size += strlen($field->getJsonName()); // size for field name + $size += $count - 1; // size for commas + $getter = $field->getGetter(); + $map_entry = $field->getMessageType(); + $key_field = $map_entry->getFieldByNumber(1); + $value_field = $map_entry->getFieldByNumber(2); + switch ($key_field->getType()) { + case GPBType::STRING: + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + case GPBType::FIXED64: + case GPBType::UINT64: + $additional_quote = false; + break; + default: + $additional_quote = true; + } + foreach ($values as $key => $value) { + if ($additional_quote) { + $size += 2; // size for "" + } + $size += $this->fieldDataOnlyJsonByteSize($key_field, $key); + $size += $this->fieldDataOnlyJsonByteSize($value_field, $value); + $size += 1; // size for : + } + } + } elseif ($field->isRepeated()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + $size += 5; // size for "\"\":[]". + $size += strlen($field->getJsonName()); // size for field name + $size += $count - 1; // size for commas + $getter = $field->getGetter(); + foreach ($values as $value) { + $size += $this->fieldDataOnlyJsonByteSize($field, $value); + } + } + } elseif ($this->existField($field)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + $getter = $field->getGetter(); + $value = $this->$getter(); + $size += $this->fieldDataOnlyJsonByteSize($field, $value); + } + return $size; + } + + /** + * @ignore + */ public function byteSize() { $size = 0; @@ -889,4 +1409,54 @@ class Message } return $size; } + + private function appendHelper($field, $append_value) + { + $getter = $field->getGetter(); + $setter = $field->getSetter(); + + $field_arr_value = $this->$getter(); + $field_arr_value[] = $append_value; + + if (!is_object($field_arr_value)) { + $this->$setter($field_arr_value); + } + } + + private function kvUpdateHelper($field, $update_key, $update_value) + { + $getter = $field->getGetter(); + $setter = $field->getSetter(); + + $field_arr_value = $this->$getter(); + $field_arr_value[$update_key] = $update_value; + + if (!is_object($field_arr_value)) { + $this->$setter($field_arr_value); + } + } + + /** + * @ignore + */ + 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++; + } + } + // size for comma + $size += $count > 0 ? ($count - 1) : 0; + return $size; + } } diff --git a/php/src/Google/Protobuf/Internal/MessageOptions.php b/php/src/Google/Protobuf/Internal/MessageOptions.php index 747f3294..99ff3d0e 100644 --- a/php/src/Google/Protobuf/Internal/MessageOptions.php +++ b/php/src/Google/Protobuf/Internal/MessageOptions.php @@ -8,16 +8,14 @@ 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; /** - * Protobuf type <code>google.protobuf.MessageOptions</code> + * Generated from protobuf message <code>google.protobuf.MessageOptions</code> */ class MessageOptions extends \Google\Protobuf\Internal\Message { /** - * <pre> * Set true to use the old proto1 MessageSet wire format for extensions. * This is provided for backwards-compatibility with the MessageSet wire * format. You should not use this for any other reason: It's less @@ -33,41 +31,35 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * be int32s, enums, or repeated messages. * Because this is an option, the above two restrictions are not enforced by * the protocol compiler. - * </pre> * - * <code>optional bool message_set_wire_format = 1 [default = false];</code> + * Generated from protobuf field <code>optional bool message_set_wire_format = 1 [default = false];</code> */ private $message_set_wire_format = false; private $has_message_set_wire_format = false; /** - * <pre> * Disables the generation of the standard "descriptor()" accessor, which can * conflict with a field of the same name. This is meant to make migration * from proto1 easier; new code should avoid fields named "descriptor". - * </pre> * - * <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code> + * Generated from protobuf field <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code> */ private $no_standard_descriptor_accessor = false; private $has_no_standard_descriptor_accessor = false; /** - * <pre> * Is this message deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the message, or it will be completely ignored; in the very least, * this is a formalization for deprecating messages. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> */ private $deprecated = false; private $has_deprecated = false; /** - * <pre> * Whether the message is an automatically generated map entry type for the * maps field. * For maps fields: - * map<KeyType, ValueType> map_field = 1; + * map<KeyType, ValueType> map_field = 1; * The parsed descriptor looks like: * message MapFieldEntry { * option map_entry = true; @@ -82,18 +74,15 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * NOTE: Do not set the option in .proto files. Always use the maps syntax * instead. The option should only be implicitly set by the proto compiler * parser. - * </pre> * - * <code>optional bool map_entry = 7;</code> + * Generated from protobuf field <code>optional bool map_entry = 7;</code> */ private $map_entry = false; private $has_map_entry = false; /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ private $uninterpreted_option; private $has_uninterpreted_option = false; @@ -104,7 +93,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Set true to use the old proto1 MessageSet wire format for extensions. * This is provided for backwards-compatibility with the MessageSet wire * format. You should not use this for any other reason: It's less @@ -120,9 +108,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * be int32s, enums, or repeated messages. * Because this is an option, the above two restrictions are not enforced by * the protocol compiler. - * </pre> * - * <code>optional bool message_set_wire_format = 1 [default = false];</code> + * Generated from protobuf field <code>optional bool message_set_wire_format = 1 [default = false];</code> + * @return bool */ public function getMessageSetWireFormat() { @@ -130,7 +118,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Set true to use the old proto1 MessageSet wire format for extensions. * This is provided for backwards-compatibility with the MessageSet wire * format. You should not use this for any other reason: It's less @@ -146,15 +133,18 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * be int32s, enums, or repeated messages. * Because this is an option, the above two restrictions are not enforced by * the protocol compiler. - * </pre> * - * <code>optional bool message_set_wire_format = 1 [default = false];</code> + * Generated from protobuf field <code>optional bool message_set_wire_format = 1 [default = false];</code> + * @param bool $var + * @return $this */ public function setMessageSetWireFormat($var) { GPBUtil::checkBool($var); $this->message_set_wire_format = $var; $this->has_message_set_wire_format = true; + + return $this; } public function hasMessageSetWireFormat() @@ -163,13 +153,12 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Disables the generation of the standard "descriptor()" accessor, which can * conflict with a field of the same name. This is meant to make migration * from proto1 easier; new code should avoid fields named "descriptor". - * </pre> * - * <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code> + * Generated from protobuf field <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code> + * @return bool */ public function getNoStandardDescriptorAccessor() { @@ -177,19 +166,21 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Disables the generation of the standard "descriptor()" accessor, which can * conflict with a field of the same name. This is meant to make migration * from proto1 easier; new code should avoid fields named "descriptor". - * </pre> * - * <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code> + * Generated from protobuf field <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code> + * @param bool $var + * @return $this */ public function setNoStandardDescriptorAccessor($var) { GPBUtil::checkBool($var); $this->no_standard_descriptor_accessor = $var; $this->has_no_standard_descriptor_accessor = true; + + return $this; } public function hasNoStandardDescriptorAccessor() @@ -198,14 +189,13 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this message deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the message, or it will be completely ignored; in the very least, * this is a formalization for deprecating messages. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> + * @return bool */ public function getDeprecated() { @@ -213,20 +203,22 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this message deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the message, or it will be completely ignored; in the very least, * this is a formalization for deprecating messages. - * </pre> * - * <code>optional bool deprecated = 3 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code> + * @param bool $var + * @return $this */ public function setDeprecated($var) { GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -235,11 +227,10 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Whether the message is an automatically generated map entry type for the * maps field. * For maps fields: - * map<KeyType, ValueType> map_field = 1; + * map<KeyType, ValueType> map_field = 1; * The parsed descriptor looks like: * message MapFieldEntry { * option map_entry = true; @@ -254,9 +245,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * NOTE: Do not set the option in .proto files. Always use the maps syntax * instead. The option should only be implicitly set by the proto compiler * parser. - * </pre> * - * <code>optional bool map_entry = 7;</code> + * Generated from protobuf field <code>optional bool map_entry = 7;</code> + * @return bool */ public function getMapEntry() { @@ -264,11 +255,10 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Whether the message is an automatically generated map entry type for the * maps field. * For maps fields: - * map<KeyType, ValueType> map_field = 1; + * map<KeyType, ValueType> map_field = 1; * The parsed descriptor looks like: * message MapFieldEntry { * option map_entry = true; @@ -283,15 +273,18 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * NOTE: Do not set the option in .proto files. Always use the maps syntax * instead. The option should only be implicitly set by the proto compiler * parser. - * </pre> * - * <code>optional bool map_entry = 7;</code> + * Generated from protobuf field <code>optional bool map_entry = 7;</code> + * @param bool $var + * @return $this */ public function setMapEntry($var) { GPBUtil::checkBool($var); $this->map_entry = $var; $this->has_map_entry = true; + + return $this; } public function hasMapEntry() @@ -300,11 +293,10 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getUninterpretedOption() { @@ -312,17 +304,19 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php index 3d8df7af..ccfce2db 100644 --- a/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php @@ -8,58 +8,49 @@ 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; /** - * <pre> * Describes a method of a service. - * </pre> * - * Protobuf type <code>google.protobuf.MethodDescriptorProto</code> + * Generated from protobuf message <code>google.protobuf.MethodDescriptorProto</code> */ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message { /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> */ private $name = ''; private $has_name = false; /** - * <pre> * Input and output type names. These are resolved in the same way as * FieldDescriptorProto.type_name, but must refer to a message type. - * </pre> * - * <code>optional string input_type = 2;</code> + * Generated from protobuf field <code>optional string input_type = 2;</code> */ private $input_type = ''; private $has_input_type = false; /** - * <code>optional string output_type = 3;</code> + * Generated from protobuf field <code>optional string output_type = 3;</code> */ private $output_type = ''; private $has_output_type = false; /** - * <code>optional .google.protobuf.MethodOptions options = 4;</code> + * Generated from protobuf field <code>optional .google.protobuf.MethodOptions options = 4;</code> */ private $options = null; private $has_options = false; /** - * <pre> * Identifies if client streams multiple client messages - * </pre> * - * <code>optional bool client_streaming = 5 [default = false];</code> + * Generated from protobuf field <code>optional bool client_streaming = 5 [default = false];</code> */ private $client_streaming = false; private $has_client_streaming = false; /** - * <pre> * Identifies if server streams multiple server messages - * </pre> * - * <code>optional bool server_streaming = 6 [default = false];</code> + * Generated from protobuf field <code>optional bool server_streaming = 6 [default = false];</code> */ private $server_streaming = false; private $has_server_streaming = false; @@ -70,7 +61,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @return string */ public function getName() { @@ -78,13 +70,17 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @param string $var + * @return $this */ public function setName($var) { GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -93,12 +89,11 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Input and output type names. These are resolved in the same way as * FieldDescriptorProto.type_name, but must refer to a message type. - * </pre> * - * <code>optional string input_type = 2;</code> + * Generated from protobuf field <code>optional string input_type = 2;</code> + * @return string */ public function getInputType() { @@ -106,18 +101,20 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Input and output type names. These are resolved in the same way as * FieldDescriptorProto.type_name, but must refer to a message type. - * </pre> * - * <code>optional string input_type = 2;</code> + * Generated from protobuf field <code>optional string input_type = 2;</code> + * @param string $var + * @return $this */ public function setInputType($var) { GPBUtil::checkString($var, True); $this->input_type = $var; $this->has_input_type = true; + + return $this; } public function hasInputType() @@ -126,7 +123,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string output_type = 3;</code> + * Generated from protobuf field <code>optional string output_type = 3;</code> + * @return string */ public function getOutputType() { @@ -134,13 +132,17 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string output_type = 3;</code> + * Generated from protobuf field <code>optional string output_type = 3;</code> + * @param string $var + * @return $this */ public function setOutputType($var) { GPBUtil::checkString($var, True); $this->output_type = $var; $this->has_output_type = true; + + return $this; } public function hasOutputType() @@ -149,7 +151,8 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.MethodOptions options = 4;</code> + * Generated from protobuf field <code>optional .google.protobuf.MethodOptions options = 4;</code> + * @return \Google\Protobuf\Internal\MethodOptions */ public function getOptions() { @@ -157,13 +160,17 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.MethodOptions options = 4;</code> + * Generated from protobuf field <code>optional .google.protobuf.MethodOptions options = 4;</code> + * @param \Google\Protobuf\Internal\MethodOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MethodOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() @@ -172,11 +179,10 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies if client streams multiple client messages - * </pre> * - * <code>optional bool client_streaming = 5 [default = false];</code> + * Generated from protobuf field <code>optional bool client_streaming = 5 [default = false];</code> + * @return bool */ public function getClientStreaming() { @@ -184,17 +190,19 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies if client streams multiple client messages - * </pre> * - * <code>optional bool client_streaming = 5 [default = false];</code> + * Generated from protobuf field <code>optional bool client_streaming = 5 [default = false];</code> + * @param bool $var + * @return $this */ public function setClientStreaming($var) { GPBUtil::checkBool($var); $this->client_streaming = $var; $this->has_client_streaming = true; + + return $this; } public function hasClientStreaming() @@ -203,11 +211,10 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies if server streams multiple server messages - * </pre> * - * <code>optional bool server_streaming = 6 [default = false];</code> + * Generated from protobuf field <code>optional bool server_streaming = 6 [default = false];</code> + * @return bool */ public function getServerStreaming() { @@ -215,17 +222,19 @@ class MethodDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies if server streams multiple server messages - * </pre> * - * <code>optional bool server_streaming = 6 [default = false];</code> + * Generated from protobuf field <code>optional bool server_streaming = 6 [default = false];</code> + * @param bool $var + * @return $this */ public function setServerStreaming($var) { GPBUtil::checkBool($var); $this->server_streaming = $var; $this->has_server_streaming = true; + + return $this; } public function hasServerStreaming() diff --git a/php/src/Google/Protobuf/Internal/MethodOptions.php b/php/src/Google/Protobuf/Internal/MethodOptions.php index 6dca5854..baa806b7 100644 --- a/php/src/Google/Protobuf/Internal/MethodOptions.php +++ b/php/src/Google/Protobuf/Internal/MethodOptions.php @@ -8,37 +8,32 @@ 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; /** - * Protobuf type <code>google.protobuf.MethodOptions</code> + * Generated from protobuf message <code>google.protobuf.MethodOptions</code> */ class MethodOptions extends \Google\Protobuf\Internal\Message { /** - * <pre> * Is this method deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the method, or it will be completely ignored; in the very least, * this is a formalization for deprecating methods. - * </pre> * - * <code>optional bool deprecated = 33 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code> */ private $deprecated = false; private $has_deprecated = false; /** - * <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code> + * Generated from protobuf field <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code> */ private $idempotency_level = 0; private $has_idempotency_level = false; /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ private $uninterpreted_option; private $has_uninterpreted_option = false; @@ -49,14 +44,13 @@ class MethodOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this method deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the method, or it will be completely ignored; in the very least, * this is a formalization for deprecating methods. - * </pre> * - * <code>optional bool deprecated = 33 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code> + * @return bool */ public function getDeprecated() { @@ -64,20 +58,22 @@ class MethodOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this method deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the method, or it will be completely ignored; in the very least, * this is a formalization for deprecating methods. - * </pre> * - * <code>optional bool deprecated = 33 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code> + * @param bool $var + * @return $this */ public function setDeprecated($var) { GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -86,7 +82,8 @@ class MethodOptions extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code> + * Generated from protobuf field <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code> + * @return int */ public function getIdempotencyLevel() { @@ -94,13 +91,17 @@ class MethodOptions extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code> + * Generated from protobuf field <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code> + * @param int $var + * @return $this */ public function setIdempotencyLevel($var) { GPBUtil::checkEnum($var, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class); $this->idempotency_level = $var; $this->has_idempotency_level = true; + + return $this; } public function hasIdempotencyLevel() @@ -109,11 +110,10 @@ class MethodOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getUninterpretedOption() { @@ -121,17 +121,19 @@ class MethodOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php b/php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php index ce4adfe7..9e06d8ee 100644 --- a/php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php +++ b/php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php @@ -5,34 +5,28 @@ namespace Google\Protobuf\Internal; /** - * <pre> * Is this method side-effect-free (or safe in HTTP parlance), or idempotent, * or neither? HTTP based RPC implementation may choose GET verb for safe * methods, and PUT verb for idempotent methods instead of the default POST. - * </pre> * - * Protobuf enum <code>google.protobuf.MethodOptions.IdempotencyLevel</code> + * Protobuf enum <code>Google\Protobuf\Internal</code> */ class MethodOptions_IdempotencyLevel { /** - * <code>IDEMPOTENCY_UNKNOWN = 0;</code> + * Generated from protobuf enum <code>IDEMPOTENCY_UNKNOWN = 0;</code> */ const IDEMPOTENCY_UNKNOWN = 0; /** - * <pre> * implies idempotent - * </pre> * - * <code>NO_SIDE_EFFECTS = 1;</code> + * Generated from protobuf enum <code>NO_SIDE_EFFECTS = 1;</code> */ const NO_SIDE_EFFECTS = 1; /** - * <pre> * idempotent, but may have side effects - * </pre> * - * <code>IDEMPOTENT = 2;</code> + * Generated from protobuf enum <code>IDEMPOTENT = 2;</code> */ const IDEMPOTENT = 2; } diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptor.php b/php/src/Google/Protobuf/Internal/OneofDescriptor.php new file mode 100644 index 00000000..04988737 --- /dev/null +++ b/php/src/Google/Protobuf/Internal/OneofDescriptor.php @@ -0,0 +1,67 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Google\Protobuf\Internal; + +class OneofDescriptor +{ + + private $name; + private $fields; + + public function setName($name) + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function addField(&$field) + { + $this->fields[] = $field; + } + + public function getFields() + { + return $this->fields; + } + + public static function buildFromProto($oneof_proto) + { + $oneof = new OneofDescriptor(); + $oneof->setName($oneof_proto->getName()); + return $oneof; + } +} diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php index e5fbe370..15ff0610 100644 --- a/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php @@ -8,25 +8,22 @@ 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; /** - * <pre> * Describes a oneof. - * </pre> * - * Protobuf type <code>google.protobuf.OneofDescriptorProto</code> + * Generated from protobuf message <code>google.protobuf.OneofDescriptorProto</code> */ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message { /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> */ private $name = ''; private $has_name = false; /** - * <code>optional .google.protobuf.OneofOptions options = 2;</code> + * Generated from protobuf field <code>optional .google.protobuf.OneofOptions options = 2;</code> */ private $options = null; private $has_options = false; @@ -37,7 +34,8 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @return string */ public function getName() { @@ -45,13 +43,17 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @param string $var + * @return $this */ public function setName($var) { GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -60,7 +62,8 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.OneofOptions options = 2;</code> + * Generated from protobuf field <code>optional .google.protobuf.OneofOptions options = 2;</code> + * @return \Google\Protobuf\Internal\OneofOptions */ public function getOptions() { @@ -68,13 +71,17 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.OneofOptions options = 2;</code> + * Generated from protobuf field <code>optional .google.protobuf.OneofOptions options = 2;</code> + * @param \Google\Protobuf\Internal\OneofOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\OneofOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/OneofOptions.php b/php/src/Google/Protobuf/Internal/OneofOptions.php index b61325d2..e5b4633d 100644 --- a/php/src/Google/Protobuf/Internal/OneofOptions.php +++ b/php/src/Google/Protobuf/Internal/OneofOptions.php @@ -8,20 +8,17 @@ 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; /** - * Protobuf type <code>google.protobuf.OneofOptions</code> + * Generated from protobuf message <code>google.protobuf.OneofOptions</code> */ class OneofOptions extends \Google\Protobuf\Internal\Message { /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ private $uninterpreted_option; private $has_uninterpreted_option = false; @@ -32,11 +29,10 @@ class OneofOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getUninterpretedOption() { @@ -44,17 +40,19 @@ class OneofOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/RawInputStream.php b/php/src/Google/Protobuf/Internal/RawInputStream.php new file mode 100644 index 00000000..4e7ed5cb --- /dev/null +++ b/php/src/Google/Protobuf/Internal/RawInputStream.php @@ -0,0 +1,50 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +namespace Google\Protobuf\Internal; + +class RawInputStream +{ + + private $buffer; + + public function __construct($buffer) + { + $this->buffer = $buffer; + } + + public function getData() + { + return $this->buffer; + } + +} diff --git a/php/src/Google/Protobuf/Internal/RepeatedField.php b/php/src/Google/Protobuf/Internal/RepeatedField.php index 2ad4709a..797b3b3a 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -41,86 +41,6 @@ use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBUtil; /** - * RepeatedFieldIter is used to iterate RepeatedField. It is also need for the - * foreach syntax. - */ -class RepeatedFieldIter implements \Iterator -{ - - /** - * @ignore - */ - private $position; - /** - * @ignore - */ - private $container; - - /** - * Create iterator instance for RepeatedField. - * - * @param RepeatedField The RepeatedField instance for which this iterator - * is created. - * @ignore - */ - public function __construct($container) - { - $this->position = 0; - $this->container = $container; - } - - /** - * Reset the status of the iterator - * - * @return void - */ - public function rewind() - { - $this->position = 0; - } - - /** - * Return the element at the current position. - * - * @return object The element at the current position. - */ - public function current() - { - return $this->container[$this->position]; - } - - /** - * Return the current position. - * - * @return integer The current position. - */ - public function key() - { - return $this->position; - } - - /** - * Move to the next position. - * - * @return void - */ - public function next() - { - ++$this->position; - } - - /** - * Check whether there are more elements to iterate. - * - * @return bool True if there are more elements to iterate. - */ - public function valid() - { - return isset($this->container[$this->position]); - } -} - -/** * RepeatedField is used by generated protocol message classes to manipulate * repeated fields. It can be used like native PHP array. */ diff --git a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php new file mode 100644 index 00000000..2b6f8230 --- /dev/null +++ b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php @@ -0,0 +1,118 @@ +<?php + +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/** + * RepeatedField and RepeatedFieldIter are used by generated protocol message + * classes to manipulate repeated fields. + */ + +namespace Google\Protobuf\Internal; + +/** + * RepeatedFieldIter is used to iterate RepeatedField. It is also need for the + * foreach syntax. + */ +class RepeatedFieldIter implements \Iterator +{ + + /** + * @ignore + */ + private $position; + /** + * @ignore + */ + private $container; + + /** + * Create iterator instance for RepeatedField. + * + * @param RepeatedField The RepeatedField instance for which this iterator + * is created. + * @ignore + */ + public function __construct($container) + { + $this->position = 0; + $this->container = $container; + } + + /** + * Reset the status of the iterator + * + * @return void + */ + public function rewind() + { + $this->position = 0; + } + + /** + * Return the element at the current position. + * + * @return object The element at the current position. + */ + public function current() + { + return $this->container[$this->position]; + } + + /** + * Return the current position. + * + * @return integer The current position. + */ + public function key() + { + return $this->position; + } + + /** + * Move to the next position. + * + * @return void + */ + public function next() + { + ++$this->position; + } + + /** + * Check whether there are more elements to iterate. + * + * @return bool True if there are more elements to iterate. + */ + public function valid() + { + return isset($this->container[$this->position]); + } +} diff --git a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php index 47776202..da88e9c4 100644 --- a/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php +++ b/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php @@ -8,30 +8,27 @@ 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; /** - * <pre> * Describes a service. - * </pre> * - * Protobuf type <code>google.protobuf.ServiceDescriptorProto</code> + * Generated from protobuf message <code>google.protobuf.ServiceDescriptorProto</code> */ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message { /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> */ private $name = ''; private $has_name = false; /** - * <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code> */ private $method; private $has_method = false; /** - * <code>optional .google.protobuf.ServiceOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.ServiceOptions options = 3;</code> */ private $options = null; private $has_options = false; @@ -42,7 +39,8 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @return string */ public function getName() { @@ -50,13 +48,17 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional string name = 1;</code> + * Generated from protobuf field <code>optional string name = 1;</code> + * @param string $var + * @return $this */ public function setName($var) { GPBUtil::checkString($var, True); $this->name = $var; $this->has_name = true; + + return $this; } public function hasName() @@ -65,7 +67,8 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getMethod() { @@ -73,13 +76,17 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code> + * @param \Google\Protobuf\Internal\MethodDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setMethod(&$var) + public function setMethod($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class); $this->method = $arr; $this->has_method = true; + + return $this; } public function hasMethod() @@ -88,7 +95,8 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.ServiceOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.ServiceOptions options = 3;</code> + * @return \Google\Protobuf\Internal\ServiceOptions */ public function getOptions() { @@ -96,13 +104,17 @@ class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message } /** - * <code>optional .google.protobuf.ServiceOptions options = 3;</code> + * Generated from protobuf field <code>optional .google.protobuf.ServiceOptions options = 3;</code> + * @param \Google\Protobuf\Internal\ServiceOptions $var + * @return $this */ - public function setOptions(&$var) + public function setOptions($var) { GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class); $this->options = $var; $this->has_options = true; + + return $this; } public function hasOptions() diff --git a/php/src/Google/Protobuf/Internal/ServiceOptions.php b/php/src/Google/Protobuf/Internal/ServiceOptions.php index 62323dba..3e7214a1 100644 --- a/php/src/Google/Protobuf/Internal/ServiceOptions.php +++ b/php/src/Google/Protobuf/Internal/ServiceOptions.php @@ -8,32 +8,27 @@ 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; /** - * Protobuf type <code>google.protobuf.ServiceOptions</code> + * Generated from protobuf message <code>google.protobuf.ServiceOptions</code> */ class ServiceOptions extends \Google\Protobuf\Internal\Message { /** - * <pre> * Is this service deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the service, or it will be completely ignored; in the very least, * this is a formalization for deprecating services. - * </pre> * - * <code>optional bool deprecated = 33 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code> */ private $deprecated = false; private $has_deprecated = false; /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> */ private $uninterpreted_option; private $has_uninterpreted_option = false; @@ -44,14 +39,13 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this service deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the service, or it will be completely ignored; in the very least, * this is a formalization for deprecating services. - * </pre> * - * <code>optional bool deprecated = 33 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code> + * @return bool */ public function getDeprecated() { @@ -59,20 +53,22 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * Is this service deprecated? * Depending on the target platform, this can emit Deprecated annotations * for the service, or it will be completely ignored; in the very least, * this is a formalization for deprecating services. - * </pre> * - * <code>optional bool deprecated = 33 [default = false];</code> + * Generated from protobuf field <code>optional bool deprecated = 33 [default = false];</code> + * @param bool $var + * @return $this */ public function setDeprecated($var) { GPBUtil::checkBool($var); $this->deprecated = $var; $this->has_deprecated = true; + + return $this; } public function hasDeprecated() @@ -81,11 +77,10 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getUninterpretedOption() { @@ -93,17 +88,19 @@ class ServiceOptions extends \Google\Protobuf\Internal\Message } /** - * <pre> * The parser stores options it doesn't recognize here. See above. - * </pre> * - * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setUninterpretedOption(&$var) + public function setUninterpretedOption($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class); $this->uninterpreted_option = $arr; $this->has_uninterpreted_option = true; + + return $this; } public function hasUninterpretedOption() diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php index eab60880..6ce05ed4 100644 --- a/php/src/Google/Protobuf/Internal/SourceCodeInfo.php +++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo.php @@ -8,21 +8,17 @@ 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; /** - * <pre> * Encapsulates information about the original source file from which a * FileDescriptorProto was generated. - * </pre> * - * Protobuf type <code>google.protobuf.SourceCodeInfo</code> + * Generated from protobuf message <code>google.protobuf.SourceCodeInfo</code> */ class SourceCodeInfo extends \Google\Protobuf\Internal\Message { /** - * <pre> * A Location identifies a piece of source code in a .proto file which * corresponds to a particular definition. This information is intended * to be useful to IDEs, code indexers, documentation generators, and similar @@ -64,9 +60,8 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message * - Code which tries to interpret locations should probably be designed to * ignore those that it doesn't understand, as more types of locations could * be recorded in the future. - * </pre> * - * <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code> */ private $location; private $has_location = false; @@ -77,7 +72,6 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message } /** - * <pre> * A Location identifies a piece of source code in a .proto file which * corresponds to a particular definition. This information is intended * to be useful to IDEs, code indexers, documentation generators, and similar @@ -119,9 +113,9 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message * - Code which tries to interpret locations should probably be designed to * ignore those that it doesn't understand, as more types of locations could * be recorded in the future. - * </pre> * - * <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getLocation() { @@ -129,7 +123,6 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message } /** - * <pre> * A Location identifies a piece of source code in a .proto file which * corresponds to a particular definition. This information is intended * to be useful to IDEs, code indexers, documentation generators, and similar @@ -171,15 +164,18 @@ class SourceCodeInfo extends \Google\Protobuf\Internal\Message * - Code which tries to interpret locations should probably be designed to * ignore those that it doesn't understand, as more types of locations could * be recorded in the future. - * </pre> * - * <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code> + * Generated from protobuf field <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code> + * @param \Google\Protobuf\Internal\SourceCodeInfo_Location[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setLocation(&$var) + public function setLocation($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo_Location::class); $this->location = $arr; $this->has_location = true; + + return $this; } public function hasLocation() diff --git a/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php b/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php index 5a02b26c..19ed2bc2 100644 --- a/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php +++ b/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php @@ -8,16 +8,14 @@ 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; /** - * Protobuf type <code>google.protobuf.SourceCodeInfo.Location</code> + * Generated from protobuf message <code>google.protobuf.SourceCodeInfo.Location</code> */ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message { /** - * <pre> * Identifies which part of the FileDescriptorProto was defined at this * location. * Each element is a field number or an index. They form a path from @@ -39,27 +37,23 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * [ 4, 3, 2, 7 ] * this path refers to the whole field declaration (from the beginning * of the label to the terminating semicolon). - * </pre> * - * <code>repeated int32 path = 1 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code> */ private $path; private $has_path = false; /** - * <pre> * Always has exactly three or four elements: start line, start column, * end line (optional, otherwise assumed same as start line), end column. * These are packed into a single field for efficiency. Note that line * and column numbers are zero-based -- typically you will want to add * 1 to each before displaying to a user. - * </pre> * - * <code>repeated int32 span = 2 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 span = 2 [packed = true];</code> */ private $span; private $has_span = false; /** - * <pre> * If this SourceCodeInfo represents a complete declaration, these are any * comments appearing before and after the declaration which appear to be * attached to the declaration. @@ -96,19 +90,18 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * * grault. */ * optional int32 grault = 6; * // ignored detached comments. - * </pre> * - * <code>optional string leading_comments = 3;</code> + * Generated from protobuf field <code>optional string leading_comments = 3;</code> */ private $leading_comments = ''; private $has_leading_comments = false; /** - * <code>optional string trailing_comments = 4;</code> + * Generated from protobuf field <code>optional string trailing_comments = 4;</code> */ private $trailing_comments = ''; private $has_trailing_comments = false; /** - * <code>repeated string leading_detached_comments = 6;</code> + * Generated from protobuf field <code>repeated string leading_detached_comments = 6;</code> */ private $leading_detached_comments; private $has_leading_detached_comments = false; @@ -119,7 +112,6 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies which part of the FileDescriptorProto was defined at this * location. * Each element is a field number or an index. They form a path from @@ -141,9 +133,9 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * [ 4, 3, 2, 7 ] * this path refers to the whole field declaration (from the beginning * of the label to the terminating semicolon). - * </pre> * - * <code>repeated int32 path = 1 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getPath() { @@ -151,7 +143,6 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <pre> * Identifies which part of the FileDescriptorProto was defined at this * location. * Each element is a field number or an index. They form a path from @@ -173,15 +164,18 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * [ 4, 3, 2, 7 ] * this path refers to the whole field declaration (from the beginning * of the label to the terminating semicolon). - * </pre> * - * <code>repeated int32 path = 1 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code> + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setPath(&$var) + public function setPath($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->path = $arr; $this->has_path = true; + + return $this; } public function hasPath() @@ -190,15 +184,14 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <pre> * Always has exactly three or four elements: start line, start column, * end line (optional, otherwise assumed same as start line), end column. * These are packed into a single field for efficiency. Note that line * and column numbers are zero-based -- typically you will want to add * 1 to each before displaying to a user. - * </pre> * - * <code>repeated int32 span = 2 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 span = 2 [packed = true];</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getSpan() { @@ -206,21 +199,23 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <pre> * Always has exactly three or four elements: start line, start column, * end line (optional, otherwise assumed same as start line), end column. * These are packed into a single field for efficiency. Note that line * and column numbers are zero-based -- typically you will want to add * 1 to each before displaying to a user. - * </pre> * - * <code>repeated int32 span = 2 [packed = true];</code> + * Generated from protobuf field <code>repeated int32 span = 2 [packed = true];</code> + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setSpan(&$var) + public function setSpan($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); $this->span = $arr; $this->has_span = true; + + return $this; } public function hasSpan() @@ -229,7 +224,6 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <pre> * If this SourceCodeInfo represents a complete declaration, these are any * comments appearing before and after the declaration which appear to be * attached to the declaration. @@ -266,9 +260,9 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * * grault. */ * optional int32 grault = 6; * // ignored detached comments. - * </pre> * - * <code>optional string leading_comments = 3;</code> + * Generated from protobuf field <code>optional string leading_comments = 3;</code> + * @return string */ public function getLeadingComments() { @@ -276,7 +270,6 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <pre> * If this SourceCodeInfo represents a complete declaration, these are any * comments appearing before and after the declaration which appear to be * attached to the declaration. @@ -313,15 +306,18 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message * * grault. */ * optional int32 grault = 6; * // ignored detached comments. - * </pre> * - * <code>optional string leading_comments = 3;</code> + * Generated from protobuf field <code>optional string leading_comments = 3;</code> + * @param string $var + * @return $this */ public function setLeadingComments($var) { GPBUtil::checkString($var, True); $this->leading_comments = $var; $this->has_leading_comments = true; + + return $this; } public function hasLeadingComments() @@ -330,7 +326,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <code>optional string trailing_comments = 4;</code> + * Generated from protobuf field <code>optional string trailing_comments = 4;</code> + * @return string */ public function getTrailingComments() { @@ -338,13 +335,17 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <code>optional string trailing_comments = 4;</code> + * Generated from protobuf field <code>optional string trailing_comments = 4;</code> + * @param string $var + * @return $this */ public function setTrailingComments($var) { GPBUtil::checkString($var, True); $this->trailing_comments = $var; $this->has_trailing_comments = true; + + return $this; } public function hasTrailingComments() @@ -353,7 +354,8 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <code>repeated string leading_detached_comments = 6;</code> + * Generated from protobuf field <code>repeated string leading_detached_comments = 6;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getLeadingDetachedComments() { @@ -361,13 +363,17 @@ class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message } /** - * <code>repeated string leading_detached_comments = 6;</code> + * Generated from protobuf field <code>repeated string leading_detached_comments = 6;</code> + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setLeadingDetachedComments(&$var) + public function setLeadingDetachedComments($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); $this->leading_detached_comments = $arr; $this->has_leading_detached_comments = true; + + return $this; } public function hasLeadingDetachedComments() diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption.php b/php/src/Google/Protobuf/Internal/UninterpretedOption.php index 28655019..4d342eb3 100644 --- a/php/src/Google/Protobuf/Internal/UninterpretedOption.php +++ b/php/src/Google/Protobuf/Internal/UninterpretedOption.php @@ -8,60 +8,55 @@ 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; /** - * <pre> * A message representing a option the parser does not recognize. This only * appears in options protos created by the compiler::Parser class. * DescriptorPool resolves these when building Descriptor objects. Therefore, * options protos in descriptor objects (e.g. returned by Descriptor::options(), * or produced by Descriptor::CopyTo()) will never have UninterpretedOptions * in them. - * </pre> * - * Protobuf type <code>google.protobuf.UninterpretedOption</code> + * Generated from protobuf message <code>google.protobuf.UninterpretedOption</code> */ class UninterpretedOption extends \Google\Protobuf\Internal\Message { /** - * <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code> */ private $name; private $has_name = false; /** - * <pre> * The value of the uninterpreted option, in whatever type the tokenizer * identified it as during parsing. Exactly one of these should be set. - * </pre> * - * <code>optional string identifier_value = 3;</code> + * Generated from protobuf field <code>optional string identifier_value = 3;</code> */ private $identifier_value = ''; private $has_identifier_value = false; /** - * <code>optional uint64 positive_int_value = 4;</code> + * Generated from protobuf field <code>optional uint64 positive_int_value = 4;</code> */ private $positive_int_value = 0; private $has_positive_int_value = false; /** - * <code>optional int64 negative_int_value = 5;</code> + * Generated from protobuf field <code>optional int64 negative_int_value = 5;</code> */ private $negative_int_value = 0; private $has_negative_int_value = false; /** - * <code>optional double double_value = 6;</code> + * Generated from protobuf field <code>optional double double_value = 6;</code> */ private $double_value = 0.0; private $has_double_value = false; /** - * <code>optional bytes string_value = 7;</code> + * Generated from protobuf field <code>optional bytes string_value = 7;</code> */ private $string_value = ''; private $has_string_value = false; /** - * <code>optional string aggregate_value = 8;</code> + * Generated from protobuf field <code>optional string aggregate_value = 8;</code> */ private $aggregate_value = ''; private $has_aggregate_value = false; @@ -72,7 +67,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code> + * @return \Google\Protobuf\Internal\RepeatedField */ public function getName() { @@ -80,13 +76,17 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code> + * Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code> + * @param \Google\Protobuf\Internal\UninterpretedOption_NamePart[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this */ - public function setName(&$var) + public function setName($var) { $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class); $this->name = $arr; $this->has_name = true; + + return $this; } public function hasName() @@ -95,12 +95,11 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <pre> * The value of the uninterpreted option, in whatever type the tokenizer * identified it as during parsing. Exactly one of these should be set. - * </pre> * - * <code>optional string identifier_value = 3;</code> + * Generated from protobuf field <code>optional string identifier_value = 3;</code> + * @return string */ public function getIdentifierValue() { @@ -108,18 +107,20 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <pre> * The value of the uninterpreted option, in whatever type the tokenizer * identified it as during parsing. Exactly one of these should be set. - * </pre> * - * <code>optional string identifier_value = 3;</code> + * Generated from protobuf field <code>optional string identifier_value = 3;</code> + * @param string $var + * @return $this */ public function setIdentifierValue($var) { GPBUtil::checkString($var, True); $this->identifier_value = $var; $this->has_identifier_value = true; + + return $this; } public function hasIdentifierValue() @@ -128,7 +129,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional uint64 positive_int_value = 4;</code> + * Generated from protobuf field <code>optional uint64 positive_int_value = 4;</code> + * @return int|string */ public function getPositiveIntValue() { @@ -136,13 +138,17 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional uint64 positive_int_value = 4;</code> + * Generated from protobuf field <code>optional uint64 positive_int_value = 4;</code> + * @param int|string $var + * @return $this */ public function setPositiveIntValue($var) { GPBUtil::checkUint64($var); $this->positive_int_value = $var; $this->has_positive_int_value = true; + + return $this; } public function hasPositiveIntValue() @@ -151,7 +157,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional int64 negative_int_value = 5;</code> + * Generated from protobuf field <code>optional int64 negative_int_value = 5;</code> + * @return int|string */ public function getNegativeIntValue() { @@ -159,13 +166,17 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional int64 negative_int_value = 5;</code> + * Generated from protobuf field <code>optional int64 negative_int_value = 5;</code> + * @param int|string $var + * @return $this */ public function setNegativeIntValue($var) { GPBUtil::checkInt64($var); $this->negative_int_value = $var; $this->has_negative_int_value = true; + + return $this; } public function hasNegativeIntValue() @@ -174,7 +185,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional double double_value = 6;</code> + * Generated from protobuf field <code>optional double double_value = 6;</code> + * @return float */ public function getDoubleValue() { @@ -182,13 +194,17 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional double double_value = 6;</code> + * Generated from protobuf field <code>optional double double_value = 6;</code> + * @param float $var + * @return $this */ public function setDoubleValue($var) { GPBUtil::checkDouble($var); $this->double_value = $var; $this->has_double_value = true; + + return $this; } public function hasDoubleValue() @@ -197,7 +213,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional bytes string_value = 7;</code> + * Generated from protobuf field <code>optional bytes string_value = 7;</code> + * @return string */ public function getStringValue() { @@ -205,13 +222,17 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional bytes string_value = 7;</code> + * Generated from protobuf field <code>optional bytes string_value = 7;</code> + * @param string $var + * @return $this */ public function setStringValue($var) { GPBUtil::checkString($var, False); $this->string_value = $var; $this->has_string_value = true; + + return $this; } public function hasStringValue() @@ -220,7 +241,8 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional string aggregate_value = 8;</code> + * Generated from protobuf field <code>optional string aggregate_value = 8;</code> + * @return string */ public function getAggregateValue() { @@ -228,13 +250,17 @@ class UninterpretedOption extends \Google\Protobuf\Internal\Message } /** - * <code>optional string aggregate_value = 8;</code> + * Generated from protobuf field <code>optional string aggregate_value = 8;</code> + * @param string $var + * @return $this */ public function setAggregateValue($var) { GPBUtil::checkString($var, True); $this->aggregate_value = $var; $this->has_aggregate_value = true; + + return $this; } public function hasAggregateValue() diff --git a/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php b/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php index 86484d23..c9a6fc3c 100644 --- a/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php +++ b/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php @@ -8,29 +8,26 @@ 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; /** - * <pre> * The name of the uninterpreted option. Each string represents a segment in * a dot-separated name. is_extension is true iff a segment represents an * extension (denoted with parentheses in options specs in .proto files). * E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents * "foo.(bar.baz).qux". - * </pre> * - * Protobuf type <code>google.protobuf.UninterpretedOption.NamePart</code> + * Generated from protobuf message <code>google.protobuf.UninterpretedOption.NamePart</code> */ class UninterpretedOption_NamePart extends \Google\Protobuf\Internal\Message { /** - * <code>required string name_part = 1;</code> + * Generated from protobuf field <code>required string name_part = 1;</code> */ private $name_part = ''; private $has_name_part = false; /** - * <code>required bool is_extension = 2;</code> + * Generated from protobuf field <code>required bool is_extension = 2;</code> */ private $is_extension = false; private $has_is_extension = false; @@ -41,7 +38,8 @@ class UninterpretedOption_NamePart extends \Google\Protobuf\Internal\Message } /** - * <code>required string name_part = 1;</code> + * Generated from protobuf field <code>required string name_part = 1;</code> + * @return string */ public function getNamePart() { @@ -49,13 +47,17 @@ class UninterpretedOption_NamePart extends \Google\Protobuf\Internal\Message } /** - * <code>required string name_part = 1;</code> + * Generated from protobuf field <code>required string name_part = 1;</code> + * @param string $var + * @return $this */ public function setNamePart($var) { GPBUtil::checkString($var, True); $this->name_part = $var; $this->has_name_part = true; + + return $this; } public function hasNamePart() @@ -64,7 +66,8 @@ class UninterpretedOption_NamePart extends \Google\Protobuf\Internal\Message } /** - * <code>required bool is_extension = 2;</code> + * Generated from protobuf field <code>required bool is_extension = 2;</code> + * @return bool */ public function getIsExtension() { @@ -72,13 +75,17 @@ class UninterpretedOption_NamePart extends \Google\Protobuf\Internal\Message } /** - * <code>required bool is_extension = 2;</code> + * Generated from protobuf field <code>required bool is_extension = 2;</code> + * @param bool $var + * @return $this */ public function setIsExtension($var) { GPBUtil::checkBool($var); $this->is_extension = $var; $this->has_is_extension = true; + + return $this; } public function hasIsExtension() diff --git a/php/src/Google/Protobuf/descriptor.php b/php/src/Google/Protobuf/descriptor.php deleted file mode 100644 index fb69eda0..00000000 --- a/php/src/Google/Protobuf/descriptor.php +++ /dev/null @@ -1,587 +0,0 @@ -<?php - -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -namespace Google\Protobuf\Internal; - -use Google\Protobuf\Internal\GPBType; -use Google\Protobuf\Internal\MessageOptions; - -class FileDescriptor -{ - - private $package; - private $message_type = []; - private $enum_type = []; - - public function setPackage($package) - { - $this->package = $package; - } - - public function getPackage() - { - return $this->package; - } - - public function getMessageType() - { - return $this->message_type; - } - - public function addMessageType($desc) - { - $this->message_type[] = $desc; - } - - public function getEnumType() - { - return $this->enum_type; - } - - public function addEnumType($desc) - { - $this->enum_type[]= $desc; - } - - public static function buildFromProto($proto) - { - $file = new FileDescriptor(); - $file->setPackage($proto->getPackage()); - foreach ($proto->getMessageType() as $message_proto) { - $file->addMessageType(Descriptor::buildFromProto( - $message_proto, $proto, "")); - } - foreach ($proto->getEnumType() as $enum_proto) { - $file->getEnumType()[] = - $file->addEnumType( - EnumDescriptor::buildFromProto( - $enum_proto, - $proto, - "")); - } - return $file; - } -} - -class Descriptor -{ - - private $full_name; - private $field = []; - private $nested_type = []; - private $enum_type = []; - private $klass; - private $options; - private $oneof_decl = []; - - public function addOneofDecl($oneof) - { - $this->oneof_decl[] = $oneof; - } - - public function getOneofDecl() - { - return $this->oneof_decl; - } - - public function setFullName($full_name) - { - $this->full_name = $full_name; - } - - public function getFullName() - { - return $this->full_name; - } - - public function addField($field) - { - $this->field[$field->getNumber()] = $field; - } - - public function getField() - { - return $this->field; - } - - public function addNestedType($desc) - { - $this->nested_type[] = $desc; - } - - public function getNestedType() - { - return $this->nested_type; - } - - public function addEnumType($desc) - { - $this->enum_type[] = $desc; - } - - public function getEnumType() - { - return $this->enum_type; - } - - public function getFieldByNumber($number) - { - if (!isset($this->field[$number])) { - return NULL; - } else { - return $this->field[$number]; - } - } - - public function setClass($klass) - { - $this->klass = $klass; - } - - public function getClass() - { - return $this->klass; - } - - public function setOptions($options) - { - $this->options = $options; - } - - public function getOptions() - { - return $this->options; - } - - public static function buildFromProto($proto, $file_proto, $containing) - { - $desc = new Descriptor(); - - $message_name_without_package = ""; - $classname = ""; - $fullname = ""; - getFullClassName( - $proto, - $containing, - $file_proto, - $message_name_without_package, - $classname, - $fullname); - $desc->setFullName($fullname); - $desc->setClass($classname); - $desc->setOptions($proto->getOptions()); - - foreach ($proto->getField() as $field_proto) { - $desc->addField(FieldDescriptor::buildFromProto($field_proto)); - } - - // Handle nested types. - foreach ($proto->getNestedType() as $nested_proto) { - $desc->addNestedType(Descriptor::buildFromProto( - $nested_proto, $file_proto, $message_name_without_package)); - } - - // Handle nested enum. - foreach ($proto->getEnumType() as $enum_proto) { - $desc->addEnumType(EnumDescriptor::buildFromProto( - $enum_proto, $file_proto, $message_name_without_package)); - } - - // Handle oneof fields. - foreach ($proto->getOneofDecl() as $oneof_proto) { - $desc->addOneofDecl( - OneofDescriptor::buildFromProto($oneof_proto, $desc)); - } - - return $desc; - } -} - -function getClassNamePrefix( - $classname, - $file_proto) -{ - $option = $file_proto->getOptions(); - $prefix = is_null($option) ? "" : $option->getPhpClassPrefix(); - if ($prefix !== "") { - return $prefix; - } - - $reserved_words = array("Empty"); - foreach ($reserved_words as $reserved_word) { - if ($classname === $reserved_word) { - if ($file_proto->getPackage() === "google.protobuf") { - return "GPB"; - } else { - return "PB"; - } - } - } - - return ""; -} - -function getClassNameWithoutPackage( - $name, - $file_proto) -{ - $classname = implode('_', array_map('ucwords', explode('.', $name))); - return getClassNamePrefix($classname, $file_proto) . $classname; -} - -function getFullClassName( - $proto, - $containing, - $file_proto, - &$message_name_without_package, - &$classname, - &$fullname) -{ - // Full name needs to start with '.'. - $message_name_without_package = $proto->getName(); - if ($containing !== "") { - $message_name_without_package = - $containing . "." . $message_name_without_package; - } - - $package = $file_proto->getPackage(); - if ($package === "") { - $fullname = "." . $message_name_without_package; - } else { - $fullname = "." . $package . "." . $message_name_without_package; - } - - $class_name_without_package = - getClassNameWithoutPackage($message_name_without_package, $file_proto); - if ($package === "") { - $classname = $class_name_without_package; - } else { - $classname = - implode('\\', array_map('ucwords', explode('.', $package))). - "\\".$class_name_without_package; - } -} - -class OneofDescriptor -{ - - private $name; - private $fields; - - public function setName($name) - { - $this->name = $name; - } - - public function getName() - { - return $this->name; - } - - public function addField(&$field) - { - $this->fields[] = $field; - } - - public function getFields() - { - return $this->fields; - } - - public static function buildFromProto($oneof_proto) - { - $oneof = new OneofDescriptor(); - $oneof->setName($oneof_proto->getName()); - return $oneof; - } -} - - -class EnumDescriptor -{ - - private $klass; - private $full_name; - private $value; - - public function setFullName($full_name) - { - $this->full_name = $full_name; - } - - public function getFullName() - { - return $this->full_name; - } - - public function addValue($number, $value) - { - $this->value[$number] = $value; - } - - public function setClass($klass) - { - $this->klass = $klass; - } - - public function getClass() - { - return $this->klass; - } - - public static function buildFromProto($proto, $file_proto, $containing) - { - $desc = new EnumDescriptor(); - - $enum_name_without_package = ""; - $classname = ""; - $fullname = ""; - getFullClassName( - $proto, - $containing, - $file_proto, - $enum_name_without_package, - $classname, - $fullname); - $desc->setFullName($fullname); - $desc->setClass($classname); - - return $desc; - } -} - -class EnumValueDescriptor -{ -} - -class FieldDescriptor -{ - - private $name; - private $setter; - private $getter; - private $number; - private $label; - private $type; - private $message_type; - private $enum_type; - private $packed; - private $is_map; - private $oneof_index = -1; - - public function setOneofIndex($index) - { - $this->oneof_index = $index; - } - - public function getOneofIndex() - { - return $this->oneof_index; - } - - public function setName($name) - { - $this->name = $name; - } - - public function getName() - { - return $this->name; - } - - public function setSetter($setter) - { - $this->setter = $setter; - } - - public function getSetter() - { - return $this->setter; - } - - public function setGetter($getter) - { - $this->getter = $getter; - } - - public function getGetter() - { - return $this->getter; - } - - public function setNumber($number) - { - $this->number = $number; - } - - public function getNumber() - { - return $this->number; - } - - public function setLabel($label) - { - $this->label = $label; - } - - public function getLabel() - { - return $this->label; - } - - public function isRepeated() - { - return $this->label === GPBLabel::REPEATED; - } - - public function setType($type) - { - $this->type = $type; - } - - public function getType() - { - return $this->type; - } - - public function setMessageType($message_type) - { - $this->message_type = $message_type; - } - - public function getMessageType() - { - return $this->message_type; - } - - public function setEnumType($enum_type) - { - $this->enum_type = $enum_type; - } - - public function getEnumType() - { - return $this->enum_type; - } - - public function setPacked($packed) - { - $this->packed = $packed; - } - - public function getPacked() - { - return $this->packed; - } - - public function isPackable() - { - return $this->isRepeated() && self::isTypePackable($this->type); - } - - public function isMap() - { - return $this->getType() == GPBType::MESSAGE && - !is_null($this->getMessageType()->getOptions()) && - $this->getMessageType()->getOptions()->getMapEntry(); - } - - private static function isTypePackable($field_type) - { - return ($field_type !== GPBType::STRING && - $field_type !== GPBType::GROUP && - $field_type !== GPBType::MESSAGE && - $field_type !== GPBType::BYTES); - } - - public static function getFieldDescriptor( - $name, - $label, - $type, - $number, - $oneof_index, - $packed, - $type_name = null) - { - $field = new FieldDescriptor(); - $field->setName($name); - $camel_name = implode('', array_map('ucwords', explode('_', $name))); - $field->setGetter('get' . $camel_name); - $field->setSetter('set' . $camel_name); - $field->setType($type); - $field->setNumber($number); - $field->setLabel($label); - $field->setPacked($packed); - $field->setOneofIndex($oneof_index); - - // At this time, the message/enum type may have not been added to pool. - // So we use the type name as place holder and will replace it with the - // actual descriptor in cross building. - switch ($type) { - case GPBType::MESSAGE: - $field->setMessageType($type_name); - break; - case GPBType::ENUM: - $field->setEnumType($type_name); - break; - default: - break; - } - - return $field; - } - - public static function buildFromProto($proto) - { - $type_name = null; - switch ($proto->getType()) { - case GPBType::MESSAGE: - case GPBType::GROUP: - case GPBType::ENUM: - $type_name = $proto->getTypeName(); - break; - default: - break; - } - - $oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1; - $packed = false; - $options = $proto->getOptions(); - if ($options !== null) { - $packed = $options->getPacked(); - } - - return FieldDescriptor::getFieldDescriptor( - $proto->getName(), $proto->getLabel(), $proto->getType(), - $proto->getNumber(), $oneof_index, $packed, $type_name); - } -} |