diff options
author | Bo Yang <paulyang1211@gmail.com> | 2017-08-05 10:42:29 -0700 |
---|---|---|
committer | Bo Yang <paulyang1211@gmail.com> | 2017-08-05 10:42:29 -0700 |
commit | 8f4b8e430a0cf087af423be434cf8d837027c651 (patch) | |
tree | a7a79a2ff33b31b9036eb378eb458928a0648481 /php/src/Google/Protobuf/Internal/Descriptor.php | |
parent | c2f69d6fa23a815948368fae0b8c1e56e50715c9 (diff) | |
parent | f14703c933d04a4aac285c482bf828269bd0a151 (diff) | |
download | protobuf-8f4b8e430a0cf087af423be434cf8d837027c651.tar.gz protobuf-8f4b8e430a0cf087af423be434cf8d837027c651.tar.bz2 protobuf-8f4b8e430a0cf087af423be434cf8d837027c651.zip |
Merge branch 'master' into 3.4.x
Diffstat (limited to 'php/src/Google/Protobuf/Internal/Descriptor.php')
-rw-r--r-- | php/src/Google/Protobuf/Internal/Descriptor.php | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/php/src/Google/Protobuf/Internal/Descriptor.php b/php/src/Google/Protobuf/Internal/Descriptor.php index 44225ad2..ee3a8bde 100644 --- a/php/src/Google/Protobuf/Internal/Descriptor.php +++ b/php/src/Google/Protobuf/Internal/Descriptor.php @@ -34,17 +34,24 @@ namespace Google\Protobuf\Internal; class Descriptor { + use HasPublicDescriptorTrait; private $full_name; private $field = []; private $json_to_field = []; private $name_to_field = []; + private $index_to_field = []; private $nested_type = []; private $enum_type = []; private $klass; private $options; private $oneof_decl = []; + public function __construct() + { + $this->public_desc = new \Google\Protobuf\Descriptor($this); + } + public function addOneofDecl($oneof) { $this->oneof_decl[] = $oneof; @@ -70,6 +77,7 @@ class Descriptor $this->field[$field->getNumber()] = $field; $this->json_to_field[$field->getJsonName()] = $field; $this->name_to_field[$field->getName()] = $field; + $this->index_to_field[] = $field; } public function getField() @@ -124,6 +132,15 @@ class Descriptor } } + public function getFieldByIndex($index) + { + if (count($this->index_to_field) <= $index) { + return NULL; + } else { + return $this->index_to_field[$index]; + } + } + public function setClass($klass) { $this->klass = $klass; @@ -179,9 +196,11 @@ class Descriptor } // Handle oneof fields. + $index = 0; foreach ($proto->getOneofDecl() as $oneof_proto) { $desc->addOneofDecl( - OneofDescriptor::buildFromProto($oneof_proto, $desc)); + OneofDescriptor::buildFromProto($oneof_proto, $desc, $index)); + $index++; } return $desc; |