Exposed more functions in FieldDescriptor and OneofDescriptor.
This commit is contained in:
parent
67f46d2495
commit
b27dd18676
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user