有用过grpc的吗?Couldn't find descriptor

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 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 12

看错误提示,需要你检查下代码生成。\GPBMetadata\Audio 这个贴出来看一眼

8个月前 评论
晏南风 (楼主) 8个月前
Crayxn (作者) 8个月前
Crayxn (作者) 8个月前
晏南风 (楼主) 8个月前
Crayxn (作者) 8个月前

file

8个月前 评论
陈先生 8个月前

file

file

检查下 代码生成吧,应该是 代码生成问题。可以参考下 我的博文

8个月前 评论
晏南风 (楼主) 8个月前
晏南风 (楼主) 8个月前
Es123 5个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!