diff --git a/php/src/Google/Protobuf/FieldDescriptor.php b/php/src/Google/Protobuf/FieldDescriptor.php index 6d08cea9da..128f0f08bd 100644 --- a/php/src/Google/Protobuf/FieldDescriptor.php +++ b/php/src/Google/Protobuf/FieldDescriptor.php @@ -39,6 +39,7 @@ class FieldDescriptor { use GetPublicDescriptorTrait; + /** @var \Google\Protobuf\Internal\FieldDescriptor $internal_desc */ private $internal_desc; /** @@ -81,6 +82,22 @@ class FieldDescriptor return $this->internal_desc->getType(); } + /** + * @return int + */ + public function getOneofIndex() + { + return $this->internal_desc->getOneofIndex(); + } + + /** + * @return boolean + */ + public function getProto3Optional() + { + return $this->internal_desc->getProto3Optional(); + } + /** * @return Descriptor Returns a descriptor for the field type if the field type is a message, otherwise throws \Exception * @throws \Exception @@ -114,12 +131,4 @@ class FieldDescriptor { return $this->internal_desc->isMap(); } - - /** - * @return boolean - */ - public function hasOptionalKeyword() - { - return $this->internal_desc->hasOptionalKeyword(); - } } diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptor.php b/php/src/Google/Protobuf/Internal/FieldDescriptor.php index ce83f63a2b..368797b340 100644 --- a/php/src/Google/Protobuf/Internal/FieldDescriptor.php +++ b/php/src/Google/Protobuf/Internal/FieldDescriptor.php @@ -46,8 +46,8 @@ class FieldDescriptor private $message_type; private $enum_type; private $packed; - private $is_map; private $oneof_index = -1; + private $proto3_optional; public function __construct() { @@ -169,6 +169,16 @@ class FieldDescriptor return $this->packed; } + public function getProto3Optional() + { + return $this->proto3_optional; + } + + public function setProto3Optional($proto3_optional) + { + $this->proto3_optional = $proto3_optional; + } + public function isPackable() { return $this->isRepeated() && self::isTypePackable($this->type); @@ -214,6 +224,10 @@ class FieldDescriptor $field_type !== GPBType::BYTES); } + /** + * @param FieldDescriptorProto $proto + * @return FieldDescriptor + */ public static function getFieldDescriptor($proto) { $type_name = null; @@ -269,6 +283,7 @@ class FieldDescriptor $field->setLabel($proto->getLabel()); $field->setPacked($packed); $field->setOneofIndex($oneof_index); + $field->setProto3Optional($proto->getProto3Optional()); // 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 diff --git a/php/src/Google/Protobuf/Internal/OneofDescriptor.php b/php/src/Google/Protobuf/Internal/OneofDescriptor.php index 67b107f6a4..e685b26701 100644 --- a/php/src/Google/Protobuf/Internal/OneofDescriptor.php +++ b/php/src/Google/Protobuf/Internal/OneofDescriptor.php @@ -37,6 +37,7 @@ class OneofDescriptor use HasPublicDescriptorTrait; private $name; + /** @var \Google\Protobuf\FieldDescriptor[] $fields */ private $fields; public function __construct() @@ -64,6 +65,11 @@ class OneofDescriptor return $this->fields; } + public function isSynthetic() + { + return count($this->fields) === 1 && $this->fields[0]->getProto3Optional(); + } + public static function buildFromProto($oneof_proto, $desc, $index) { $oneof = new OneofDescriptor(); diff --git a/php/src/Google/Protobuf/OneofDescriptor.php b/php/src/Google/Protobuf/OneofDescriptor.php index 92b4e279da..9717da8a77 100644 --- a/php/src/Google/Protobuf/OneofDescriptor.php +++ b/php/src/Google/Protobuf/OneofDescriptor.php @@ -38,6 +38,7 @@ class OneofDescriptor { use GetPublicDescriptorTrait; + /** @var \Google\Protobuf\Internal\OneofDescriptor $internal_desc */ private $internal_desc; /** @@ -75,6 +76,6 @@ class OneofDescriptor public function isSynthetic() { - return $this->internal_desc->isSynthetic(); + return $this->internal_desc->isSynthetic(); } }