syntax = "proto3";
package protobuf;
message C2SAudio{
bytes audio = 1;
}
message S2CAudio{
bytes audio = 1;
string account = 4;
}
<?php
namespace Grpc;
use Google\Protobuf\Internal\GPBUtil;
class C2SAudio extends \Google\Protobuf\Internal\Message
{
protected $audio = '';
public function __construct($data = NULL) {
\GPBMetadata\Audio::initOnce();
parent::__construct($data);
}
public function getAudio()
{
return $this->audio;
}
public function setAudio($var)
{
GPBUtil::checkString($var, False);
$this->audio = $var;
return $this;
}
}
<?php
namespace App\Service;
use Google\Protobuf\Internal\GPBUtil;
use Hyperf\Grpc\Parser;
use Grpc\C2SAudio;
class AudioService
{
public function handle($fd, $content)
{
$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...')
<?php
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 協議》,轉載必須註明作者和本文連結