有用過grpc的嗎?Couldn't find descriptor

晏南風發表於2023-08-08
syntax = "proto3";
package protobuf;

message C2SAudio{
    bytes audio = 1;
}
message S2CAudio{
    bytes audio = 1;
   string account = 4;
}
<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: app/Proto/audio.proto

namespace Grpc;

use Google\Protobuf\Internal\GPBUtil;

/**
 * Generated from protobuf message <code>protobuf.C2SAudio</code>
 */
class C2SAudio extends \Google\Protobuf\Internal\Message
{
    /**
     * Generated from protobuf field <code>bytes audio = 1;</code>
     */
    protected $audio = '';

    /**
     * Constructor.
     *
     * @param array $data {
     *     Optional. Data for populating the Message object.
     *
     *     @type string $audio
     * }
     */
    public function __construct($data = NULL) {
        \GPBMetadata\Audio::initOnce();
        parent::__construct($data);
    }

    /**
     * Generated from protobuf field <code>bytes audio = 1;</code>
     * @return string
     */
    public function getAudio()
    {
        return $this->audio;
    }

    /**
     * Generated from protobuf field <code>bytes audio = 1;</code>
     * @param string $var
     * @return $this
     */
    public function setAudio($var)
    {
        GPBUtil::checkString($var, False);
        $this->audio = $var;

        return $this;
    }

}
<?php
/**
 * User: jesse * Date: 2023/8/7 15:31 */
namespace App\Service;

use Google\Protobuf\Internal\GPBUtil;

use Hyperf\Grpc\Parser;
use Grpc\C2SAudio;

class AudioService
{

  public function handle($fd, $content)
 {
  /** @var C2SAudio $audio */
  $audio = Parser::deserializeMessage([C2SAudio::class, null], $content);

  var_dump($audio->getAudio());

 return $content;
  }
}
[ERROR] Exception: Couldn't find descriptor. Note only generated code may derive from \Google\Protobuf\Internal\Message in /www/conversation/grpc/Protobuf/C2SAudio.php:30
Stack trace:
#0 /www/conversation/grpc/Protobuf/C2SAudio.php(30): Google\Protobuf\Internal\Message->__construct(NULL)
#1 /www/conversation/vendor/hyperf/grpc/src/Parser.php(102): Grpc\C2SAudio->__construct()
#2 /www/conversation/vendor/hyperf/grpc/src/Parser.php(50): Hyperf\Grpc\Parser::deserializeUnpackedMessage(Array, '\x05|\x00\x07\x00S\x00S\x00\x07\x00\r\x00\t\x00...')
#3 /www/conversation/app/Service/AudioService.php(22): Hyperf\Grpc\Parser::deserializeMessage(Array, '\x05|\x00\x07\x00S\x00S\x00\x07\x00\r\x00\t\x00...')
#4 /www/conversation/runtime/container/proxy/App_Controller_WebSocketController.proxy.php(43): App\Service\AudioService->handle(3, '\x05|\x00\x07\x00S\x00S\x00\x07\x00\r\x00\t\x00...')
#5 /www/conversation/vendor/hyperf/websocket-server/src/Server.php(208): App\Controller\WebSocketController->onMessage(Object(Swoole\WebSocket\Server), Object(Swoole\WebSocket\Frame))
#6 [internal function]: Hyperf\WebSocketServer\Server->onMessage(Object(Swoole\WebSocket\Server), Object(Swoole\WebSocket\Frame))
#7 {main}
<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: app/Proto/audio.proto

namespace GPBMetadata;

class Audio
{
  public static $is_initialized = false;

 public static function initOnce() {
  $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();

 if (static::$is_initialized == true) {
  return;
  }
  $pool->internalAddGeneratedFile(
  '
p
app/Proto/audio.protoprotobuf"
C2SAudio
audio ("*
S2CAudio
audio (
account (  bproto3'
  , true);

 static::$is_initialized = true;
  }
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章