Trying to construct generated PHP class causes InvalidArgumentException with a message about the class not being found in Descriptor Pool

381 views
Skip to first unread message

Jakob Merrild

unread,
Mar 28, 2022, 6:58:28 AM3/28/22
to Protocol Buffers
I'm trying to use the google/protobuf package for php, but am running into an issue that I don't understand. When trying to construct an instance of the generated class I'm met with the following exception

InvalidArgumentException: Famly\Queue\Model\Proto\ExportRequest is not found in descriptor pool. Only generated classes may derive from Message.

I have added the following to `composer.json`

```
"require":  {
       ...,
        "google/protobuf": "^3.19"
}.
"psr-0": {
     "Famly\\Queue": "Packages/Application/Famly/Queue"
}
````

I'm using `protoc` version 3.19.4 and generated the the files with 
protoc --proto_path="famlyqueue/src/main/protobuf" --php_out="core/Packages/Application/Famly.Queue/Classes" famlyqueue/src/main/protobuf/co/famly/export/ExportRequest.proto

Here's the `proto` file

```
syntax = "proto3";

package co.famly.export.proto;
option php_namespace = "Famly/Queue/Model/Proto";
option php_metadata_namespace = "Famly/Queue/Model/Proto/Meta";

message ExportRequest {
    // The ID of the entity to export
    string entityId = 1;
    // The type of the entity to export
    ExportEntityType entityType = 2;
}

enum ExportEntityType {
    BILL_PAYER = 0;
    BILL_PAYER_INVOICES = 1;
    CHILD = 2;
    LOGIN = 3;
    LOGIN_POST_MEDIA = 4;
    SITE = 5;
    SITE_MEDIA = 6;
}
```

And the test where I'm trying to construct the class instance (simply roundtrip test)
```
<?php
namespace Famly\Queue\Model\Proto;

use Neos\Flow\Tests\UnitTestCase;
use Neos\Flow\Utility\Algorithms;

class ExportRequestTest extends UnitTestCase {
/**
* @test
*/
public function canRoundtripSerialization() {
$from = new ExportRequest();
$entityId = Algorithms::generateUUID();
$from->setEntityId($entityId);
$from->setEntityType(ExportEntityType::SITE);

$serialized = $from->serializeToString();

$to = new ExportRequest();
$to->mergeFromString($serialized);

$this->assertEquals($to->getEntityId(), $entityId);
$this->assertEquals($to->getEntityType(), ExportEntityType::SITE);
}
}
```

Jakob Merrild

unread,
Mar 28, 2022, 7:00:20 AM3/28/22
to Protocol Buffers
I'm sorry the autoloading is of course
```
"psr-0": {
     "Famly\\Queue": "Packages/Application/Famly.Queue/Classes"
}
```

Deanna Garcia

unread,
May 2, 2022, 2:37:56 PM5/2/22
to Protocol Buffers
This looks similar to this issue. Did you set up protobuf autoloading correctly?

Jakob Merrild

unread,
May 3, 2022, 3:25:11 AM5/3/22
to Protocol Buffers
Thanks. I did attempt various different auto-loading options, but it is entirely possible that I didn't do it correctly.
In the end I ended up not using the php_namespace and php_metadata_namespace options and it worked.
Reply all
Reply to author
Forward
0 new messages