Example #1
0
 public function internalAddGeneratedFile($data)
 {
     $files = new FileDescriptorSet();
     $files->decode($data);
     $file = FileDescriptor::buildFromProto($files->getFile()[0]);
     foreach ($file->getMessageType() as &$desc) {
         $this->addDescriptor($desc);
     }
     unset($desc);
     foreach ($file->getEnumType() as &$desc) {
         $this->addEnumDescriptor($desc);
     }
     unset($desc);
     foreach ($file->getMessageType() as &$desc) {
         $this->crossLink($desc);
     }
     unset($desc);
 }
 public function testDescriptorDecode()
 {
     $file_desc_set = new FileDescriptorSet();
     $file_desc_set->decode(hex2bin("0a3b0a12746573745f696e636c7564652e70726f746f120362617222180a" . "0b54657374496e636c75646512090a0161180120012805620670726f746f33"));
     $this->assertSame(1, sizeof($file_desc_set->getFile()));
     $file_desc = $file_desc_set->getFile()[0];
     $this->assertSame("test_include.proto", $file_desc->getName());
     $this->assertSame("bar", $file_desc->getPackage());
     $this->assertSame(0, sizeof($file_desc->getDependency()));
     $this->assertSame(1, sizeof($file_desc->getMessageType()));
     $this->assertSame(0, sizeof($file_desc->getEnumType()));
     $this->assertSame("proto3", $file_desc->getSyntax());
     $desc = $file_desc->getMessageType()[0];
     $this->assertSame("TestInclude", $desc->getName());
     $this->assertSame(1, sizeof($desc->getField()));
     $this->assertSame(0, sizeof($desc->getNestedType()));
     $this->assertSame(0, sizeof($desc->getEnumType()));
     $this->assertSame(0, sizeof($desc->getOneofDecl()));
     $field = $desc->getField()[0];
     $this->assertSame("a", $field->getName());
     $this->assertSame(1, $field->getNumber());
     $this->assertSame(GPBLabel::OPTIONAL, $field->getLabel());
     $this->assertSame(GPBType::INT32, $field->getType());
 }